-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_payment.py
More file actions
52 lines (42 loc) · 1.33 KB
/
Copy pathbasic_payment.py
File metadata and controls
52 lines (42 loc) · 1.33 KB
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
46
47
48
49
50
51
52
import asyncio
import time
from pprint import pprint
from dotenv import load_dotenv
from payos import APIError, AsyncPayOS, PayOS
from payos.types import CreatePaymentLinkRequest
# Assume that credentials have been set in environment
# If not, you must provide them when init client
load_dotenv()
def sync_main() -> None:
client = PayOS()
payment_data = CreatePaymentLinkRequest(
order_code=int(time.time()),
amount=2000,
description="Thanh toan",
cancel_url="https://your-url.com/cancel",
return_url="https://your-url.com/success",
)
try:
response = client.payment_requests.create(payment_data=payment_data)
pprint(response)
except APIError as e:
pprint(e.error_code)
pprint(e.error_desc)
pprint(e.status_code)
async def async_main() -> None:
client = AsyncPayOS()
payment_data = CreatePaymentLinkRequest(
order_code=int(time.time()),
amount=2000,
description="Thanh toan",
cancel_url="https://your-url.com/cancel",
return_url="https://your-url.com/success",
)
try:
response = await client.payment_requests.create(payment_data=payment_data)
pprint(response)
except APIError as e:
pprint(e)
if __name__ == "__main__":
sync_main()
asyncio.run(async_main())