irgateway 0.1.0__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.
- irgateway-0.1.0/LICENSE +21 -0
- irgateway-0.1.0/PKG-INFO +191 -0
- irgateway-0.1.0/README.md +180 -0
- irgateway-0.1.0/irgateway/__init__.py +3 -0
- irgateway-0.1.0/irgateway/zarinpal/__init__.py +4 -0
- irgateway-0.1.0/irgateway/zarinpal/client.py +556 -0
- irgateway-0.1.0/irgateway/zarinpal/enums.py +19 -0
- irgateway-0.1.0/irgateway/zarinpal/errors.py +348 -0
- irgateway-0.1.0/irgateway/zarinpal/types.py +447 -0
- irgateway-0.1.0/pyproject.toml +14 -0
irgateway-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Javad Dalirani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
irgateway-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: irgateway
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Zarinpal Payment Gateway with sync and async support.
|
|
5
|
+
Author-email: Javad Dalirani <jdalirani82@gmail.com>
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Project-URL: Homepage, https://github.com/javad2nd/irgateway
|
|
10
|
+
|
|
11
|
+
# Zarinpal Python SDK
|
|
12
|
+
|
|
13
|
+
A modern, type-safe Python SDK for Zarinpal Payment Gateway with both synchronous and asynchronous support.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- ✅ Sync and async client support
|
|
18
|
+
- ✅ Type hints and full IDE autocomplete
|
|
19
|
+
- ✅ Comprehensive error handling
|
|
20
|
+
- ✅ Support for all Zarinpal API endpoints
|
|
21
|
+
- ✅ Sandbox environment for testing
|
|
22
|
+
- ✅ Custom StartPay endpoint configuration
|
|
23
|
+
- ✅ Wage splitting for shared settlements
|
|
24
|
+
- ✅ Fee calculation utilities
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
pip install irgateway
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Synchronous Usage
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
from irgateway.zarinpal import ZarinpalClient
|
|
38
|
+
from irgateway.zarinpal.enums import Environment, Currency
|
|
39
|
+
|
|
40
|
+
# Initialize client
|
|
41
|
+
client = ZarinpalClient(
|
|
42
|
+
merchant_id="YOUR-MERCHANT-ID",
|
|
43
|
+
environment=Environment.SANDBOX # Use PRODUCTION for live
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Create payment request
|
|
47
|
+
payment = client.request(
|
|
48
|
+
amount=10000,
|
|
49
|
+
callback_url="https://yoursite.com/callback",
|
|
50
|
+
description="خرید محصول"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
print(f"Payment URL: {payment.payment_url}")
|
|
54
|
+
|
|
55
|
+
# Verify payment after callback
|
|
56
|
+
verification = client.verify(
|
|
57
|
+
authority="A00000000000000000000000000123456789",
|
|
58
|
+
amount=10000
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
print(f"Reference ID: {verification.ref_id}")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Asynchronous Usage
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
from irgateway.zarinpal import ZarinpalClient
|
|
68
|
+
from irgateway.zarinpal.enums import Environment, Currency
|
|
69
|
+
|
|
70
|
+
async def process_payment():
|
|
71
|
+
async with AsyncZarinpalClient(
|
|
72
|
+
merchant_id="YOUR-MERCHANT-ID",
|
|
73
|
+
environment=Environment.SANDBOX
|
|
74
|
+
) as client:
|
|
75
|
+
payment = await client.request(
|
|
76
|
+
amount=10000,
|
|
77
|
+
callback_url="https://yoursite.com/callback",
|
|
78
|
+
description="خرید محصول"
|
|
79
|
+
)
|
|
80
|
+
return payment.payment_url
|
|
81
|
+
|
|
82
|
+
# In your async function
|
|
83
|
+
url = await process_payment()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## API Methods
|
|
87
|
+
|
|
88
|
+
| Method | Description |
|
|
89
|
+
|--------|-------------|
|
|
90
|
+
| `request()` | Create new payment request |
|
|
91
|
+
| `verify()` | Verify payment after user returns |
|
|
92
|
+
| `unverified()` | Get list of unverified transactions |
|
|
93
|
+
| `reverse()` | Request refund (requires permission) |
|
|
94
|
+
| `inquiry()` | Check payment status |
|
|
95
|
+
| `calculate_fee()` | Calculate gateway fees |
|
|
96
|
+
|
|
97
|
+
## Advanced Features
|
|
98
|
+
|
|
99
|
+
### Payment Metadata
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
from irgateway.types import PaymentMetadata
|
|
103
|
+
|
|
104
|
+
metadata = PaymentMetadata(
|
|
105
|
+
mobile="09123456789",
|
|
106
|
+
email="user@example.com"
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
payment = client.request(
|
|
110
|
+
amount=10000,
|
|
111
|
+
callback_url="https://yoursite.com/callback",
|
|
112
|
+
description="خرید محصول",
|
|
113
|
+
metadata=metadata
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Wage Splitting
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
from irgateway.zarinpal.types import Wage
|
|
121
|
+
|
|
122
|
+
wages = [
|
|
123
|
+
Wage(iban="IR123456789012345678901234", amount=5000),
|
|
124
|
+
Wage(iban="IR987654321098765432109876", amount=3000)
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
payment = client.request(
|
|
128
|
+
amount=10000,
|
|
129
|
+
callback_url="https://yoursite.com/callback",
|
|
130
|
+
description="خرید مشترک",
|
|
131
|
+
wages=wages
|
|
132
|
+
)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Configuration
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
from irgateway.zarinpal import ZarinpalClient, ZarinpalConfig
|
|
139
|
+
|
|
140
|
+
config = ZarinpalConfig(
|
|
141
|
+
timeout=30, # Request timeout in seconds
|
|
142
|
+
startpay_endpoint="https://custom-gateway.com/" # Optional custom gateway
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
client = ZarinpalClient(
|
|
146
|
+
merchant_id="YOUR-MERCHANT-ID",
|
|
147
|
+
config=config
|
|
148
|
+
)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Error Handling
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
from irgateway.zarinpal.errors import ZarinpalException, InvalidMerchantError
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
payment = client.request(...)
|
|
158
|
+
except InvalidMerchantError:
|
|
159
|
+
print("Merchant ID is invalid")
|
|
160
|
+
except ZarinpalException as e:
|
|
161
|
+
print(f"Error {e.code}: {e.message}")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Requirements
|
|
165
|
+
|
|
166
|
+
- Python 3.7+
|
|
167
|
+
- requests (for sync client)
|
|
168
|
+
- aiohttp (for async client)
|
|
169
|
+
|
|
170
|
+
## Development
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
# Clone repository
|
|
174
|
+
git clone https://github.com/javad2nd/irgateway.git
|
|
175
|
+
cd irgateway
|
|
176
|
+
|
|
177
|
+
# Install dependencies
|
|
178
|
+
pip install -e ".[dev]"
|
|
179
|
+
|
|
180
|
+
# Run tests
|
|
181
|
+
pytest
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
MIT License - see LICENSE file for details
|
|
187
|
+
|
|
188
|
+
## Contributing
|
|
189
|
+
|
|
190
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
191
|
+
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Zarinpal Python SDK
|
|
2
|
+
|
|
3
|
+
A modern, type-safe Python SDK for Zarinpal Payment Gateway with both synchronous and asynchronous support.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ Sync and async client support
|
|
8
|
+
- ✅ Type hints and full IDE autocomplete
|
|
9
|
+
- ✅ Comprehensive error handling
|
|
10
|
+
- ✅ Support for all Zarinpal API endpoints
|
|
11
|
+
- ✅ Sandbox environment for testing
|
|
12
|
+
- ✅ Custom StartPay endpoint configuration
|
|
13
|
+
- ✅ Wage splitting for shared settlements
|
|
14
|
+
- ✅ Fee calculation utilities
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
pip install irgateway
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### Synchronous Usage
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
from irgateway.zarinpal import ZarinpalClient
|
|
28
|
+
from irgateway.zarinpal.enums import Environment, Currency
|
|
29
|
+
|
|
30
|
+
# Initialize client
|
|
31
|
+
client = ZarinpalClient(
|
|
32
|
+
merchant_id="YOUR-MERCHANT-ID",
|
|
33
|
+
environment=Environment.SANDBOX # Use PRODUCTION for live
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# Create payment request
|
|
37
|
+
payment = client.request(
|
|
38
|
+
amount=10000,
|
|
39
|
+
callback_url="https://yoursite.com/callback",
|
|
40
|
+
description="خرید محصول"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
print(f"Payment URL: {payment.payment_url}")
|
|
44
|
+
|
|
45
|
+
# Verify payment after callback
|
|
46
|
+
verification = client.verify(
|
|
47
|
+
authority="A00000000000000000000000000123456789",
|
|
48
|
+
amount=10000
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
print(f"Reference ID: {verification.ref_id}")
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Asynchronous Usage
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
from irgateway.zarinpal import ZarinpalClient
|
|
58
|
+
from irgateway.zarinpal.enums import Environment, Currency
|
|
59
|
+
|
|
60
|
+
async def process_payment():
|
|
61
|
+
async with AsyncZarinpalClient(
|
|
62
|
+
merchant_id="YOUR-MERCHANT-ID",
|
|
63
|
+
environment=Environment.SANDBOX
|
|
64
|
+
) as client:
|
|
65
|
+
payment = await client.request(
|
|
66
|
+
amount=10000,
|
|
67
|
+
callback_url="https://yoursite.com/callback",
|
|
68
|
+
description="خرید محصول"
|
|
69
|
+
)
|
|
70
|
+
return payment.payment_url
|
|
71
|
+
|
|
72
|
+
# In your async function
|
|
73
|
+
url = await process_payment()
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## API Methods
|
|
77
|
+
|
|
78
|
+
| Method | Description |
|
|
79
|
+
|--------|-------------|
|
|
80
|
+
| `request()` | Create new payment request |
|
|
81
|
+
| `verify()` | Verify payment after user returns |
|
|
82
|
+
| `unverified()` | Get list of unverified transactions |
|
|
83
|
+
| `reverse()` | Request refund (requires permission) |
|
|
84
|
+
| `inquiry()` | Check payment status |
|
|
85
|
+
| `calculate_fee()` | Calculate gateway fees |
|
|
86
|
+
|
|
87
|
+
## Advanced Features
|
|
88
|
+
|
|
89
|
+
### Payment Metadata
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
from irgateway.types import PaymentMetadata
|
|
93
|
+
|
|
94
|
+
metadata = PaymentMetadata(
|
|
95
|
+
mobile="09123456789",
|
|
96
|
+
email="user@example.com"
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
payment = client.request(
|
|
100
|
+
amount=10000,
|
|
101
|
+
callback_url="https://yoursite.com/callback",
|
|
102
|
+
description="خرید محصول",
|
|
103
|
+
metadata=metadata
|
|
104
|
+
)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Wage Splitting
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
from irgateway.zarinpal.types import Wage
|
|
111
|
+
|
|
112
|
+
wages = [
|
|
113
|
+
Wage(iban="IR123456789012345678901234", amount=5000),
|
|
114
|
+
Wage(iban="IR987654321098765432109876", amount=3000)
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
payment = client.request(
|
|
118
|
+
amount=10000,
|
|
119
|
+
callback_url="https://yoursite.com/callback",
|
|
120
|
+
description="خرید مشترک",
|
|
121
|
+
wages=wages
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Configuration
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
from irgateway.zarinpal import ZarinpalClient, ZarinpalConfig
|
|
129
|
+
|
|
130
|
+
config = ZarinpalConfig(
|
|
131
|
+
timeout=30, # Request timeout in seconds
|
|
132
|
+
startpay_endpoint="https://custom-gateway.com/" # Optional custom gateway
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
client = ZarinpalClient(
|
|
136
|
+
merchant_id="YOUR-MERCHANT-ID",
|
|
137
|
+
config=config
|
|
138
|
+
)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Error Handling
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
from irgateway.zarinpal.errors import ZarinpalException, InvalidMerchantError
|
|
145
|
+
|
|
146
|
+
try:
|
|
147
|
+
payment = client.request(...)
|
|
148
|
+
except InvalidMerchantError:
|
|
149
|
+
print("Merchant ID is invalid")
|
|
150
|
+
except ZarinpalException as e:
|
|
151
|
+
print(f"Error {e.code}: {e.message}")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Requirements
|
|
155
|
+
|
|
156
|
+
- Python 3.7+
|
|
157
|
+
- requests (for sync client)
|
|
158
|
+
- aiohttp (for async client)
|
|
159
|
+
|
|
160
|
+
## Development
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
# Clone repository
|
|
164
|
+
git clone https://github.com/javad2nd/irgateway.git
|
|
165
|
+
cd irgateway
|
|
166
|
+
|
|
167
|
+
# Install dependencies
|
|
168
|
+
pip install -e ".[dev]"
|
|
169
|
+
|
|
170
|
+
# Run tests
|
|
171
|
+
pytest
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
MIT License - see LICENSE file for details
|
|
177
|
+
|
|
178
|
+
## Contributing
|
|
179
|
+
|
|
180
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|