payra-sdk 1.1.3__tar.gz → 1.2.5__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.
@@ -1,13 +1,20 @@
1
- QUICK_NODE_RPC_API_KEY=your-api-key
1
+ PAYRA_EXCHANGE_RATE_API_KEY=
2
+ PAYRA_EXCHANGE_RATE_CACHE_TIME=720 # in minutes
2
3
 
3
4
  PAYRA_POLYGON_CORE_FORWARD_CONTRACT_ADDRESS=0xf30070da76B55E5cB5750517E4DECBD6Cc5ce5a8
4
5
  PAYRA_POLYGON_PRIVATE_KEY=
5
6
  PAYRA_POLYGON_MERCHANT_ID=
7
+ PAYRA_POLYGON_RPC_URL_1=
8
+ PAYRA_POLYGON_RPC_URL_2=
6
9
 
7
10
  PAYRA_ETHEREUM_CORE_FORWARD_CONTRACT_ADDRESS=
8
11
  PAYRA_ETHEREUM_PRIVATE_KEY=
9
12
  PAYRA_ETHEREUM_MERCHANT_ID=
13
+ PAYRA_ETHEREUM_RPC_URL_1=
14
+ PAYRA_ETHEREUM_RPC_URL_2=
10
15
 
11
16
  PAYRA_LINEA_CORE_FORWARD_CONTRACT_ADDRESS=
12
17
  PAYRA_LINEA_PRIVATE_KEY=
13
18
  PAYRA_LINEA_MERCHANT_ID=
