payra-sdk 1.2.3__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()
payra_sdk/utils.py CHANGED
@@ -84,11 +84,11 @@ class PayraUtils:
84
84
  Default cache time: 720 minutes (12 hours).
85
85
  """
86
86
 
87
- api_key = os.getenv("EXCHANGE_RATE_API_KEY")
87
+ api_key = os.getenv("PAYRA_EXCHANGE_RATE_API_KEY")
88
88
  if not api_key:
89
- raise InvalidArgumentError("EXCHANGE_RATE_API_KEY is not set in .env")
89
+ raise InvalidArgumentError("PAYRA_EXCHANGE_RATE_API_KEY is not set in .env")
90
90
 
91
- cache_minutes = int(os.getenv("EXCHANGE_RATE_CACHE_TIME", 720))
91
+ cache_minutes = int(os.getenv("PAYRA_EXCHANGE_RATE_CACHE_TIME", 720))
92
92
  cache_ttl = cache_minutes * 60
93
93
 
94
94
  api_url = f"https://v6.exchangerate-api.com/v6/{api_key}/latest/USD"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: payra_sdk
3
- Version: 1.2.3
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>
@@ -26,7 +26,7 @@ Dynamic: license-file
26
26
 
27
27
  # Payra Python SDK
28
28
 
29
- Official Python SDK for integrating **Payra's on-chain payment system** into your backend applications.
29
+ Official **Python SDK** for integrating **Payra's on-chain payment system** into your backend applications.
30
30
 
31
31
  This SDK provides:
32
32
  - Secure generation of **ECDSA signatures** compatible with the Payra smart contract — used for order payment verification.
@@ -36,40 +36,40 @@ This SDK provides:
36
36
 
37
37
  The typical flow for signing and verifying a Payra transaction:
38
38
 
39
- 1. The **frontend** prepares all required payment parameters:
40
- - **Network** – blockchain name (e.g. Polygon, Linea)
41
- - **Token address** – ERC-20 token contract address
42
- - **Order ID** – unique order identifier
43
- - **AmountWei** – already converted to the smallest unit (e.g. wei, 10⁶)
44
- - **Timestamp** – Unix timestamp of the order
45
- - **Payer wallet address**
46
-
47
- 2. The frontend sends these parameters to your **backend**.
48
- 3. The **backend** uses this SDK to generate a cryptographic **ECDSA signature** with its private key (performed **offline**).
49
- 4. The backend returns the generated signature to the frontend.
50
- 5. The **frontend** calls the Payra smart contract (`payOrder`) with all parameters **plus** the signature.
39
+ 1. The **frontend** prepares all required payment parameters:
40
+ - **Network** – blockchain name (e.g. Polygon, Linea)
41
+ - **Token address** – ERC-20 token contract address
42
+ - **Order ID** – unique order identifier
43
+ - **Amount Wei** – already converted to the smallest unit (e.g. wei, 10⁶)
44
+ - **Timestamp** – Unix timestamp of the order
45
+ - **Payer wallet address** – the wallet address from which the user will make the on-chain payment
46
+ 2. The frontend sends these parameters to your **backend**.
47
+ 3. The **backend** uses this SDK to generate a cryptographic **ECDSA signature** with its private key (performed **offline**).
48
+ 4. The backend returns the generated signature to the frontend.
49
+ 5. The **frontend** calls the Payra smart contract (`payOrder`) with all parameters **plus** the signature.
51
50
 
52
51
  This process ensures full compatibility between your backend and Payra’s on-chain verification logic.
53
52
 
54
53
  ## Features
55
54
 
56
- - Generates **Ethereum ECDSA signatures** using the `secp256k1` curve.
55
+ - Generates **Ethereum ECDSA signatures** using the `secp256k1` curve.
57
56
  - Fully compatible with **Payra's Solidity smart contracts** (`ERC-1155` payment verification).
58
- - Includes built-in **ABI encoding and decoding** via [`web3.py`](https://github.com/ethereum/web3.py).
59
- - Supports environment-based configuration (`.env`) for managing multiple blockchain networks.
57
+ - Includes built-in **ABI encoding and decoding** via `web3.php`.
58
+ - Supports `.env` and `config/payra.php` configuration for multiple blockchain networks.
59
+ - Laravel IoC container integration (easy dependency injection)
60
60
  - Verifies **order payment status directly on-chain** via RPC or blockchain explorer API.
61
- - Provides **secure backend integration** using merchant private keys.
61
+ - Provides **secure backend integration** for signing and verifying transactions.
62
62
  - Includes optional utility helpers for:
63
- - **Currency conversion** (via [ExchangeRate API](https://www.exchangerate-api.com/))
64
- - **USD ⇄ WEI** conversion for token precision handling.
63
+ - **Currency conversion** (via [ExchangeRate API](https://www.exchangerate-api.com/))
64
+ - **USD ⇄ WEI** conversion for token precision handling.
65
65
 
66
66
  ## Setup
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)
@@ -118,13 +118,13 @@ This SDK requires:
118
118
 
119
119
  ## Environment Configuration
120
120
 
121
- Create a (`.env`) file in your project root (you can copy from example):
121
+ Create a `.env` file in your project root (you can copy from example):
122
122
 
123
123
  ```bash
124
124
  cp .env.example .env
125
125
  ```
126
126
 
127
- This file stores your **private configuration** and connection settings for all supported networks. Never commit (`.env`) to version control.
127
+ This file stores your **private configuration** and connection settings for all supported networks. Never commit `.env` to version control.
128
128
 
129
129
  ### Required Variables
130
130
 
@@ -133,8 +133,9 @@ This file stores your **private configuration** and connection settings for all
133
133
  Used for automatic fiat → USD conversions via the built-in Payra utilities.
134
134
 
135
135
  ```bash
136
- EXCHANGE_RATE_API_KEY= # Your ExchangeRate API key (from exchangerate-api.com)
137
- EXCHANGE_RATE_CACHE_TIME=720 # Cache duration in minutes (default: 720 = 12h)
136
+ # Optional only needed if you want to use the built-in currency conversion helper
137
+ PAYRA_EXCHANGE_RATE_API_KEY= # Your ExchangeRate API key (from exchangerate-api.com)
138
+ PAYRA_EXCHANGE_RATE_CACHE_TIME=720 # Cache duration in minutes (default: 720 = 12h)
138
139
 
139
140
  PAYRA_POLYGON_CORE_FORWARD_CONTRACT_ADDRESS=0xf30070da76B55E5cB5750517E4DECBD6Cc5ce5a8
140
141
  PAYRA_POLYGON_PRIVATE_KEY=
@@ -158,7 +159,7 @@ PAYRA_LINEA_RPC_URL_2=
158
159
  #### Important Notes
159
160
 
160
161
  - The cache automatically refreshes when it expires.
161
- - You can adjust the cache duration by setting `EXCHANGE_RATE_CACHE_TIME`:
162
+ - You can adjust the cache duration by setting `PAYRA_EXCHANGE_RATE_CACHE_TIME`:
162
163
  - `5` → cache for 5 minutes
163
164
  - `60` → cache for 1 hour
164
165
  - `720` → cache for 12 hours (default)
@@ -208,24 +209,89 @@ except Exception as e:
208
209
  print(f"Unexpected error: {e}")
209
210
  ```
210
211
 
212
+ #### Input Parameters
213
+
214
+ | Field | Type | Description |
215
+ |--------------|----------|----------------------------------------------|
216
+ | **`network`** | `string` | Selected network name |
217
+ | **`tokenAddress`** | `string` | ERC20 token contract address |
218
+ | **`orderId`** | `string` | Unique order reference (e.g. ORDER-123) |
219
+ | **`amountWei`** | `string` or `integer` | Token amount in smallest unit (e.g. wei) |
220
+ | **`timestamp`** | `number` | Unix timestamp of signature creation |
221
+ | **`payerAddress`** | `string` | Payer Wallet Address
222
+
211
223
  #### Behind the Scenes
212
224
 
213
225
  1. The backend converts the amount to the smallest blockchain unit (e.g. wei).
214
- 3. A `PayraSignatureGenerator` instance is created using your private key from (`.env`).
226
+ 3. A `PayraSignatureGenerator` instance is created using your private key from `.env`
215
227
  4. It generates an ECDSA signature that is fully verifiable on-chain by the Payra smart contract.
216
228
  5. The resulting signature should be sent to the **frontend**, which must call `payOrder(...)` using the same parameters (`timestamp`, `orderId`, `amount`, `tokenAddress`, etc.) that were used to generate the signature.
217
229
 
218
230
  ---
219
231
 
220
- ### Checking On-Chain Order Status
232
+ ### Get Order Status
233
+
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.
221
287
 
222
- You can verify whether a Payra order has been successfully paid on-chain:
288
+ Use this method when you only need a **quick boolean confirmation** of the payment status.
223
289
 
224
290
  ```python
225
291
  from payra_sdk import PayraOrderVerification, PayraSDKException
226
292
 
227
293
  try:
228
- ORDER_ID = "ORDER-1753824905006-301-322"
294
+ ORDER_ID = "ORDER-1765138911744-126-5"
229
295
 
230
296
  # Initialize verifier for a specific network
231
297
  verifier = PayraOrderVerification("polygon")
@@ -251,9 +317,9 @@ except Exception as e:
251
317
 
252
318
  #### Behind the Scenes
253
319
 
254
- 1. The backend initializes a `PayraOrderVerification` object for the desired blockchain network.
255
- 3. It calls `is_order_paid(order_id)` to check if the order transaction exists and is confirmed on-chain.
256
- 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:
257
323
  ```python
258
324
  {
259
325
  "success": True,
@@ -261,7 +327,7 @@ except Exception as e:
261
327
  "error": None
262
328
  }
263
329
  ```
264
- 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.
265
331
 
266
332
  ---
267
333
 
@@ -272,29 +338,29 @@ The `PayraUtils` module provides convenient helpers for token conversion, precis
272
338
  ```python
273
339
  from payra_sdk import PayraUtils
274
340
 
275
- # 🔹 Convert USD/token amount to smallest unit (Wei or token decimals)
341
+ # Convert USD/token amount to smallest unit (Wei or token decimals)
276
342
  amount_wei = PayraUtils.to_wei(3.34, 'polygon', 'usdt')
277
343
  print("Amount in Wei:", amount_wei) # 3340000
278
344
 
279
- # 🔹 Convert from Wei back to readable token amount
345
+ # Convert from Wei back to readable token amount
280
346
  amount = PayraUtils.from_wei(3340000, 'polygon', 'usdt', precision=2)
281
347
  print("Readable amount:", amount) # "3.34"
282
348
 
283
- # 🔹 Get token decimals for any supported network
349
+ # Get token decimals for any supported network
284
350
  print("USDT decimals on Polygon:", PayraUtils.get_decimals("polygon", "usdt"))
285
351
  print("POL decimals on Polygon:", PayraUtils.get_decimals("polygon", "pol"))
286
352
 
287
- # 🔹 Convert fiat currency to USD using the built-in ExchangeRate API
353
+ # Convert fiat currency to USD using the built-in ExchangeRate API
288
354
  usd_value = PayraUtils.convert_to_usd(100, "EUR")
289
355
  print(f"100 EUR = {usd_value} USD")
290
356
  ```
291
357
 
292
358
  #### Behind the Scenes
293
359
 
294
- - `to_wei(amount, network, token)` – Converts a human-readable token amount into the smallest unit (used on-chain).
295
- - `from_wei(amount, network, token, precision)` – Converts back from smallest unit to a formatted amount.
296
- - `get_decimals(network, token)` – Returns the number of decimals for the given token on that network.
297
- - `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.
298
364
 
299
365
  ## Testing
300
366
  You can run the included `examples` to test signing and verification:
@@ -305,34 +371,34 @@ python3 example_order_verification.py
305
371
  python3 example_utils.py
306
372
  ```
307
373
 
308
- Make sure your (`.env`) file contains correct values for the `network` being used.
374
+ Make sure your `.env` file contains correct values for the `network` being used.
309
375
 
310
376
  ### Tips
311
377
 
312
- - Always verify your (`.env`) configuration before running any signing or on-chain verification examples.
378
+ - Always verify your `.env` configuration before running any signing or on-chain verification examples.
313
379
  - The SDK examples are safe to run — they use **read-only RPC calls** (no real transactions are broadcast).
314
380
  - You can modify `example_signature.py` to test custom token addresses or order parameters.
315
381
 
316
382
  ## Projects
317
383
 
318
- - [GitHub / Home](https://github.com/payracash)
319
- - [GitHub / Source](https://github.com/payracash/payra-sdk-python)
320
- - [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)
321
387
 
322
388
  ## Project
323
389
 
324
- - [https://payra.cash](https://payra.cash)
325
- - [https://payra.tech](https://payra.tech)
326
- - [https://payra.xyz](https://payra.xyz)
327
- - [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
328
394
 
329
395
  ## Social Media
330
396
 
331
397
  - [Telegram Payra Group](https://t.me/+GhTyJJrd4SMyMDA0)
332
398
  - [Telegram Announcements](https://t.me/payracash)
333
399
  - [Twix (X)](https://x.com/PayraCash)
334
- - [Hashnode](https://payra.hashnode.dev)
400
+ - [Dev.to](https://dev.to/payracash)
335
401
 
336
402
  ## License
337
403
 
338
- 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=SSh_3AfPpceEoGL3tO7ydXJz17Kl3k7D-mM0wiv-h-c,4836
6
- payra_sdk-1.2.3.dist-info/licenses/LICENSE,sha256=mnnujAcvHr1ULEDD2l0ZT6lrpeTv_9bG3n8sngv7ew8,120
7
- payra_sdk-1.2.3.dist-info/METADATA,sha256=GY6VfwviC9LRXYiHb1IY1vpMvoqKcSvmbAvYeNgl-18,11696
8
- payra_sdk-1.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- payra_sdk-1.2.3.dist-info/top_level.txt,sha256=oC4dhGzjcpDRRwyU9JjtLu56Uc5moaa76utQGYsPL-g,10
10
- payra_sdk-1.2.3.dist-info/RECORD,,