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