19
+ PAYRA_LINEA_RPC_URL_1=
20
+ PAYRA_LINEA_RPC_URL_2=
@@ -0,0 +1,404 @@
1
+ Metadata-Version: 2.4
2
+ Name: payra_sdk
3
+ Version: 1.2.5
4
+ Summary: Python SDK for Payra payment signature generation (backend)
5
+ Author: Your Name
6
+ Author-email: Wraith <contact@payra.cash>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2025 Wraith
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy...
12
+
13
+ Project-URL: Homepage, https://github.com/payracash
14
+ Project-URL: Source, https://github.com/payracash/payra-sdk-python
15
+ Project-URL: Issues, https://github.com/payracash/payra-sdk-python/issues
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: web3>=6.0.0
20
+ Requires-Dist: eth-abi>=4.0.0
21
+ Requires-Dist: eth-account>=0.10.0
22
+ Requires-Dist: python-dotenv>=1.0.0
23
+ Dynamic: license-file
24
+
25
+
26
+
27
+ # Payra Python SDK
28
+
29
+ Official **Python SDK** for integrating **Payra's on-chain payment system** into your backend applications.
30
+
31
+ This SDK provides:
32
+ - Secure generation of **ECDSA signatures** compatible with the Payra smart contract — used for order payment verification.
33
+ - Simple methods for **checking the on-chain status of orders** to confirm completed payments.
34
+
35
+ ## How It Works
36
+
37
+ The typical flow for signing and verifying a Payra transaction:
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
+ - **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.
50
+
51
+ This process ensures full compatibility between your backend and Payra’s on-chain verification logic.
52
+
53
+ ## Features
54
+
55
+ - Generates **Ethereum ECDSA signatures** using the `secp256k1` curve.
56
+ - Fully compatible with **Payra's Solidity smart contracts** (`ERC-1155` payment verification).
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
+ - Verifies **order payment status directly on-chain** via RPC or blockchain explorer API.
61
+ - Provides **secure backend integration** for signing and verifying transactions.
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.
65
+
66
+ ## Setup
67
+
68
+ Before installing this package, make sure you have an active **Payra** account:
69
+
70
+ [https://payra.cash/products/on-chain-payments/merchant-registration](https://payra.cash/products/on-chain-payments/merchant-registration)
71
+
72
+ Before installing this package, make sure you have a **MerchantID**
73
+
74
+ - Your **Merchant ID** (unique for each blockchain network)
75
+ - Your **Private Key** (used to sign Payra transactions securely)
76
+
77
+ Additionally:
78
+
79
+ - Create a free account at [QuickNode](https://www.quicknode.com/) to obtain your **RPC URLs** - these are required for reading on-chain order statuses directly from the blockchain.
80
+
81
+ Optional (recommended):
82
+
83
+ - Create a free API key at [ExchangeRate API](https://www.exchangerate-api.com/)
84
+ to enable **automatic fiat → USD conversions** using the built-in utility helpers.
85
+
86
+ ## Installation
87
+
88
+ ### From PyPI
89
+
90
+ Install the latest stable version from [PyPI](https://pypi.org/project/payra-sdk/):
91
+
92
+ ```bash
93
+ pip install payra-sdk
94
+ ```
95
+
96
+ ### From Source (for development)
97
+
98
+ Clone and install locally (editable mode for development):
99
+
100
+ ```bash
101
+ git clone https://github.com/payracash/payra-sdk-python.git
102
+ cd payra-sdk-python
103
+
104
+ python3 -m venv venv
105
+ source venv/bin/activate # Windows: venv\Scripts\activate
106
+
107
+ pip install -e .
108
+ ```
109
+
110
+ ### Dependencies
111
+
112
+ This SDK requires:
113
+ - **Python 3.8+**
114
+ - **web3.py**
115
+ - **ecdsa**
116
+ - **python-dotenv**
117
+ - _(optional)_ `requests` and `exchange-rate-api` for fiat conversion utilities.
118
+
119
+ ## Environment Configuration
120
+
121
+ Create a `.env` file in your project root (you can copy from example):
122
+
123
+ ```bash
124
+ cp .env.example .env
125
+ ```
126
+
127
+ This file stores your **private configuration** and connection settings for all supported networks. Never commit `.env` to version control.
128
+
129
+ ### Required Variables
130
+
131
+ #### Exchange Rate (optional)
132
+
133
+ Used for automatic fiat → USD conversions via the built-in Payra utilities.
134
+
135
+ ```bash
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)
139
+
140
+ PAYRA_POLYGON_CORE_FORWARD_CONTRACT_ADDRESS=0xf30070da76B55E5cB5750517E4DECBD6Cc5ce5a8
141
+ PAYRA_POLYGON_PRIVATE_KEY=
142
+ PAYRA_POLYGON_MERCHANT_ID=
143
+ PAYRA_POLYGON_RPC_URL_1=
144
+ PAYRA_POLYGON_RPC_URL_2=
145
+
146
+ PAYRA_ETHEREUM_CORE_FORWARD_CONTRACT_ADDRESS=
147
+ PAYRA_ETHEREUM_PRIVATE_KEY=
148
+ PAYRA_ETHEREUM_MERCHANT_ID=
149
+ PAYRA_ETHEREUM_RPC_URL_1=
150
+ PAYRA_ETHEREUM_RPC_URL_2=
151
+
152
+ PAYRA_LINEA_CORE_FORWARD_CONTRACT_ADDRESS=
153
+ PAYRA_LINEA_PRIVATE_KEY=
154
+ PAYRA_LINEA_MERCHANT_ID=
155
+ PAYRA_LINEA_RPC_URL_1=
156
+ PAYRA_LINEA_RPC_URL_2=
157
+ ```
158
+
159
+ #### Important Notes
160
+
161
+ - The cache automatically refreshes when it expires.
162
+ - You can adjust the cache duration by setting `PAYRA_EXCHANGE_RATE_CACHE_TIME`:
163
+ - `5` → cache for 5 minutes
164
+ - `60` → cache for 1 hour
165
+ - `720` → cache for 12 hours (default)
166
+ - Each network (Polygon, Ethereum, Linea) has its own **merchant ID**, **private key**, and **RPC URLs**.
167
+ - The SDK automatically detects which chain configuration to use based on the selected network.
168
+ - You can use multiple RPC URLs for redundancy (the SDK will automatically fall back if one fails).
169
+ - Contract addresses correspond to the deployed Payra Core Forward contracts per network.
170
+
171
+ ## Usage Example
172
+
173
+ ### Generating and verifying a Payra signature in your backend
174
+
175
+ ```python
176
+ from payra_sdk import PayraUtils, PayraSignatureGenerator, PayraSDKException
177
+
178
+ try:
179
+ # Convert amount to smallest unit (wei or token decimals)
180
+ amount_wei = PayraUtils.to_wei(3.34, 'polygon', 'usdt')
181
+
182
+ PAYMENT_DATA = {
183
+ "network": "polygon",
184
+ "tokenAddress": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F", # USDT on Polygon
185
+ "orderId": "ORDER-1753824905006-301-322",
186
+ "amountWei": amount_wei, # e.g. 3.34 USDT in smallest unit
187
+ "timestamp": 1753826059, # current Unix timestamp
188
+ "payerAddress": "0xe6c961D6ad9a27Ea8e5d99e40abaC365DE9Cc162"
189
+ }
190
+
191
+ # Initialize signer
192
+ payra_signer = PayraSignatureGenerator()
193
+
194
+ # Generate cryptographic signature
195
+ signature = payra_signer.generate_signature(
196
+ network=PAYMENT_DATA["network"],
197
+ token_address=PAYMENT_DATA["tokenAddress"],
198
+ order_id=PAYMENT_DATA["orderId"],
199
+ amount_wei=PAYMENT_DATA["amountWei"],
200
+ timestamp=PAYMENT_DATA["timestamp"],
201
+ payer_address=PAYMENT_DATA["payerAddress"]
202
+ )
203
+
204
+ print(f"Generated signature: {signature}")
205
+
206
+ except PayraSDKException as e:
207
+ print(f"Payra SDK error: {e}")
208
+ except Exception as e:
209
+ print(f"Unexpected error: {e}")
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
+
223
+ #### Behind the Scenes
224
+
225
+ 1. The backend converts the amount to the smallest blockchain unit (e.g. wei).
226
+ 3. A `PayraSignatureGenerator` instance is created using your private key from `.env`
227
+ 4. It generates an ECDSA signature that is fully verifiable on-chain by the Payra smart contract.
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.
229
+
230
+ ---
231
+
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.
287
+
288
+ Use this method when you only need a **quick boolean confirmation** of the payment status.
289
+
290
+ ```python
291
+ from payra_sdk import PayraOrderVerification, PayraSDKException
292
+
293
+ try:
294
+ ORDER_ID = "ORDER-1765138911744-126-5"
295
+
296
+ # Initialize verifier for a specific network
297
+ verifier = PayraOrderVerification("polygon")
298
+
299
+ print("\nChecking order status...")
300
+ result = verifier.is_order_paid(ORDER_ID)
301
+
302
+ print("Order ID:", ORDER_ID)
303
+ print("Result:", result)
304
+
305
+ if result["success"] and result["paid"]:
306
+ print("Order is PAID on-chain")
307
+ elif result["success"]:
308
+ print("Order is NOT paid yet")
309
+ else:
310
+ print("Error:", result["error"])
311
+
312
+ except PayraSDKException as e:
313
+ print(f"Payra SDK error: {e}")
314
+ except Exception as e:
315
+ print(f"Unexpected error: {e}")
316
+ ```
317
+
318
+ #### Behind the Scenes
319
+
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:
323
+ ```python
324
+ {
325
+ "success": True,
326
+ "paid": True,
327
+ "error": None
328
+ }
329
+ ```
330
+ 5. If `paid` is `True`, the order has been successfully processed and confirmed by the Payra smart contract.
331
+
332
+ ---
333
+
334
+ ### Using Utility Functions
335
+
336
+ The `PayraUtils` module provides convenient helpers for token conversion, precision handling, and fiat currency operations.
337
+
338
+ ```python
339
+ from payra_sdk import PayraUtils
340
+
341
+ # Convert USD/token amount to smallest unit (Wei or token decimals)
342
+ amount_wei = PayraUtils.to_wei(3.34, 'polygon', 'usdt')
343
+ print("Amount in Wei:", amount_wei) # 3340000
344
+
345
+ # Convert from Wei back to readable token amount
346
+ amount = PayraUtils.from_wei(3340000, 'polygon', 'usdt', precision=2)
347
+ print("Readable amount:", amount) # "3.34"
348
+
349
+ # Get token decimals for any supported network
350
+ print("USDT decimals on Polygon:", PayraUtils.get_decimals("polygon", "usdt"))
351
+ print("POL decimals on Polygon:", PayraUtils.get_decimals("polygon", "pol"))
352
+
353
+ # Convert fiat currency to USD using the built-in ExchangeRate API
354
+ usd_value = PayraUtils.convert_to_usd(100, "EUR")
355
+ print(f"100 EUR = {usd_value} USD")
356
+ ```
357
+
358
+ #### Behind the Scenes
359
+
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.
364
+
365
+ ## Testing
366
+ You can run the included `examples` to test signing and verification:
367
+
368
+ ```python
369
+ python3 example_signature.py
370
+ python3 example_order_verification.py
371
+ python3 example_utils.py
372
+ ```
373
+
374
+ Make sure your `.env` file contains correct values for the `network` being used.
375
+
376
+ ### Tips
377
+
378
+ - Always verify your `.env` configuration before running any signing or on-chain verification examples.
379
+ - The SDK examples are safe to run — they use **read-only RPC calls** (no real transactions are broadcast).
380
+ - You can modify `example_signature.py` to test custom token addresses or order parameters.
381
+
382
+ ## Projects
383
+
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)
387
+
388
+ ## Project
389
+
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
394
+
395
+ ## Social Media
396
+
397
+ - [Telegram Payra Group](https://t.me/+GhTyJJrd4SMyMDA0)
398
+ - [Telegram Announcements](https://t.me/payracash)
399
+ - [Twix (X)](https://x.com/PayraCash)
400
+ - [Dev.to](https://dev.to/payracash)
401
+
402
+ ## License
403
+
404
+ MIT © [Payra](https://payra.cash)