payra-sdk 1.2.4__tar.gz → 1.2.6__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.
@@ -0,0 +1,20 @@
1
+ PAYRA_EXCHANGE_RATE_API_KEY=
2
+ PAYRA_EXCHANGE_RATE_CACHE_TIME=720 # in minutes
3
+
4
+ PAYRA_POLYGON_OCP_GATEWAY_CONTRACT_ADDRESS=0xc56c55D9cF0FF05c85A2DF5BFB9a65b34804063b
5
+ PAYRA_POLYGON_SIGNATURE_KEY=
6
+ PAYRA_POLYGON_MERCHANT_ID=
7
+ PAYRA_POLYGON_RPC_URL_1=https://polygon-rpc.com
8
+ PAYRA_POLYGON_RPC_URL_2=
9
+
10
+ PAYRA_ETHEREUM_OCP_GATEWAY_CONTRACT_ADDRESS=
11
+ PAYRA_ETHEREUM_SIGNATURE_KEY=
12
+ PAYRA_ETHEREUM_MERCHANT_ID=
13
+ PAYRA_ETHEREUM_RPC_URL_1=
14
+ PAYRA_ETHEREUM_RPC_URL_2=
15
+
16
+ PAYRA_LINEA_OCP_GATEWAY_CONTRACT_ADDRESS=
17
+ PAYRA_LINEA_SIGNATURE_KEY=
18
+ PAYRA_LINEA_MERCHANT_ID=
19
+ PAYRA_LINEA_RPC_URL_1=
20
+ PAYRA_LINEA_RPC_URL_2=
File without changes
File without changes
@@ -0,0 +1,410 @@
1
+ Metadata-Version: 2.4
2
+ Name: payra_sdk
3
+ Version: 1.2.6
4
+ Summary: Python SDK for Payra payment signature generation (backend)
5
+ Author: Your Name
6
+ Author-email: Wraith <support@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
+ # Payra Python SDK
26
+
27
+ Official **Python SDK** for integrating **Payra's on-chain payment system** into your backend applications.
28
+
29
+ This SDK provides:
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 status of orders** to confirm completed payments.
32
+
33
+
34
+ ## How It Works
35
+
36
+ The typical flow for signing and verifying a Payra transaction:
37
+ 1. The **frontend** prepares all required payment parameters:
38
+ - **Network** – blockchain name (e.g. Polygon, Linea)
39
+ - **Token address** – ERC-20 token contract address
40
+ - **Order ID** – unique order identifier
41
+ - **Amount WEI** – already converted to the smallest unit (e.g. wei, 10⁶)
42
+ - **Timestamp** – Unix timestamp of the order
43
+ - **Payer wallet address** – the wallet address from which the user will make the on-chain payment
44
+ 2. The frontend sends these parameters to your **backend**.
45
+ 3. The **backend** uses this SDK to generate a cryptographic **ECDSA signature** with its signature key (performed **offline**).
46
+ 4. The backend returns the generated signature to the frontend.
47
+ 5. The **frontend** calls the Payra smart contract (`payOrder`) with all parameters **plus** the signature.
48
+
49
+ This process ensures full compatibility between your backend and Payra’s on-chain verification logic.
50
+
51
+
52
+ ## Features
53
+
54
+ - Generates **Ethereum ECDSA signatures** using the `secp256k1` curve.
55
+ - Fully compatible with **Payra's Solidity smart contracts** (`ERC-1155` payment verification).
56
+ - Supports `.env` and `config/payra.php` configuration for multiple blockchain networks.
57
+ - Laravel IoC container integration (easy dependency injection)
58
+ - Verifies **order payment status directly on-chain** via RPC or blockchain explorer API.
59
+ - Provides **secure backend integration** for signing and verifying transactions.
60
+ - Includes optional utility helpers for:
61
+ - **Currency conversion** (via [ExchangeRate API](https://www.exchangerate-api.com/))
62
+ - **USD ⇄ WEI** conversion for token precision handling.
63
+
64
+
65
+ ## Setup
66
+
67
+ Before installing this package, make sure you have an active **Payra** account:
68
+
69
+ [https://payra.cash/products/on-chain-payments/registration](https://payra.cash/products/on-chain-payments/registration#registration-form)
70
+
71
+ Before installing this package, make sure you have a **MerchantID**
72
+
73
+ - Your **Merchant ID** (unique for each blockchain network)
74
+ - Your **Signature Key** (used to sign Payra transactions securely)
75
+
76
+ Additionally:
77
+ To obtain your **RPC URLs** which are required for reading on-chain order statuses directly from the blockchain, you can use the public free endpoints provided with this package or create an account on one of the following services for better performance and reliability:
78
+
79
+ - **QuickNode** – Extremely fast and excellent for Polygon/Mainnet. ([quicknode.com](https://quicknode.com/))
80
+
81
+ - **Alchemy** – Offers a great developer dashboard and high reliability. ([alchemy.com](https://alchemy.com/))
82
+
83
+ - **DRPC** – Decentralized RPC with a generous free tier and a strict no-log policy. ([drpc.org](https://drpc.org))
84
+
85
+ - **Infura** – The industry standard; very stable, especially for Ethereum. ([infura.io](https://infura.io))
86
+
87
+ Optional (recommended):
88
+ - 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
+
90
+
91
+ ## Installation
92
+
93
+ ### From PyPI
94
+
95
+ Install the latest stable version from [PyPI](https://pypi.org/project/payra-sdk/):
96
+
97
+ ```bash
98
+ pip install payra-sdk
99
+ ```
100
+
101
+ ### From Source (for development)
102
+ Clone and install locally (editable mode for development):
103
+
104
+ ```bash
105
+ git clone https://github.com/payracash/payra-sdk-python.git
106
+ cd payra-sdk-python
107
+ python3 -m venv venv
108
+ source venv/bin/activate # Windows: venv\Scripts\activate
109
+ pip install -e .
110
+ ```
111
+
112
+ ### Dependencies
113
+
114
+ This SDK requires:
115
+ - **Python 3.8+**
116
+ - **web3.py**
117
+ - **ecdsa**
118
+ - **python-dotenv**
119
+ - _(optional)_ `requests` and `exchange-rate-api` for fiat conversion utilities.
120
+
121
+
122
+ ## Environment Configuration
123
+
124
+ Create a `.env` file in your project root (you can copy from example):
125
+
126
+ ```bash
127
+ cp .env.example .env
128
+ ```
129
+
130
+ This file stores your **private configuration** and connection settings for all supported networks. Never commit `.env` to version control.
131
+
132
+
133
+ ### Required Variables
134
+
135
+ #### Exchange Rate (optional)
136
+
137
+ Used for automatic fiat → USD conversions via the built-in Payra utilities.
138
+
139
+ ```bash
140
+ # Optional only needed if you want to use the built-in currency conversion helper
141
+ PAYRA_EXCHANGE_RATE_API_KEY= # Your ExchangeRate API key (from exchangerate-api.com)
142
+ PAYRA_EXCHANGE_RATE_CACHE_TIME=720 # Cache duration in minutes (default: 720 = 12h)
143
+
144
+ PAYRA_POLYGON_OCP_GATEWAY_CONTRACT_ADDRESS=0xc56c55D9cF0FF05c85A2DF5BFB9a65b34804063b
145
+ PAYRA_POLYGON_SIGNATURE_KEY=
146
+ PAYRA_POLYGON_MERCHANT_ID=
147
+ PAYRA_POLYGON_RPC_URL_1=https://polygon-rpc.com
148
+ PAYRA_POLYGON_RPC_URL_2=
149
+
150
+ PAYRA_ETHEREUM_OCP_GATEWAY_CONTRACT_ADDRESS=
151
+ PAYRA_ETHEREUM_SIGNATURE_KEY=
152
+ PAYRA_ETHEREUM_MERCHANT_ID=
153
+ PAYRA_ETHEREUM_RPC_URL_1=
154
+ PAYRA_ETHEREUM_RPC_URL_2=
155
+
156
+ PAYRA_LINEA_OCP_GATEWAY_CONTRACT_ADDRESS=
157
+ PAYRA_LINEA_SIGNATURE_KEY=
158
+ PAYRA_LINEA_MERCHANT_ID=
159
+ PAYRA_LINEA_RPC_URL_1=
160
+ PAYRA_LINEA_RPC_URL_2=
161
+ ```
162
+
163
+ #### Important Notes
164
+
165
+ - The cache automatically refreshes when it expires.
166
+ - 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)
170
+ - Each network (Polygon, Ethereum, Linea) has its own **merchant ID**, **signature key**, and **RPC URLs**.
171
+ - The SDK automatically detects which chain configuration to use based on the selected network.
172
+ - You can use multiple RPC URLs for redundancy (the SDK will automatically fall back if one fails).
173
+ - Contract addresses correspond to the deployed Payra Core Forward contracts per network.
174
+
175
+
176
+ ## Usage Example
177
+
178
+ ### Generating and verifying a Payra signature in your backend
179
+
180
+ ```python
181
+ from payra_sdk import PayraUtils, PayraSignatureGenerator, PayraSDKException
182
+
183
+ try:
184
+ # Convert amount to smallest unit (wei or token decimals
185
+ amount_wei = PayraUtils.to_wei(3.34, 'polygon', 'usdt')
186
+
187
+ PAYMENT_DATA = {
188
+ "network": "polygon",
189
+ "tokenAddress": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F", # USDT on Polygon
190
+ "orderId": "ORDER-1753824905006-301-322",
191
+ "amountWei": amount_wei, # e.g. 3.34 USDT in smallest unit
192
+ "timestamp": 1753826059, # current Unix timestamp
193
+ "payerAddress": "0xe6c961D6ad9a27Ea8e5d99e40abaC365DE9Cc162"
194
+ }
195
+
196
+ # Initialize signer
197
+ payra_signer = PayraSignatureGenerator()
198
+
199
+ # Generate cryptographic signature
200
+ signature = payra_signer.generate_signature(
201
+ network=PAYMENT_DATA["network"],
202
+ token_address=PAYMENT_DATA["tokenAddress"],
203
+ order_id=PAYMENT_DATA["orderId"],
204
+ amount_wei=PAYMENT_DATA["amountWei"],
205
+ timestamp=PAYMENT_DATA["timestamp"],
206
+ payer_address=PAYMENT_DATA["payerAddress"]
207
+ )
208
+
209
+ print(f"Generated signature: {signature}")
210
+ except PayraSDKException as e:
211
+ print(f"Payra SDK error: {e}")
212
+ except Exception as e:
213
+ print(f"Unexpected error: {e}")
214
+ ```
215
+
216
+ #### Input Parameters
217
+
218
+ | Field | Type | Description |
219
+ |--------------|----------|----------------------------------------------|
220
+ | **`network`** | `string` | Selected network name |
221
+ | **`tokenAddress`** | `string` | ERC20 token contract address |
222
+ | **`orderId`** | `string` | Unique order reference (e.g. ORDER-123) |
223
+ | **`amountWei`** | `string` or `integer` | Token amount in smallest unit (e.g. wei) |
224
+ | **`timestamp`** | `number` | Unix timestamp of signature creation |
225
+ | **`payerAddress`** | `string` | Payer Wallet Address
226
+
227
+ #### Behind the Scenes
228
+
229
+ 1. The backend converts the amount to the smallest blockchain unit (e.g. wei).
230
+ 2. A `PayraSignatureGenerator` instance is created using your signature key from `.env`
231
+ 3. It generates an ECDSA signature that is fully verifiable on-chain by the Payra smart contract.
232
+ 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
+
234
+ ---
235
+
236
+ ### Get Order Status
237
+
238
+ 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
+ - whether the order has been paid,
240
+ - the payment token address,
241
+ - the paid amount,
242
+ - the fee amount,
243
+ - and the payment timestamp.
244
+
245
+ Use this method when you need **detailed information** about the payment or want to display full transaction data.
246
+
247
+ ```python
248
+ from payra_sdk import PayraOrderVerification, PayraSDKException
249
+
250
+ try:
251
+ ORDER_ID = "ord-258"
252
+ # Initialize verifier for a specific network
253
+ verifier = PayraOrderVerification("polygon")
254
+
255
+ print("\nGet order status...")
256
+ result = verifier.get_order_status(ORDER_ID)
257
+
258
+ print("Order ID:", ORDER_ID)
259
+ print("Result:", result)
260
+
261
+ except PayraSDKException as e:
262
+ print(f"Payra SDK error: {e}")
263
+ except Exception as e:
264
+ print(f"Unexpected error: {e}")
265
+ ```
266
+
267
+ #### Behind the Scenes
268
+
269
+ 1. The backend initializes a `PayraOrderVerification` object for the desired blockchain network.
270
+ 2. It calls `get_order_status(order_id)` to check if the order transaction exists and is confirmed on-chain.
271
+ 3. The function returns a dictionary with:
272
+
273
+ ```python
274
+ {
275
+ "success": True,
276
+ "paid": True,
277
+ "error": None.
278
+ "toke": '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
279
+ "amount": 400000,
280
+ "fee": 3600,
281
+ "timestamp": 1765138941
282
+ }
283
+ ```
284
+
285
+ ---
286
+
287
+ ### Check Order Paid Status
288
+
289
+ 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.
290
+
291
+ Use this method when you only need a **quick boolean confirmation** of the payment status.
292
+
293
+ ```python
294
+ from payra_sdk import PayraOrderVerification, PayraSDKException
295
+
296
+ try:
297
+ ORDER_ID = "ord-258"
298
+
299
+ # Initialize verifier for a specific network
300
+ verifier = PayraOrderVerification("polygon")
301
+
302
+ print("\nChecking order status...")
303
+ result = verifier.is_order_paid(ORDER_ID)
304
+
305
+ print("Order ID:", ORDER_ID)
306
+ print("Result:", result)
307
+
308
+ if result["success"] and result["paid"]:
309
+ print("Order is PAID on-chain")
310
+ elif result["success"]:
311
+ print("Order is NOT paid yet")
312
+ else:
313
+ print("Error:", result["error"])
314
+
315
+ except PayraSDKException as e:
316
+ print(f"Payra SDK error: {e}")
317
+ except Exception as e:
318
+ print(f"Unexpected error: {e}")
319
+ ```
320
+
321
+ #### Behind the Scenes
322
+
323
+ 1. The backend initializes a `PayraOrderVerification` object for the desired blockchain network.
324
+ 2. It calls `is_order_paid(order_id)` to check if the order transaction exists and is confirmed on-chain.
325
+ 3. The function returns a dictionary with:
326
+ ```python
327
+ {
328
+ "success": True,
329
+ "paid": True,
330
+ "error": None
331
+ }
332
+ ```
333
+ 4. If `paid` is `True`, the order has been successfully processed and confirmed by the Payra smart contract.
334
+
335
+ ---
336
+
337
+ ### Using Utility Functions
338
+
339
+ The `PayraUtils` module provides convenient helpers for token conversion, precision handling, and fiat currency operations.
340
+
341
+ ```python
342
+ from payra_sdk import PayraUtils
343
+
344
+ # Convert USD/token amount to smallest unit (Wei or token decimals)
345
+ amount_wei = PayraUtils.to_wei(3.34, 'polygon', 'usdt')
346
+ print("Amount in Wei:", amount_wei) # 3340000
347
+
348
+ # Convert from Wei back to readable token amount
349
+ amount = PayraUtils.from_wei(3340000, 'polygon', 'usdt', precision=2)
350
+ print("Readable amount:", amount) # "3.34"
351
+
352
+ # Get token decimals for any supported network
353
+ print("USDT decimals on Polygon:", PayraUtils.get_decimals("polygon", "usdt"))
354
+ print("POL decimals on Polygon:", PayraUtils.get_decimals("polygon", "pol"))
355
+
356
+ # Convert fiat currency to USD using the built-in ExchangeRate API
357
+ usd_value = PayraUtils.convert_to_usd(100, "EUR")
358
+ print(f"100 EUR = {usd_value} USD")
359
+ ```
360
+
361
+ #### Behind the Scenes
362
+
363
+ - `to_wei(amount, network, token)` – Converts a human-readable token amount into the smallest unit (used on-chain).
364
+ - `from_wei(amount, network, token, precision)` – Converts back from smallest unit to a formatted amount.
365
+ - `get_decimals(network, token)` – Returns the number of decimals for the given token on that network.
366
+ - `convert_to_usd(amount, currency)` – Converts fiat amounts (e.g. EUR, GBP) to USD using your ExchangeRate API key.
367
+
368
+
369
+ ## Testing
370
+
371
+ You can run the included `examples` to test signing and verification:
372
+
373
+ ```python
374
+ python3 example_signature.py
375
+ python3 example_order_verification.py
376
+ python3 example_utils.py
377
+ ```
378
+
379
+ Make sure your `.env` file contains correct values for the `network` being used.
380
+
381
+ ### Tips
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.
386
+
387
+
388
+ ## Projects
389
+
390
+ - [GitHub/Home](https://github.com/payracash)
391
+ - [GitHub/Source](https://github.com/payracash/payra-sdk-python)
392
+ - [GitHub/Issues](https://github.com/payracash/payra-sdk-python/issues)
393
+
394
+ ## Project
395
+
396
+ - [https://payra.cash](https://payra.cash)
397
+ - [https://payra.tech](https://payra.tech)
398
+ - [https://payra.xyz](https://payra.xyz)
399
+ - [https://payra.eth](https://payra.eth.limo) - suporrted by Brave and Opera Browser or .limo
400
+
401
+
402
+ ## Social Media
403
+
404
+ - [Telegram Payra Group](https://t.me/+GhTyJJrd4SMyMDA0)
405
+ - [Telegram Announcements](https://t.me/payracash)
406
+ - [Twix (X)](https://x.com/PayraCash)
407
+ - [Dev.to](https://dev.to/payracash)
408
+
409
+ ## License
410
+ MIT © [Payra](https://payra.cash)