payra-sdk 1.2.4__py3-none-any.whl → 1.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,37 +66,84 @@ class PayraOrderVerification:
66
66
 
67
67
  return random.choice(urls)
68
68
 
69
+
69
70
  def is_order_paid(self, order_id: str) -> dict:
70
71
  """
71
72
  Calls the Payra Forward contract to check if an order is paid.
72
73
  """
73
74
  try:
74
- # encode isOrderPaid call manually
75
- core_fn_selector = PayraUtils.function_selector(self.core_fn)
76
- encoded_params = self.web3.codec.encode(
77
- [inp["type"] for inp in self.core_fn["inputs"]],
75
+ raw = self._call_core_function(
76
+ "isOrderPaid",
78
77
  [int(self.merchant_id), order_id]
79
78
  )
80
- data = core_fn_selector + encoded_params.hex()
81
79
 
82
- # call forward()
83
- result = self.forward_contract.functions.forward("0x" + data).call()
80
+ decoded = self.web3.codec.decode(["bool"], raw)
81
+
82
+ return {
83
+ "success": True,
84
+ "paid": bool(decoded[0]),
85
+ "error": None
86
+ }
87
+
88
+ except Exception as e:
89
+ return {
90
+ "success": False,
91
+ "paid": None,
92
+ "error": str(e)
93
+ }
94
+
95
+
96
+ def get_order_status(self, order_id: str) -> dict:
97
+ """
98
+ Calls the Payra Forward contract to get order status.
99
+ """
100
+ try:
101
+ raw = self._call_core_function(
102
+ "getOrderStatus",
103
+ [int(self.merchant_id), order_id]
104
+ )
84
105
 
85
- # decode result
86
106
  decoded = self.web3.codec.decode(
87
- [out["type"] for out in self.core_fn["outputs"]],
88
- result
107
+ ["bool", "address", "uint256", "uint256", "uint256"],
108
+ raw
89
109
  )
90
110
 
91
111
  return {
92
112
  "success": True,
113
+ "error": None,
93
114
  "paid": bool(decoded[0]),
94
- "error": None
115
+ "token": decoded[1],
116
+ "amount": int(decoded[2]),
117
+ "fee": int(decoded[3]),
118
+ "timestamp": int(decoded[4]),
95
119
  }
96
120
 
97
121
  except Exception as e:
98
122
  return {
99
123
  "success": False,
124
+ "error": str(e),
100
125
  "paid": None,
101
- "error": str(e)
126
+ "token": None,
127
+ "amount": None,
128
+ "fee": None,
129
+ "timestamp": None,
102
130
  }
131
+
132
+ def _call_core_function(self, function_name: str, params: list) -> bytes:
133
+ """
134
+ Calls Payra Core contract via Forward and returns raw bytes.
135
+ """
136
+ core_fn = PayraUtils.find_function(self.abi, function_name)
137
+
138
+ selector = PayraUtils.function_selector(core_fn)
139
+
140
+ encoded_params = self.web3.codec.encode(
141
+ [inp["type"] for inp in core_fn["inputs"]],
142
+ params
143
+ )
144
+
145
+ data = selector + encoded_params.hex()
146
+
147
+ return self.forward_contract.functions.forward(
148
+ "0x" + data
149
+ ).call()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: payra_sdk
3
- Version: 1.2.4
3
+ Version: 1.2.5
4
4
  Summary: Python SDK for Payra payment signature generation (backend)
5
5
  Author: Your Name
6
6
  Author-email: Wraith <contact@payra.cash>
@@ -67,9 +67,9 @@ This process ensures full compatibility between your backend and Payra’s on-ch
67
67
 
68
68
  Before installing this package, make sure you have an active **Payra** account:
69
69
 
70
- [https://payra.cash](https://payra.cash)
70
+ [https://payra.cash/products/on-chain-payments/merchant-registration](https://payra.cash/products/on-chain-payments/merchant-registration)
71
71
 
72
- You will need:
72
+ Before installing this package, make sure you have a **MerchantID**
73
73
 
74
74
  - Your **Merchant ID** (unique for each blockchain network)
75
75
  - Your **Private Key** (used to sign Payra transactions securely)
@@ -229,15 +229,69 @@ except Exception as e:
229
229
 
230
230
  ---
231
231
 
232
- ### Checking On-Chain Order Status
232
+ ### Get Order Status
233
233
 
234
- You can verify whether a Payra order has been successfully paid on-chain:
234
+ Retrieve **full payment details** for a specific order from the Payra smart contract. This method returns the complete on-chain payment data associated with the order, including:
235
+
236
+ - whether the order has been paid,
237
+ - the payment token address,
238
+ - the paid amount,
239
+ - the fee amount,
240
+ - and the payment timestamp.
241
+
242
+ Use this method when you need **detailed information** about the payment or want to display full transaction data.
243
+
244
+ ```python
245
+ from payra_sdk import PayraOrderVerification, PayraSDKException
246
+
247
+ try:
248
+ ORDER_ID = "ORDER-1765138911744-126-5"
249
+
250
+ # Initialize verifier for a specific network
251
+ verifier = PayraOrderVerification("polygon")
252
+
253
+ print("\nGet order status...")
254
+ result = verifier.get_order_status(ORDER_ID)
255
+
256
+ print("Order ID:", ORDER_ID)
257
+ print("Result:", result)
258
+
259
+ except PayraSDKException as e:
260
+ print(f"Payra SDK error: {e}")
261
+ except Exception as e:
262
+ print(f"Unexpected error: {e}")
263
+ ```
264
+
265
+ #### Behind the Scenes
266
+
267
+ 1. The backend initializes a `PayraOrderVerification` object for the desired blockchain network.
268
+ 3. It calls `get_order_status(order_id)` to check if the order transaction exists and is confirmed on-chain.
269
+ 4. The function returns a dictionary with:
270
+ ```python
271
+ {
272
+ "success": True,
273
+ "paid": True,
274
+ "error": None.
275
+ "toke": '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
276
+ "amount": 400000,
277
+ "fee": 3600,
278
+ "timestamp": 1765138941
279
+ }
280
+ ```
281
+
282
+ ---
283
+
284
+ ### Check Order Paid Status
285
+
286
+ Perform a **simple payment check** for a specific order. This method only verifies whether the order has been paid (`true` or `false`) and does **not** return any additional payment details.
287
+
288
+ Use this method when you only need a **quick boolean confirmation** of the payment status.
235
289
 
236
290
  ```python
237
291
  from payra_sdk import PayraOrderVerification, PayraSDKException
238
292
 
239
293
  try:
240
- ORDER_ID = "ORDER-1753824905006-301-322"
294
+ ORDER_ID = "ORDER-1765138911744-126-5"
241
295
 
242
296
  # Initialize verifier for a specific network
243
297
  verifier = PayraOrderVerification("polygon")
@@ -263,9 +317,9 @@ except Exception as e:
263
317
 
264
318
  #### Behind the Scenes
265
319
 
266
- 1. The backend initializes a `PayraOrderVerification` object for the desired blockchain network.
267
- 3. It calls `is_order_paid(order_id)` to check if the order transaction exists and is confirmed on-chain.
268
- 4. The function returns a dictionary with:
320
+ 1. The backend initializes a `PayraOrderVerification` object for the desired blockchain network.
321
+ 3. It calls `is_order_paid(order_id)` to check if the order transaction exists and is confirmed on-chain.
322
+ 4. The function returns a dictionary with:
269
323
  ```python
270
324
  {
271
325
  "success": True,
@@ -273,7 +327,7 @@ except Exception as e:
273
327
  "error": None
274
328
  }
275
329
  ```
276
- 5. If `paid` is `True`, the order has been successfully processed and confirmed by the Payra smart contract.
330
+ 5. If `paid` is `True`, the order has been successfully processed and confirmed by the Payra smart contract.
277
331
 
278
332
  ---
279
333
 
@@ -284,29 +338,29 @@ The `PayraUtils` module provides convenient helpers for token conversion, precis
284
338
  ```python
285
339
  from payra_sdk import PayraUtils
286
340
 
287
- # 🔹 Convert USD/token amount to smallest unit (Wei or token decimals)
341
+ # Convert USD/token amount to smallest unit (Wei or token decimals)
288
342
  amount_wei = PayraUtils.to_wei(3.34, 'polygon', 'usdt')
289
343
  print("Amount in Wei:", amount_wei) # 3340000
290
344
 
291
- # 🔹 Convert from Wei back to readable token amount
345
+ # Convert from Wei back to readable token amount
292
346
  amount = PayraUtils.from_wei(3340000, 'polygon', 'usdt', precision=2)
293
347
  print("Readable amount:", amount) # "3.34"
294
348
 
295
- # 🔹 Get token decimals for any supported network
349
+ # Get token decimals for any supported network
296
350
  print("USDT decimals on Polygon:", PayraUtils.get_decimals("polygon", "usdt"))
297
351
  print("POL decimals on Polygon:", PayraUtils.get_decimals("polygon", "pol"))
298
352
 
299
- # 🔹 Convert fiat currency to USD using the built-in ExchangeRate API
353
+ # Convert fiat currency to USD using the built-in ExchangeRate API
300
354
  usd_value = PayraUtils.convert_to_usd(100, "EUR")
301
355
  print(f"100 EUR = {usd_value} USD")
302
356
  ```
303
357
 
304
358
  #### Behind the Scenes
305
359
 
306
- - `to_wei(amount, network, token)` – Converts a human-readable token amount into the smallest unit (used on-chain).
307
- - `from_wei(amount, network, token, precision)` – Converts back from smallest unit to a formatted amount.
308
- - `get_decimals(network, token)` – Returns the number of decimals for the given token on that network.
309
- - `convert_to_usd(amount, currency)` – Converts fiat amounts (e.g. EUR, GBP) to USD using your ExchangeRate API key.
360
+ - `to_wei(amount, network, token)` – Converts a human-readable token amount into the smallest unit (used on-chain).
361
+ - `from_wei(amount, network, token, precision)` – Converts back from smallest unit to a formatted amount.
362
+ - `get_decimals(network, token)` – Returns the number of decimals for the given token on that network.
363
+ - `convert_to_usd(amount, currency)` – Converts fiat amounts (e.g. EUR, GBP) to USD using your ExchangeRate API key.
310
364
 
311
365
  ## Testing
312
366
  You can run the included `examples` to test signing and verification:
@@ -327,24 +381,24 @@ Make sure your `.env` file contains correct values for the `network` being used.
327
381
 
328
382
  ## Projects
329
383
 
330
- - [GitHub / Home](https://github.com/payracash)
331
- - [GitHub / Source](https://github.com/payracash/payra-sdk-python)
332
- - [GitHub / Issues](https://github.com/payracash/payra-sdk-python/issues)
384
+ - [GitHub/Home](https://github.com/payracash)
385
+ - [GitHub/Source](https://github.com/payracash/payra-sdk-python)
386
+ - [GitHub/Issues](https://github.com/payracash/payra-sdk-python/issues)
333
387
 
334
388
  ## Project
335
389
 
336
- - [https://payra.cash](https://payra.cash)
337
- - [https://payra.tech](https://payra.tech)
338
- - [https://payra.xyz](https://payra.xyz)
339
- - [https://payra.eth](https://payra.eth)
390
+ - [https://payra.cash](https://payra.cash)
391
+ - [https://payra.tech](https://payra.tech)
392
+ - [https://payra.xyz](https://payra.xyz)
393
+ - [https://payra.eth](https://payra.eth.limo) - suporrted by Brave Browser or .limo
340
394
 
341
395
  ## Social Media
342
396
 
343
397
  - [Telegram Payra Group](https://t.me/+GhTyJJrd4SMyMDA0)
344
398
  - [Telegram Announcements](https://t.me/payracash)
345
399
  - [Twix (X)](https://x.com/PayraCash)
346
- - [Hashnode](https://payra.hashnode.dev)
400
+ - [Dev.to](https://dev.to/payracash)
347
401
 
348
402
  ## License
349
403
 
350
- MIT © [Payra](https://github.com/payracash)
404
+ MIT © [Payra](https://payra.cash)
@@ -0,0 +1,10 @@
1
+ payra_sdk/__init__.py,sha256=VMmHadXy0RLCjEPZhW_hCc3hg34pkmrL4VhTjqmVBiI,422
2
+ payra_sdk/exceptions.py,sha256=Dr8dy0RohAYII_-YeSu_doPJSr0EsJPcp6Oj02sio9Q,425
3
+ payra_sdk/order_verification.py,sha256=wS43tz6yfGSoHGj_B_vr60d0Z2UhXwy4RxZRX3OfvKo,4556
4
+ payra_sdk/signature.py,sha256=Vn85w4DAGzHK1y9h3hMETij_-Qa4aSNz0KwnzwCyFQw,8613
5
+ payra_sdk/utils.py,sha256=gIQZX9N97Eneh5ScJ-YWY8_8wRqxBe0h5lDAVFYV8CE,4854
6
+ payra_sdk-1.2.5.dist-info/licenses/LICENSE,sha256=mnnujAcvHr1ULEDD2l0ZT6lrpeTv_9bG3n8sngv7ew8,120
7
+ payra_sdk-1.2.5.dist-info/METADATA,sha256=GljMlwKvvai4_jzlyTehLzBT6Qb7s3okV8NVZLC9nvY,14367
8
+ payra_sdk-1.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ payra_sdk-1.2.5.dist-info/top_level.txt,sha256=oC4dhGzjcpDRRwyU9JjtLu56Uc5moaa76utQGYsPL-g,10
10
+ payra_sdk-1.2.5.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- payra_sdk/__init__.py,sha256=VMmHadXy0RLCjEPZhW_hCc3hg34pkmrL4VhTjqmVBiI,422
2
- payra_sdk/exceptions.py,sha256=Dr8dy0RohAYII_-YeSu_doPJSr0EsJPcp6Oj02sio9Q,425
3
- payra_sdk/order_verification.py,sha256=IWKV4V6gZRyrtJtXsDRPflUcSsuN5D1kFZn5QVTPi5Q,3379
4
- payra_sdk/signature.py,sha256=Vn85w4DAGzHK1y9h3hMETij_-Qa4aSNz0KwnzwCyFQw,8613
5
- payra_sdk/utils.py,sha256=gIQZX9N97Eneh5ScJ-YWY8_8wRqxBe0h5lDAVFYV8CE,4854
6
- payra_sdk-1.2.4.dist-info/licenses/LICENSE,sha256=mnnujAcvHr1ULEDD2l0ZT6lrpeTv_9bG3n8sngv7ew8,120
7
- payra_sdk-1.2.4.dist-info/METADATA,sha256=BF0bsVhP4ycHdUfzYPG1q6c6zR_z5aG2i2toHAGRW2c,12574
8
- payra_sdk-1.2.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- payra_sdk-1.2.4.dist-info/top_level.txt,sha256=oC4dhGzjcpDRRwyU9JjtLu56Uc5moaa76utQGYsPL-g,10
10
- payra_sdk-1.2.4.dist-info/RECORD,,