payra-sdk 1.2.6__tar.gz → 1.2.8__tar.gz
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.
- {payra_sdk-1.2.6/payra_sdk.egg-info → payra_sdk-1.2.8}/PKG-INFO +33 -40
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/README.md +32 -39
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/payra_sdk/__init__.py +4 -4
- payra_sdk-1.2.6/payra_sdk/order_verification.py → payra_sdk-1.2.8/payra_sdk/order_service.py +4 -4
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/payra_sdk/signature.py +5 -5
- {payra_sdk-1.2.6 → payra_sdk-1.2.8/payra_sdk.egg-info}/PKG-INFO +33 -40
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/payra_sdk.egg-info/SOURCES.txt +1 -1
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/payra_sdk.egg-info/dependency_links.txt +0 -0
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/payra_sdk.egg-info/requires.txt +0 -0
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/payra_sdk.egg-info/top_level.txt +0 -0
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/pyproject.toml +1 -1
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/.env.example +0 -0
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/LICENSE +0 -0
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/MANIFEST.in +0 -0
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/payra_sdk/exceptions.py +0 -0
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/payra_sdk/utils.py +0 -0
- {payra_sdk-1.2.6 → payra_sdk-1.2.8}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: payra_sdk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.8
|
|
4
4
|
Summary: Python SDK for Payra payment signature generation (backend)
|
|
5
5
|
Author: Your Name
|
|
6
6
|
Author-email: Wraith <support@payra.cash>
|
|
@@ -28,8 +28,7 @@ Official **Python SDK** for integrating **Payra's on-chain payment system** into
|
|
|
28
28
|
|
|
29
29
|
This SDK provides:
|
|
30
30
|
- Secure generation of **ECDSA signatures** compatible with the Payra smart contract, used for order payment verification.
|
|
31
|
-
- Simple methods for **checking the on-chain
|
|
32
|
-
|
|
31
|
+
- Simple methods for **checking the on-chain details of orders** to confirm completed payments.
|
|
33
32
|
|
|
34
33
|
## How It Works
|
|
35
34
|
|
|
@@ -48,20 +47,18 @@ The typical flow for signing and verifying a Payra transaction:
|
|
|
48
47
|
|
|
49
48
|
This process ensures full compatibility between your backend and Payra’s on-chain verification logic.
|
|
50
49
|
|
|
51
|
-
|
|
52
50
|
## Features
|
|
53
51
|
|
|
54
52
|
- Generates **Ethereum ECDSA signatures** using the `secp256k1` curve.
|
|
55
53
|
- Fully compatible with **Payra's Solidity smart contracts** (`ERC-1155` payment verification).
|
|
56
54
|
- Supports `.env` and `config/payra.php` configuration for multiple blockchain networks.
|
|
57
55
|
- Laravel IoC container integration (easy dependency injection)
|
|
58
|
-
- Verifies **order payment
|
|
56
|
+
- Verifies **order payment details directly on-chain** via RPC or blockchain explorer API.
|
|
59
57
|
- Provides **secure backend integration** for signing and verifying transactions.
|
|
60
58
|
- Includes optional utility helpers for:
|
|
61
59
|
- **Currency conversion** (via [ExchangeRate API](https://www.exchangerate-api.com/))
|
|
62
60
|
- **USD ⇄ WEI** conversion for token precision handling.
|
|
63
61
|
|
|
64
|
-
|
|
65
62
|
## Setup
|
|
66
63
|
|
|
67
64
|
Before installing this package, make sure you have an active **Payra** account:
|
|
@@ -87,7 +84,6 @@ To obtain your **RPC URLs** which are required for reading on-chain order status
|
|
|
87
84
|
Optional (recommended):
|
|
88
85
|
- Create a free API key at [ExchangeRate API](https://www.exchangerate-api.com/) to enable **automatic fiat → USD conversions** using the built-in utility helpers.
|
|
89
86
|
|
|
90
|
-
|
|
91
87
|
## Installation
|
|
92
88
|
|
|
93
89
|
### From PyPI
|
|
@@ -129,7 +125,6 @@ cp .env.example .env
|
|
|
129
125
|
|
|
130
126
|
This file stores your **private configuration** and connection settings for all supported networks. Never commit `.env` to version control.
|
|
131
127
|
|
|
132
|
-
|
|
133
128
|
### Required Variables
|
|
134
129
|
|
|
135
130
|
#### Exchange Rate (optional)
|
|
@@ -164,9 +159,9 @@ PAYRA_LINEA_RPC_URL_2=
|
|
|
164
159
|
|
|
165
160
|
- The cache automatically refreshes when it expires.
|
|
166
161
|
- You can adjust the cache duration by setting `PAYRA_EXCHANGE_RATE_CACHE_TIME`:
|
|
167
|
-
- `5` → cache for 5 minutes
|
|
168
|
-
- `60` → cache for 1 hour
|
|
169
|
-
- `720` → cache for 12 hours (default)
|
|
162
|
+
- `5` → cache for 5 minutes
|
|
163
|
+
- `60` → cache for 1 hour
|
|
164
|
+
- `720` → cache for 12 hours (default)
|
|
170
165
|
- Each network (Polygon, Ethereum, Linea) has its own **merchant ID**, **signature key**, and **RPC URLs**.
|
|
171
166
|
- The SDK automatically detects which chain configuration to use based on the selected network.
|
|
172
167
|
- You can use multiple RPC URLs for redundancy (the SDK will automatically fall back if one fails).
|
|
@@ -175,10 +170,10 @@ PAYRA_LINEA_RPC_URL_2=
|
|
|
175
170
|
|
|
176
171
|
## Usage Example
|
|
177
172
|
|
|
178
|
-
### Generating
|
|
173
|
+
### Generating signature
|
|
179
174
|
|
|
180
175
|
```python
|
|
181
|
-
from payra_sdk import PayraUtils,
|
|
176
|
+
from payra_sdk import PayraUtils, PayraSignature, PayraSDKException
|
|
182
177
|
|
|
183
178
|
try:
|
|
184
179
|
# Convert amount to smallest unit (wei or token decimals
|
|
@@ -187,17 +182,17 @@ try:
|
|
|
187
182
|
PAYMENT_DATA = {
|
|
188
183
|
"network": "polygon",
|
|
189
184
|
"tokenAddress": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F", # USDT on Polygon
|
|
190
|
-
"orderId": "
|
|
185
|
+
"orderId": "ord-258",
|
|
191
186
|
"amountWei": amount_wei, # e.g. 3.34 USDT in smallest unit
|
|
192
187
|
"timestamp": 1753826059, # current Unix timestamp
|
|
193
188
|
"payerAddress": "0xe6c961D6ad9a27Ea8e5d99e40abaC365DE9Cc162"
|
|
194
189
|
}
|
|
195
190
|
|
|
196
191
|
# Initialize signer
|
|
197
|
-
|
|
192
|
+
payra_signature = PayraSignature()
|
|
198
193
|
|
|
199
194
|
# Generate cryptographic signature
|
|
200
|
-
signature =
|
|
195
|
+
signature = payra_signature.generate(
|
|
201
196
|
network=PAYMENT_DATA["network"],
|
|
202
197
|
token_address=PAYMENT_DATA["tokenAddress"],
|
|
203
198
|
order_id=PAYMENT_DATA["orderId"],
|
|
@@ -227,13 +222,13 @@ except Exception as e:
|
|
|
227
222
|
#### Behind the Scenes
|
|
228
223
|
|
|
229
224
|
1. The backend converts the amount to the smallest blockchain unit (e.g. wei).
|
|
230
|
-
2. A `
|
|
225
|
+
2. A `PayraSignature` instance is created using your signature key from `.env`
|
|
231
226
|
3. It generates an ECDSA signature that is fully verifiable on-chain by the Payra smart contract.
|
|
232
227
|
4. 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.
|
|
233
228
|
|
|
234
229
|
---
|
|
235
230
|
|
|
236
|
-
### Get Order
|
|
231
|
+
### Get Order Details
|
|
237
232
|
|
|
238
233
|
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:
|
|
239
234
|
- whether the order has been paid,
|
|
@@ -245,19 +240,19 @@ Retrieve **full payment details** for a specific order from the Payra smart cont
|
|
|
245
240
|
Use this method when you need **detailed information** about the payment or want to display full transaction data.
|
|
246
241
|
|
|
247
242
|
```python
|
|
248
|
-
from payra_sdk import
|
|
243
|
+
from payra_sdk import PayraOrderService, PayraSDKException
|
|
249
244
|
|
|
250
245
|
try:
|
|
251
246
|
ORDER_ID = "ord-258"
|
|
252
247
|
# Initialize verifier for a specific network
|
|
253
|
-
|
|
248
|
+
order_service = PayraOrderService("polygon")
|
|
254
249
|
|
|
255
|
-
print("\nGet order
|
|
256
|
-
|
|
250
|
+
print("\nGet order details...")
|
|
251
|
+
details = order_service.get_details(ORDER_ID)
|
|
257
252
|
|
|
258
253
|
print("Order ID:", ORDER_ID)
|
|
259
|
-
print("
|
|
260
|
-
|
|
254
|
+
print("Details:", details)
|
|
255
|
+
|
|
261
256
|
except PayraSDKException as e:
|
|
262
257
|
print(f"Payra SDK error: {e}")
|
|
263
258
|
except Exception as e:
|
|
@@ -266,15 +261,15 @@ except Exception as e:
|
|
|
266
261
|
|
|
267
262
|
#### Behind the Scenes
|
|
268
263
|
|
|
269
|
-
1. The backend initializes a `
|
|
270
|
-
2. It calls `
|
|
264
|
+
1. The backend initializes a `PayraOrderService` object for the desired blockchain network.
|
|
265
|
+
2. It calls `get_details(order_id)` to get transaction details from blockchain.
|
|
271
266
|
3. The function returns a dictionary with:
|
|
272
267
|
|
|
273
268
|
```python
|
|
274
269
|
{
|
|
275
270
|
"success": True,
|
|
276
271
|
"paid": True,
|
|
277
|
-
"error": None
|
|
272
|
+
"error": None,
|
|
278
273
|
"toke": '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
|
|
279
274
|
"amount": 400000,
|
|
280
275
|
"fee": 3600,
|
|
@@ -291,16 +286,16 @@ Perform a **simple payment check** for a specific order. This method only verifi
|
|
|
291
286
|
Use this method when you only need a **quick boolean confirmation** of the payment status.
|
|
292
287
|
|
|
293
288
|
```python
|
|
294
|
-
from payra_sdk import
|
|
289
|
+
from payra_sdk import PayraOrderService, PayraSDKException
|
|
295
290
|
|
|
296
291
|
try:
|
|
297
292
|
ORDER_ID = "ord-258"
|
|
298
293
|
|
|
299
294
|
# Initialize verifier for a specific network
|
|
300
|
-
|
|
295
|
+
order_service = PayraOrderService("polygon")
|
|
301
296
|
|
|
302
297
|
print("\nChecking order status...")
|
|
303
|
-
result =
|
|
298
|
+
result = order_service.is_paid(ORDER_ID)
|
|
304
299
|
|
|
305
300
|
print("Order ID:", ORDER_ID)
|
|
306
301
|
print("Result:", result)
|
|
@@ -320,8 +315,8 @@ except Exception as e:
|
|
|
320
315
|
|
|
321
316
|
#### Behind the Scenes
|
|
322
317
|
|
|
323
|
-
1. The backend initializes a `
|
|
324
|
-
2. It calls `
|
|
318
|
+
1. The backend initializes a `PayraOrderService` object for the desired blockchain network.
|
|
319
|
+
2. It calls `is_paid(order_id)` to check if the order transaction exists and is confirmed on-chain.
|
|
325
320
|
3. The function returns a dictionary with:
|
|
326
321
|
```python
|
|
327
322
|
{
|
|
@@ -365,25 +360,23 @@ print(f"100 EUR = {usd_value} USD")
|
|
|
365
360
|
- `get_decimals(network, token)` – Returns the number of decimals for the given token on that network.
|
|
366
361
|
- `convert_to_usd(amount, currency)` – Converts fiat amounts (e.g. EUR, GBP) to USD using your ExchangeRate API key.
|
|
367
362
|
|
|
368
|
-
|
|
369
363
|
## Testing
|
|
370
364
|
|
|
371
365
|
You can run the included `examples` to test signing and verification:
|
|
372
366
|
|
|
373
367
|
```python
|
|
374
368
|
python3 example_signature.py
|
|
375
|
-
python3
|
|
369
|
+
python3 example_order_get_details.py
|
|
370
|
+
python3 example_order_is_paid.py
|
|
376
371
|
python3 example_utils.py
|
|
377
372
|
```
|
|
378
373
|
|
|
379
374
|
Make sure your `.env` file contains correct values for the `network` being used.
|
|
380
375
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
- Always verify your `.env` configuration before running any signing or on-chain verification examples.
|
|
384
|
-
- The SDK examples are safe to run, they use **read-only RPC calls** (no real transactions are broadcast).
|
|
385
|
-
- You can modify `example_signature.py` to test custom token addresses or order parameters.
|
|
376
|
+
## Security Notice
|
|
386
377
|
|
|
378
|
+
Never expose your signature key in frontend or client-side code.
|
|
379
|
+
This SDK is **server-side only** and must be used securely on your backend. Never use it in frontend or browser environments. Also, never commit your `.env` file to version control.
|
|
387
380
|
|
|
388
381
|
## Projects
|
|
389
382
|
|
|
@@ -398,7 +391,6 @@ Make sure your `.env` file contains correct values for the `network` being used.
|
|
|
398
391
|
- [https://payra.xyz](https://payra.xyz)
|
|
399
392
|
- [https://payra.eth](https://payra.eth.limo) - suporrted by Brave and Opera Browser or .limo
|
|
400
393
|
|
|
401
|
-
|
|
402
394
|
## Social Media
|
|
403
395
|
|
|
404
396
|
- [Telegram Payra Group](https://t.me/+GhTyJJrd4SMyMDA0)
|
|
@@ -407,4 +399,5 @@ Make sure your `.env` file contains correct values for the `network` being used.
|
|
|
407
399
|
- [Dev.to](https://dev.to/payracash)
|
|
408
400
|
|
|
409
401
|
## License
|
|
402
|
+
|
|
410
403
|
MIT © [Payra](https://payra.cash)
|
|
@@ -4,8 +4,7 @@ Official **Python SDK** for integrating **Payra's on-chain payment system** into
|
|
|
4
4
|
|
|
5
5
|
This SDK provides:
|
|
6
6
|
- Secure generation of **ECDSA signatures** compatible with the Payra smart contract, used for order payment verification.
|
|
7
|
-
- Simple methods for **checking the on-chain
|
|
8
|
-
|
|
7
|
+
- Simple methods for **checking the on-chain details of orders** to confirm completed payments.
|
|
9
8
|
|
|
10
9
|
## How It Works
|
|
11
10
|
|
|
@@ -24,20 +23,18 @@ The typical flow for signing and verifying a Payra transaction:
|
|
|
24
23
|
|
|
25
24
|
This process ensures full compatibility between your backend and Payra’s on-chain verification logic.
|
|
26
25
|
|
|
27
|
-
|
|
28
26
|
## Features
|
|
29
27
|
|
|
30
28
|
- Generates **Ethereum ECDSA signatures** using the `secp256k1` curve.
|
|
31
29
|
- Fully compatible with **Payra's Solidity smart contracts** (`ERC-1155` payment verification).
|
|
32
30
|
- Supports `.env` and `config/payra.php` configuration for multiple blockchain networks.
|
|
33
31
|
- Laravel IoC container integration (easy dependency injection)
|
|
34
|
-
- Verifies **order payment
|
|
32
|
+
- Verifies **order payment details directly on-chain** via RPC or blockchain explorer API.
|
|
35
33
|
- Provides **secure backend integration** for signing and verifying transactions.
|
|
36
34
|
- Includes optional utility helpers for:
|
|
37
35
|
- **Currency conversion** (via [ExchangeRate API](https://www.exchangerate-api.com/))
|
|
38
36
|
- **USD ⇄ WEI** conversion for token precision handling.
|
|
39
37
|
|
|
40
|
-
|
|
41
38
|
## Setup
|
|
42
39
|
|
|
43
40
|
Before installing this package, make sure you have an active **Payra** account:
|
|
@@ -63,7 +60,6 @@ To obtain your **RPC URLs** which are required for reading on-chain order status
|
|
|
63
60
|
Optional (recommended):
|
|
64
61
|
- Create a free API key at [ExchangeRate API](https://www.exchangerate-api.com/) to enable **automatic fiat → USD conversions** using the built-in utility helpers.
|
|
65
62
|
|
|
66
|
-
|
|
67
63
|
## Installation
|
|
68
64
|
|
|
69
65
|
### From PyPI
|
|
@@ -105,7 +101,6 @@ cp .env.example .env
|
|
|
105
101
|
|
|
106
102
|
This file stores your **private configuration** and connection settings for all supported networks. Never commit `.env` to version control.
|
|
107
103
|
|
|
108
|
-
|
|
109
104
|
### Required Variables
|
|
110
105
|
|
|
111
106
|
#### Exchange Rate (optional)
|
|
@@ -140,9 +135,9 @@ PAYRA_LINEA_RPC_URL_2=
|
|
|
140
135
|
|
|
141
136
|
- The cache automatically refreshes when it expires.
|
|
142
137
|
- You can adjust the cache duration by setting `PAYRA_EXCHANGE_RATE_CACHE_TIME`:
|
|
143
|
-
- `5` → cache for 5 minutes
|
|
144
|
-
- `60` → cache for 1 hour
|
|
145
|
-
- `720` → cache for 12 hours (default)
|
|
138
|
+
- `5` → cache for 5 minutes
|
|
139
|
+
- `60` → cache for 1 hour
|
|
140
|
+
- `720` → cache for 12 hours (default)
|
|
146
141
|
- Each network (Polygon, Ethereum, Linea) has its own **merchant ID**, **signature key**, and **RPC URLs**.
|
|
147
142
|
- The SDK automatically detects which chain configuration to use based on the selected network.
|
|
148
143
|
- You can use multiple RPC URLs for redundancy (the SDK will automatically fall back if one fails).
|
|
@@ -151,10 +146,10 @@ PAYRA_LINEA_RPC_URL_2=
|
|
|
151
146
|
|
|
152
147
|
## Usage Example
|
|
153
148
|
|
|
154
|
-
### Generating
|
|
149
|
+
### Generating signature
|
|
155
150
|
|
|
156
151
|
```python
|
|
157
|
-
from payra_sdk import PayraUtils,
|
|
152
|
+
from payra_sdk import PayraUtils, PayraSignature, PayraSDKException
|
|
158
153
|
|
|
159
154
|
try:
|
|
160
155
|
# Convert amount to smallest unit (wei or token decimals
|
|
@@ -163,17 +158,17 @@ try:
|
|
|
163
158
|
PAYMENT_DATA = {
|
|
164
159
|
"network": "polygon",
|
|
165
160
|
"tokenAddress": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F", # USDT on Polygon
|
|
166
|
-
"orderId": "
|
|
161
|
+
"orderId": "ord-258",
|
|
167
162
|
"amountWei": amount_wei, # e.g. 3.34 USDT in smallest unit
|
|
168
163
|
"timestamp": 1753826059, # current Unix timestamp
|
|
169
164
|
"payerAddress": "0xe6c961D6ad9a27Ea8e5d99e40abaC365DE9Cc162"
|
|
170
165
|
}
|
|
171
166
|
|
|
172
167
|
# Initialize signer
|
|
173
|
-
|
|
168
|
+
payra_signature = PayraSignature()
|
|
174
169
|
|
|
175
170
|
# Generate cryptographic signature
|
|
176
|
-
signature =
|
|
171
|
+
signature = payra_signature.generate(
|
|
177
172
|
network=PAYMENT_DATA["network"],
|
|
178
173
|
token_address=PAYMENT_DATA["tokenAddress"],
|
|
179
174
|
order_id=PAYMENT_DATA["orderId"],
|
|
@@ -203,13 +198,13 @@ except Exception as e:
|
|
|
203
198
|
#### Behind the Scenes
|
|
204
199
|
|
|
205
200
|
1. The backend converts the amount to the smallest blockchain unit (e.g. wei).
|
|
206
|
-
2. A `
|
|
201
|
+
2. A `PayraSignature` instance is created using your signature key from `.env`
|
|
207
202
|
3. It generates an ECDSA signature that is fully verifiable on-chain by the Payra smart contract.
|
|
208
203
|
4. 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.
|
|
209
204
|
|
|
210
205
|
---
|
|
211
206
|
|
|
212
|
-
### Get Order
|
|
207
|
+
### Get Order Details
|
|
213
208
|
|
|
214
209
|
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:
|
|
215
210
|
- whether the order has been paid,
|
|
@@ -221,19 +216,19 @@ Retrieve **full payment details** for a specific order from the Payra smart cont
|
|
|
221
216
|
Use this method when you need **detailed information** about the payment or want to display full transaction data.
|
|
222
217
|
|
|
223
218
|
```python
|
|
224
|
-
from payra_sdk import
|
|
219
|
+
from payra_sdk import PayraOrderService, PayraSDKException
|
|
225
220
|
|
|
226
221
|
try:
|
|
227
222
|
ORDER_ID = "ord-258"
|
|
228
223
|
# Initialize verifier for a specific network
|
|
229
|
-
|
|
224
|
+
order_service = PayraOrderService("polygon")
|
|
230
225
|
|
|
231
|
-
print("\nGet order
|
|
232
|
-
|
|
226
|
+
print("\nGet order details...")
|
|
227
|
+
details = order_service.get_details(ORDER_ID)
|
|
233
228
|
|
|
234
229
|
print("Order ID:", ORDER_ID)
|
|
235
|
-
print("
|
|
236
|
-
|
|
230
|
+
print("Details:", details)
|
|
231
|
+
|
|
237
232
|
except PayraSDKException as e:
|
|
238
233
|
print(f"Payra SDK error: {e}")
|
|
239
234
|
except Exception as e:
|
|
@@ -242,15 +237,15 @@ except Exception as e:
|
|
|
242
237
|
|
|
243
238
|
#### Behind the Scenes
|
|
244
239
|
|
|
245
|
-
1. The backend initializes a `
|
|
246
|
-
2. It calls `
|
|
240
|
+
1. The backend initializes a `PayraOrderService` object for the desired blockchain network.
|
|
241
|
+
2. It calls `get_details(order_id)` to get transaction details from blockchain.
|
|
247
242
|
3. The function returns a dictionary with:
|
|
248
243
|
|
|
249
244
|
```python
|
|
250
245
|
{
|
|
251
246
|
"success": True,
|
|
252
247
|
"paid": True,
|
|
253
|
-
"error": None
|
|
248
|
+
"error": None,
|
|
254
249
|
"toke": '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
|
|
255
250
|
"amount": 400000,
|
|
256
251
|
"fee": 3600,
|
|
@@ -267,16 +262,16 @@ Perform a **simple payment check** for a specific order. This method only verifi
|
|
|
267
262
|
Use this method when you only need a **quick boolean confirmation** of the payment status.
|
|
268
263
|
|
|
269
264
|
```python
|
|
270
|
-
from payra_sdk import
|
|
265
|
+
from payra_sdk import PayraOrderService, PayraSDKException
|
|
271
266
|
|
|
272
267
|
try:
|
|
273
268
|
ORDER_ID = "ord-258"
|
|
274
269
|
|
|
275
270
|
# Initialize verifier for a specific network
|
|
276
|
-
|
|
271
|
+
order_service = PayraOrderService("polygon")
|
|
277
272
|
|
|
278
273
|
print("\nChecking order status...")
|
|
279
|
-
result =
|
|
274
|
+
result = order_service.is_paid(ORDER_ID)
|
|
280
275
|
|
|
281
276
|
print("Order ID:", ORDER_ID)
|
|
282
277
|
print("Result:", result)
|
|
@@ -296,8 +291,8 @@ except Exception as e:
|
|
|
296
291
|
|
|
297
292
|
#### Behind the Scenes
|
|
298
293
|
|
|
299
|
-
1. The backend initializes a `
|
|
300
|
-
2. It calls `
|
|
294
|
+
1. The backend initializes a `PayraOrderService` object for the desired blockchain network.
|
|
295
|
+
2. It calls `is_paid(order_id)` to check if the order transaction exists and is confirmed on-chain.
|
|
301
296
|
3. The function returns a dictionary with:
|
|
302
297
|
```python
|
|
303
298
|
{
|
|
@@ -341,25 +336,23 @@ print(f"100 EUR = {usd_value} USD")
|
|
|
341
336
|
- `get_decimals(network, token)` – Returns the number of decimals for the given token on that network.
|
|
342
337
|
- `convert_to_usd(amount, currency)` – Converts fiat amounts (e.g. EUR, GBP) to USD using your ExchangeRate API key.
|
|
343
338
|
|
|
344
|
-
|
|
345
339
|
## Testing
|
|
346
340
|
|
|
347
341
|
You can run the included `examples` to test signing and verification:
|
|
348
342
|
|
|
349
343
|
```python
|
|
350
344
|
python3 example_signature.py
|
|
351
|
-
python3
|
|
345
|
+
python3 example_order_get_details.py
|
|
346
|
+
python3 example_order_is_paid.py
|
|
352
347
|
python3 example_utils.py
|
|
353
348
|
```
|
|
354
349
|
|
|
355
350
|
Make sure your `.env` file contains correct values for the `network` being used.
|
|
356
351
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
- Always verify your `.env` configuration before running any signing or on-chain verification examples.
|
|
360
|
-
- The SDK examples are safe to run, they use **read-only RPC calls** (no real transactions are broadcast).
|
|
361
|
-
- You can modify `example_signature.py` to test custom token addresses or order parameters.
|
|
352
|
+
## Security Notice
|
|
362
353
|
|
|
354
|
+
Never expose your signature key in frontend or client-side code.
|
|
355
|
+
This SDK is **server-side only** and must be used securely on your backend. Never use it in frontend or browser environments. Also, never commit your `.env` file to version control.
|
|
363
356
|
|
|
364
357
|
## Projects
|
|
365
358
|
|
|
@@ -374,7 +367,6 @@ Make sure your `.env` file contains correct values for the `network` being used.
|
|
|
374
367
|
- [https://payra.xyz](https://payra.xyz)
|
|
375
368
|
- [https://payra.eth](https://payra.eth.limo) - suporrted by Brave and Opera Browser or .limo
|
|
376
369
|
|
|
377
|
-
|
|
378
370
|
## Social Media
|
|
379
371
|
|
|
380
372
|
- [Telegram Payra Group](https://t.me/+GhTyJJrd4SMyMDA0)
|
|
@@ -383,4 +375,5 @@ Make sure your `.env` file contains correct values for the `network` being used.
|
|
|
383
375
|
- [Dev.to](https://dev.to/payracash)
|
|
384
376
|
|
|
385
377
|
## License
|
|
378
|
+
|
|
386
379
|
MIT © [Payra](https://payra.cash)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# payra-sdk-python/payra_sdk/__init__.py
|
|
2
2
|
|
|
3
|
-
from .signature import
|
|
4
|
-
from .
|
|
3
|
+
from .signature import PayraSignature
|
|
4
|
+
from .order_service import PayraOrderService
|
|
5
5
|
from .exceptions import PayraSDKException, InvalidArgumentError, SignatureError
|
|
6
6
|
from .utils import PayraUtils
|
|
7
7
|
|
|
8
8
|
__all__ = [
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"PayraSignature",
|
|
10
|
+
"PayraOrderService",
|
|
11
11
|
"PayraSDKException",
|
|
12
12
|
"InvalidArgumentError",
|
|
13
13
|
"SignatureError",
|
payra_sdk-1.2.6/payra_sdk/order_verification.py → payra_sdk-1.2.8/payra_sdk/order_service.py
RENAMED
|
@@ -11,7 +11,7 @@ from .exceptions import InvalidArgumentError, SignatureError
|
|
|
11
11
|
# load env
|
|
12
12
|
load_dotenv()
|
|
13
13
|
|
|
14
|
-
class
|
|
14
|
+
class PayraOrderService:
|
|
15
15
|
"""
|
|
16
16
|
SDK for verifying if an order has been paid using the Payra smart contract.
|
|
17
17
|
"""
|
|
@@ -22,7 +22,7 @@ class PayraOrderVerification:
|
|
|
22
22
|
|
|
23
23
|
self.web3 = Web3(Web3.HTTPProvider(self.rpc_url))
|
|
24
24
|
if not self.web3.is_connected():
|
|
25
|
-
raise ConnectionError(f"Failed to connect to
|
|
25
|
+
raise ConnectionError(f"Failed to connect to RPC for {self.network}")
|
|
26
26
|
|
|
27
27
|
self.merchant_id = os.getenv(f"PAYRA_{self.network}_MERCHANT_ID")
|
|
28
28
|
self.gateway_address = os.getenv(f"PAYRA_{self.network}_OCP_GATEWAY_CONTRACT_ADDRESS")
|
|
@@ -53,7 +53,7 @@ class PayraOrderVerification:
|
|
|
53
53
|
# Return the actual contract responsible for order data
|
|
54
54
|
return self.web3.eth.contract(address=user_data_address, abi=self.abi)
|
|
55
55
|
|
|
56
|
-
def
|
|
56
|
+
def is_paid(self, order_id: str) -> dict:
|
|
57
57
|
"""
|
|
58
58
|
Verify if an order is paid on Payra contract.
|
|
59
59
|
"""
|
|
@@ -76,7 +76,7 @@ class PayraOrderVerification:
|
|
|
76
76
|
"error": str(e)
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
def
|
|
79
|
+
def get_details(self, order_id: str) -> dict:
|
|
80
80
|
"""
|
|
81
81
|
Detailed status of an order from Payra smart contract.
|
|
82
82
|
Equivalent to getOrderDetails in Node.js version.
|
|
@@ -12,7 +12,7 @@ from .exceptions import InvalidArgumentError, SignatureError
|
|
|
12
12
|
# Load environment variables from .env file
|
|
13
13
|
load_dotenv()
|
|
14
14
|
|
|
15
|
-
class
|
|
15
|
+
class PayraSignature:
|
|
16
16
|
"""
|
|
17
17
|
SDK for generating Payra payment signatures on the backend.
|
|
18
18
|
This version assumes `amount_wei` is already in the token's smallest unit (e.g., wei)
|
|
@@ -22,10 +22,10 @@ class PayraSignatureGenerator:
|
|
|
22
22
|
def __init__(self):
|
|
23
23
|
|
|
24
24
|
"""
|
|
25
|
-
Initializes the
|
|
25
|
+
Initializes the PayraSignature.
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
|
-
def
|
|
28
|
+
def generate(
|
|
29
29
|
self,
|
|
30
30
|
network: str,
|
|
31
31
|
token_address: str,
|
|
@@ -117,7 +117,7 @@ class PayraSignatureGenerator:
|
|
|
117
117
|
raise SignatureError(f"Error generating signature: {e}")
|
|
118
118
|
|
|
119
119
|
# Optional: Add a verification method if you ever need to verify a signature offline
|
|
120
|
-
def
|
|
120
|
+
def verify(
|
|
121
121
|
self,
|
|
122
122
|
network: str,
|
|
123
123
|
token_address: str,
|
|
@@ -168,7 +168,7 @@ class PayraSignatureGenerator:
|
|
|
168
168
|
) -> bytes:
|
|
169
169
|
"""
|
|
170
170
|
Generates the raw Keccak256 hash of the ABI-encoded payment data.
|
|
171
|
-
This is a helper for internal use, especially for `
|
|
171
|
+
This is a helper for internal use, especially for `verify`.
|
|
172
172
|
"""
|
|
173
173
|
checksum_token_address = to_checksum_address(token_address)
|
|
174
174
|
checksum_payer_address = to_checksum_address(payer_address)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: payra_sdk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.8
|
|
4
4
|
Summary: Python SDK for Payra payment signature generation (backend)
|
|
5
5
|
Author: Your Name
|
|
6
6
|
Author-email: Wraith <support@payra.cash>
|
|
@@ -28,8 +28,7 @@ Official **Python SDK** for integrating **Payra's on-chain payment system** into
|
|
|
28
28
|
|
|
29
29
|
This SDK provides:
|
|
30
30
|
- Secure generation of **ECDSA signatures** compatible with the Payra smart contract, used for order payment verification.
|
|
31
|
-
- Simple methods for **checking the on-chain
|
|
32
|
-
|
|
31
|
+
- Simple methods for **checking the on-chain details of orders** to confirm completed payments.
|
|
33
32
|
|
|
34
33
|
## How It Works
|
|
35
34
|
|
|
@@ -48,20 +47,18 @@ The typical flow for signing and verifying a Payra transaction:
|
|
|
48
47
|
|
|
49
48
|
This process ensures full compatibility between your backend and Payra’s on-chain verification logic.
|
|
50
49
|
|
|
51
|
-
|
|
52
50
|
## Features
|
|
53
51
|
|
|
54
52
|
- Generates **Ethereum ECDSA signatures** using the `secp256k1` curve.
|
|
55
53
|
- Fully compatible with **Payra's Solidity smart contracts** (`ERC-1155` payment verification).
|
|
56
54
|
- Supports `.env` and `config/payra.php` configuration for multiple blockchain networks.
|
|
57
55
|
- Laravel IoC container integration (easy dependency injection)
|
|
58
|
-
- Verifies **order payment
|
|
56
|
+
- Verifies **order payment details directly on-chain** via RPC or blockchain explorer API.
|
|
59
57
|
- Provides **secure backend integration** for signing and verifying transactions.
|
|
60
58
|
- Includes optional utility helpers for:
|
|
61
59
|
- **Currency conversion** (via [ExchangeRate API](https://www.exchangerate-api.com/))
|
|
62
60
|
- **USD ⇄ WEI** conversion for token precision handling.
|
|
63
61
|
|
|
64
|
-
|
|
65
62
|
## Setup
|
|
66
63
|
|
|
67
64
|
Before installing this package, make sure you have an active **Payra** account:
|
|
@@ -87,7 +84,6 @@ To obtain your **RPC URLs** which are required for reading on-chain order status
|
|
|
87
84
|
Optional (recommended):
|
|
88
85
|
- Create a free API key at [ExchangeRate API](https://www.exchangerate-api.com/) to enable **automatic fiat → USD conversions** using the built-in utility helpers.
|
|
89
86
|
|
|
90
|
-
|
|
91
87
|
## Installation
|
|
92
88
|
|
|
93
89
|
### From PyPI
|
|
@@ -129,7 +125,6 @@ cp .env.example .env
|
|
|
129
125
|
|
|
130
126
|
This file stores your **private configuration** and connection settings for all supported networks. Never commit `.env` to version control.
|
|
131
127
|
|
|
132
|
-
|
|
133
128
|
### Required Variables
|
|
134
129
|
|
|
135
130
|
#### Exchange Rate (optional)
|
|
@@ -164,9 +159,9 @@ PAYRA_LINEA_RPC_URL_2=
|
|
|
164
159
|
|
|
165
160
|
- The cache automatically refreshes when it expires.
|
|
166
161
|
- You can adjust the cache duration by setting `PAYRA_EXCHANGE_RATE_CACHE_TIME`:
|
|
167
|
-
- `5` → cache for 5 minutes
|
|
168
|
-
- `60` → cache for 1 hour
|
|
169
|
-
- `720` → cache for 12 hours (default)
|
|
162
|
+
- `5` → cache for 5 minutes
|
|
163
|
+
- `60` → cache for 1 hour
|
|
164
|
+
- `720` → cache for 12 hours (default)
|
|
170
165
|
- Each network (Polygon, Ethereum, Linea) has its own **merchant ID**, **signature key**, and **RPC URLs**.
|
|
171
166
|
- The SDK automatically detects which chain configuration to use based on the selected network.
|
|
172
167
|
- You can use multiple RPC URLs for redundancy (the SDK will automatically fall back if one fails).
|
|
@@ -175,10 +170,10 @@ PAYRA_LINEA_RPC_URL_2=
|
|
|
175
170
|
|
|
176
171
|
## Usage Example
|
|
177
172
|
|
|
178
|
-
### Generating
|
|
173
|
+
### Generating signature
|
|
179
174
|
|
|
180
175
|
```python
|
|
181
|
-
from payra_sdk import PayraUtils,
|
|
176
|
+
from payra_sdk import PayraUtils, PayraSignature, PayraSDKException
|
|
182
177
|
|
|
183
178
|
try:
|
|
184
179
|
# Convert amount to smallest unit (wei or token decimals
|
|
@@ -187,17 +182,17 @@ try:
|
|
|
187
182
|
PAYMENT_DATA = {
|
|
188
183
|
"network": "polygon",
|
|
189
184
|
"tokenAddress": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F", # USDT on Polygon
|
|
190
|
-
"orderId": "
|
|
185
|
+
"orderId": "ord-258",
|
|
191
186
|
"amountWei": amount_wei, # e.g. 3.34 USDT in smallest unit
|
|
192
187
|
"timestamp": 1753826059, # current Unix timestamp
|
|
193
188
|
"payerAddress": "0xe6c961D6ad9a27Ea8e5d99e40abaC365DE9Cc162"
|
|
194
189
|
}
|
|
195
190
|
|
|
196
191
|
# Initialize signer
|
|
197
|
-
|
|
192
|
+
payra_signature = PayraSignature()
|
|
198
193
|
|
|
199
194
|
# Generate cryptographic signature
|
|
200
|
-
signature =
|
|
195
|
+
signature = payra_signature.generate(
|
|
201
196
|
network=PAYMENT_DATA["network"],
|
|
202
197
|
token_address=PAYMENT_DATA["tokenAddress"],
|
|
203
198
|
order_id=PAYMENT_DATA["orderId"],
|
|
@@ -227,13 +222,13 @@ except Exception as e:
|
|
|
227
222
|
#### Behind the Scenes
|
|
228
223
|
|
|
229
224
|
1. The backend converts the amount to the smallest blockchain unit (e.g. wei).
|
|
230
|
-
2. A `
|
|
225
|
+
2. A `PayraSignature` instance is created using your signature key from `.env`
|
|
231
226
|
3. It generates an ECDSA signature that is fully verifiable on-chain by the Payra smart contract.
|
|
232
227
|
4. 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.
|
|
233
228
|
|
|
234
229
|
---
|
|
235
230
|
|
|
236
|
-
### Get Order
|
|
231
|
+
### Get Order Details
|
|
237
232
|
|
|
238
233
|
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:
|
|
239
234
|
- whether the order has been paid,
|
|
@@ -245,19 +240,19 @@ Retrieve **full payment details** for a specific order from the Payra smart cont
|
|
|
245
240
|
Use this method when you need **detailed information** about the payment or want to display full transaction data.
|
|
246
241
|
|
|
247
242
|
```python
|
|
248
|
-
from payra_sdk import
|
|
243
|
+
from payra_sdk import PayraOrderService, PayraSDKException
|
|
249
244
|
|
|
250
245
|
try:
|
|
251
246
|
ORDER_ID = "ord-258"
|
|
252
247
|
# Initialize verifier for a specific network
|
|
253
|
-
|
|
248
|
+
order_service = PayraOrderService("polygon")
|
|
254
249
|
|
|
255
|
-
print("\nGet order
|
|
256
|
-
|
|
250
|
+
print("\nGet order details...")
|
|
251
|
+
details = order_service.get_details(ORDER_ID)
|
|
257
252
|
|
|
258
253
|
print("Order ID:", ORDER_ID)
|
|
259
|
-
print("
|
|
260
|
-
|
|
254
|
+
print("Details:", details)
|
|
255
|
+
|
|
261
256
|
except PayraSDKException as e:
|
|
262
257
|
print(f"Payra SDK error: {e}")
|
|
263
258
|
except Exception as e:
|
|
@@ -266,15 +261,15 @@ except Exception as e:
|
|
|
266
261
|
|
|
267
262
|
#### Behind the Scenes
|
|
268
263
|
|
|
269
|
-
1. The backend initializes a `
|
|
270
|
-
2. It calls `
|
|
264
|
+
1. The backend initializes a `PayraOrderService` object for the desired blockchain network.
|
|
265
|
+
2. It calls `get_details(order_id)` to get transaction details from blockchain.
|
|
271
266
|
3. The function returns a dictionary with:
|
|
272
267
|
|
|
273
268
|
```python
|
|
274
269
|
{
|
|
275
270
|
"success": True,
|
|
276
271
|
"paid": True,
|
|
277
|
-
"error": None
|
|
272
|
+
"error": None,
|
|
278
273
|
"toke": '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
|
|
279
274
|
"amount": 400000,
|
|
280
275
|
"fee": 3600,
|
|
@@ -291,16 +286,16 @@ Perform a **simple payment check** for a specific order. This method only verifi
|
|
|
291
286
|
Use this method when you only need a **quick boolean confirmation** of the payment status.
|
|
292
287
|
|
|
293
288
|
```python
|
|
294
|
-
from payra_sdk import
|
|
289
|
+
from payra_sdk import PayraOrderService, PayraSDKException
|
|
295
290
|
|
|
296
291
|
try:
|
|
297
292
|
ORDER_ID = "ord-258"
|
|
298
293
|
|
|
299
294
|
# Initialize verifier for a specific network
|
|
300
|
-
|
|
295
|
+
order_service = PayraOrderService("polygon")
|
|
301
296
|
|
|
302
297
|
print("\nChecking order status...")
|
|
303
|
-
result =
|
|
298
|
+
result = order_service.is_paid(ORDER_ID)
|
|
304
299
|
|
|
305
300
|
print("Order ID:", ORDER_ID)
|
|
306
301
|
print("Result:", result)
|
|
@@ -320,8 +315,8 @@ except Exception as e:
|
|
|
320
315
|
|
|
321
316
|
#### Behind the Scenes
|
|
322
317
|
|
|
323
|
-
1. The backend initializes a `
|
|
324
|
-
2. It calls `
|
|
318
|
+
1. The backend initializes a `PayraOrderService` object for the desired blockchain network.
|
|
319
|
+
2. It calls `is_paid(order_id)` to check if the order transaction exists and is confirmed on-chain.
|
|
325
320
|
3. The function returns a dictionary with:
|
|
326
321
|
```python
|
|
327
322
|
{
|
|
@@ -365,25 +360,23 @@ print(f"100 EUR = {usd_value} USD")
|
|
|
365
360
|
- `get_decimals(network, token)` – Returns the number of decimals for the given token on that network.
|
|
366
361
|
- `convert_to_usd(amount, currency)` – Converts fiat amounts (e.g. EUR, GBP) to USD using your ExchangeRate API key.
|
|
367
362
|
|
|
368
|
-
|
|
369
363
|
## Testing
|
|
370
364
|
|
|
371
365
|
You can run the included `examples` to test signing and verification:
|
|
372
366
|
|
|
373
367
|
```python
|
|
374
368
|
python3 example_signature.py
|
|
375
|
-
python3
|
|
369
|
+
python3 example_order_get_details.py
|
|
370
|
+
python3 example_order_is_paid.py
|
|
376
371
|
python3 example_utils.py
|
|
377
372
|
```
|
|
378
373
|
|
|
379
374
|
Make sure your `.env` file contains correct values for the `network` being used.
|
|
380
375
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
- Always verify your `.env` configuration before running any signing or on-chain verification examples.
|
|
384
|
-
- The SDK examples are safe to run, they use **read-only RPC calls** (no real transactions are broadcast).
|
|
385
|
-
- You can modify `example_signature.py` to test custom token addresses or order parameters.
|
|
376
|
+
## Security Notice
|
|
386
377
|
|
|
378
|
+
Never expose your signature key in frontend or client-side code.
|
|
379
|
+
This SDK is **server-side only** and must be used securely on your backend. Never use it in frontend or browser environments. Also, never commit your `.env` file to version control.
|
|
387
380
|
|
|
388
381
|
## Projects
|
|
389
382
|
|
|
@@ -398,7 +391,6 @@ Make sure your `.env` file contains correct values for the `network` being used.
|
|
|
398
391
|
- [https://payra.xyz](https://payra.xyz)
|
|
399
392
|
- [https://payra.eth](https://payra.eth.limo) - suporrted by Brave and Opera Browser or .limo
|
|
400
393
|
|
|
401
|
-
|
|
402
394
|
## Social Media
|
|
403
395
|
|
|
404
396
|
- [Telegram Payra Group](https://t.me/+GhTyJJrd4SMyMDA0)
|
|
@@ -407,4 +399,5 @@ Make sure your `.env` file contains correct values for the `network` being used.
|
|
|
407
399
|
- [Dev.to](https://dev.to/payracash)
|
|
408
400
|
|
|
409
401
|
## License
|
|
402
|
+
|
|
410
403
|
MIT © [Payra](https://payra.cash)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|