-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpayments.py
45 lines (34 loc) · 1.12 KB
/
payments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
from config import RETURN_URL, YOOKASSA_ACCOUNT_ID, YOOKASSA_SECRET_KEY
from yookassa import Configuration, Payment
import uuid
Configuration.account_id = YOOKASSA_ACCOUNT_ID
Configuration.secret_key = YOOKASSA_SECRET_KEY
def get_payments() -> str:
payments = Payment.list()
return payments.json()
def create_payment(amount: int, description: str) -> tuple[str, str]:
idempotence_key = str(uuid.uuid4())
payment = Payment.create({
"amount": {
"value": float(str(amount)),
"currency": "RUB"
},
"confirmation": {
"type": "redirect",
"return_url": RETURN_URL
},
"description": description
}, idempotence_key)
return payment.confirmation.confirmation_url, payment.id
def get_payment_status(payment_id: str) -> str:
payment = Payment.find_one(payment_id)
return json.loads(payment.json())['status']
def confirm_payment(payment_id: str) -> str:
idempotence_key = str(uuid.uuid4())
response = Payment.capture(
payment_id,
{},
idempotence_key
)
return response.json()