-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.py
59 lines (46 loc) · 1.57 KB
/
examples.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
## Note: Firstly you should install the library, what else program can't find 'nowpayments' module.
## Clone repository and move to python/site-packages directory.
## In mac:
- cd /Library/Frameworks/Python.framework/versions/3.x/lib/python3.x/site-packages
- mv /Users/mert/Desktop/nowpayments .
"""
from nowpayments import (
currency,
exchanges,
Plugins,
Payments,
NowPaymentsAPI,
GetPaymentContext
)
from nowpayments.dataclasses import IPNCompatibleResponse
from logging import Logger, WARN
API_KEY: str = "x-api-key"
plugins = Plugins(API_KEY)
class _TempInterface(IPNCompatibleResponse):
npc: NowPaymentsAPI
payment: Payments
def main():
logger = Logger(__name__)
ipn = plugins.create_payment(
client_id=123456789,
amount=34.5,
price_currency=currency.usd,
pay_currency=exchanges.eth,
order_description="Test Payment"
)
ipn: _TempInterface
payment_response = ipn.npc.get(payment_id=ipn.id)
payment_context_call = GetPaymentContext(payment_response, ipn.npc.api_key)
payment_context = payment_context_call.payment()
## you can also get data from response `payment_response.json()` returns python-dict.
message = """%d ödeme kimliğine sahip ödeme oluşturulmuştur.\nÖdeme: %.2f %s\nÖdeme Durumu: %s\nÖdeme Linki: %s""" % (
ipn.id,
payment_context.price_amount,
payment_context.price_currency.upper(),
payment_context.payment_status,
ipn.url
)
logger.warning(message)
return ipn
main()