ninepay-sdk 1.0.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.
- ninepay_sdk-1.0.0/LICENSE +21 -0
- ninepay_sdk-1.0.0/MANIFEST.in +9 -0
- ninepay_sdk-1.0.0/PKG-INFO +170 -0
- ninepay_sdk-1.0.0/README.md +136 -0
- ninepay_sdk-1.0.0/examples/__init__.py +1 -0
- ninepay_sdk-1.0.0/examples/create_payment.py +67 -0
- ninepay_sdk-1.0.0/examples/django_full_example.py +350 -0
- ninepay_sdk-1.0.0/examples/django_webhook.py +108 -0
- ninepay_sdk-1.0.0/examples/flask_webhook.py +101 -0
- ninepay_sdk-1.0.0/examples/query_transaction.py +46 -0
- ninepay_sdk-1.0.0/ninepay/__init__.py +30 -0
- ninepay_sdk-1.0.0/ninepay/config.py +137 -0
- ninepay_sdk-1.0.0/ninepay/enums.py +75 -0
- ninepay_sdk-1.0.0/ninepay/exceptions.py +27 -0
- ninepay_sdk-1.0.0/ninepay/gateway.py +248 -0
- ninepay_sdk-1.0.0/ninepay/request.py +107 -0
- ninepay_sdk-1.0.0/ninepay/response.py +95 -0
- ninepay_sdk-1.0.0/ninepay/utils.py +59 -0
- ninepay_sdk-1.0.0/ninepay_sdk.egg-info/PKG-INFO +170 -0
- ninepay_sdk-1.0.0/ninepay_sdk.egg-info/SOURCES.txt +26 -0
- ninepay_sdk-1.0.0/ninepay_sdk.egg-info/dependency_links.txt +1 -0
- ninepay_sdk-1.0.0/ninepay_sdk.egg-info/requires.txt +1 -0
- ninepay_sdk-1.0.0/ninepay_sdk.egg-info/top_level.txt +3 -0
- ninepay_sdk-1.0.0/requirements.txt +2 -0
- ninepay_sdk-1.0.0/setup.cfg +4 -0
- ninepay_sdk-1.0.0/setup.py +33 -0
- ninepay_sdk-1.0.0/tests/__init__.py +1 -0
- ninepay_sdk-1.0.0/tests/test_ninepay.py +230 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 9Pay Labs
|
|
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.
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ninepay-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python SDK for 9PAY Payment Gateway
|
|
5
|
+
Home-page: https://github.com/9pay-labs/9pay-sdk-python
|
|
6
|
+
Author: 9Pay Labs
|
|
7
|
+
Author-email: support@9pay.vn
|
|
8
|
+
Keywords: payment gateway 9pay vietnam payment-processing
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Requires-Python: >=3.7
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: requests>=2.25.0
|
|
23
|
+
Dynamic: author
|
|
24
|
+
Dynamic: author-email
|
|
25
|
+
Dynamic: classifier
|
|
26
|
+
Dynamic: description
|
|
27
|
+
Dynamic: description-content-type
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: keywords
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
Dynamic: requires-dist
|
|
32
|
+
Dynamic: requires-python
|
|
33
|
+
Dynamic: summary
|
|
34
|
+
|
|
35
|
+
# 9PAY Payment Gateway Python SDK
|
|
36
|
+
|
|
37
|
+
Official Python SDK for integrating 9PAY Payment Gateway.
|
|
38
|
+
|
|
39
|
+
[English](#english) | [Tiếng Việt](#tiếng-việt)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## English
|
|
44
|
+
|
|
45
|
+
### 🚀 Quick Start (Recommended)
|
|
46
|
+
|
|
47
|
+
1. **Install SDK:**
|
|
48
|
+
```bash
|
|
49
|
+
pip install ninepay-sdk python-dotenv
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
2. **Configure Environment:**
|
|
53
|
+
Copy `.env.example` to `.env` and fill in your credentials.
|
|
54
|
+
```bash
|
|
55
|
+
cp .env.example .env
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```env
|
|
59
|
+
NINEPAY_MERCHANT_ID=your_merchant_id
|
|
60
|
+
NINEPAY_SECRET_KEY=your_secret_key
|
|
61
|
+
NINEPAY_CHECKSUM_KEY=your_checksum_key
|
|
62
|
+
NINEPAY_ENV=SANDBOX
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
3. **Usage:**
|
|
66
|
+
```python
|
|
67
|
+
from ninepay import NinePayConfig, NinePayGateway
|
|
68
|
+
|
|
69
|
+
# Load config automatically from .env
|
|
70
|
+
config = NinePayConfig.from_env()
|
|
71
|
+
gateway = NinePayGateway(config)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 📦 Features
|
|
75
|
+
- ✅ **Dynamic Config**: Managed via `.env` files (PHP/Laravel style)
|
|
76
|
+
- ✅ **Secure**: Signature generation and verification
|
|
77
|
+
- ✅ **Complete**: Payment creation, inquiry, and webhook handlers
|
|
78
|
+
- ✅ **Framework Friendly**: Ready for Django, Flask, FastAPI
|
|
79
|
+
|
|
80
|
+
### 🛠 Installation
|
|
81
|
+
```bash
|
|
82
|
+
pip install ninepay-sdk
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 💡 Example: Create Payment
|
|
86
|
+
```python
|
|
87
|
+
from ninepay import CreatePaymentRequest, PaymentMethod, Currency, Language
|
|
88
|
+
import time
|
|
89
|
+
|
|
90
|
+
request = CreatePaymentRequest(
|
|
91
|
+
invoice_no=f'INV_{int(time.time())}',
|
|
92
|
+
amount='50000',
|
|
93
|
+
description='Order #12345',
|
|
94
|
+
back_url='https://yoursite.com/cancel',
|
|
95
|
+
return_url='https://yoursite.com/success'
|
|
96
|
+
).with_method(PaymentMethod.ATM_CARD).with_lang(Language.EN)
|
|
97
|
+
|
|
98
|
+
response = gateway.create_payment(request)
|
|
99
|
+
if response.is_success():
|
|
100
|
+
print(f"Redirect URL: {response.get_data()['redirect_url']}")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Tiếng Việt
|
|
106
|
+
|
|
107
|
+
### 🚀 Bắt đầu nhanh (Khuyên dùng)
|
|
108
|
+
|
|
109
|
+
1. **Cài đặt:**
|
|
110
|
+
```bash
|
|
111
|
+
pip install ninepay-sdk python-dotenv
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
2. **Cấu hình môi trường:**
|
|
115
|
+
Copy `.env.example` thành `.env` và điền thông tin của bạn.
|
|
116
|
+
```bash
|
|
117
|
+
cp .env.example .env
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
3. **Sử dụng:**
|
|
121
|
+
```python
|
|
122
|
+
from ninepay import NinePayConfig, NinePayGateway
|
|
123
|
+
|
|
124
|
+
# Tự động load cấu hình từ file .env
|
|
125
|
+
config = NinePayConfig.from_env()
|
|
126
|
+
gateway = NinePayGateway(config)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### ✨ Tính năng chính
|
|
130
|
+
- ✅ **Cấu hình tập trung**: Quản lý qua file `.env` (giống Laravel/PHP)
|
|
131
|
+
- ✅ **Bảo mật**: Tự động tạo và xác thực chữ ký (checksum)
|
|
132
|
+
- ✅ **Đầy đủ**: Hỗ trợ tạo thanh toán, truy vấn đơn hàng và Webhook
|
|
133
|
+
- ✅ **Dễ tích hợp**: Tương thích tốt với Django, Flask, FastAPI
|
|
134
|
+
|
|
135
|
+
### 💡 Ví dụ: Tạo thanh toán
|
|
136
|
+
```python
|
|
137
|
+
from ninepay import CreatePaymentRequest, PaymentMethod, Language
|
|
138
|
+
import time
|
|
139
|
+
|
|
140
|
+
request = CreatePaymentRequest(
|
|
141
|
+
invoice_no=f'INV_{int(time.time())}',
|
|
142
|
+
amount='100000',
|
|
143
|
+
description='Thanh toán đơn hàng #123',
|
|
144
|
+
back_url='https://site.com/cancel',
|
|
145
|
+
return_url='https://site.com/success'
|
|
146
|
+
).with_method(PaymentMethod.ATM_CARD).with_lang(Language.VI)
|
|
147
|
+
|
|
148
|
+
response = gateway.create_payment(request)
|
|
149
|
+
if response.is_success():
|
|
150
|
+
print(f"URL Thanh toán: {response.get_data()['redirect_url']}")
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 🖥 Chạy Demo
|
|
154
|
+
Bạn có thể chạy script demo để kiểm tra nhanh:
|
|
155
|
+
```bash
|
|
156
|
+
python demo.py
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 🧪 Chạy Test
|
|
160
|
+
```bash
|
|
161
|
+
python -m unittest discover tests -v
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 📞 Hỗ trợ
|
|
165
|
+
- Email: support@9pay.vn
|
|
166
|
+
- Website: https://9pay.vn
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
Licensed under MIT.
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# 9PAY Payment Gateway Python SDK
|
|
2
|
+
|
|
3
|
+
Official Python SDK for integrating 9PAY Payment Gateway.
|
|
4
|
+
|
|
5
|
+
[English](#english) | [Tiếng Việt](#tiếng-việt)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## English
|
|
10
|
+
|
|
11
|
+
### 🚀 Quick Start (Recommended)
|
|
12
|
+
|
|
13
|
+
1. **Install SDK:**
|
|
14
|
+
```bash
|
|
15
|
+
pip install ninepay-sdk python-dotenv
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
2. **Configure Environment:**
|
|
19
|
+
Copy `.env.example` to `.env` and fill in your credentials.
|
|
20
|
+
```bash
|
|
21
|
+
cp .env.example .env
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```env
|
|
25
|
+
NINEPAY_MERCHANT_ID=your_merchant_id
|
|
26
|
+
NINEPAY_SECRET_KEY=your_secret_key
|
|
27
|
+
NINEPAY_CHECKSUM_KEY=your_checksum_key
|
|
28
|
+
NINEPAY_ENV=SANDBOX
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
3. **Usage:**
|
|
32
|
+
```python
|
|
33
|
+
from ninepay import NinePayConfig, NinePayGateway
|
|
34
|
+
|
|
35
|
+
# Load config automatically from .env
|
|
36
|
+
config = NinePayConfig.from_env()
|
|
37
|
+
gateway = NinePayGateway(config)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 📦 Features
|
|
41
|
+
- ✅ **Dynamic Config**: Managed via `.env` files (PHP/Laravel style)
|
|
42
|
+
- ✅ **Secure**: Signature generation and verification
|
|
43
|
+
- ✅ **Complete**: Payment creation, inquiry, and webhook handlers
|
|
44
|
+
- ✅ **Framework Friendly**: Ready for Django, Flask, FastAPI
|
|
45
|
+
|
|
46
|
+
### 🛠 Installation
|
|
47
|
+
```bash
|
|
48
|
+
pip install ninepay-sdk
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 💡 Example: Create Payment
|
|
52
|
+
```python
|
|
53
|
+
from ninepay import CreatePaymentRequest, PaymentMethod, Currency, Language
|
|
54
|
+
import time
|
|
55
|
+
|
|
56
|
+
request = CreatePaymentRequest(
|
|
57
|
+
invoice_no=f'INV_{int(time.time())}',
|
|
58
|
+
amount='50000',
|
|
59
|
+
description='Order #12345',
|
|
60
|
+
back_url='https://yoursite.com/cancel',
|
|
61
|
+
return_url='https://yoursite.com/success'
|
|
62
|
+
).with_method(PaymentMethod.ATM_CARD).with_lang(Language.EN)
|
|
63
|
+
|
|
64
|
+
response = gateway.create_payment(request)
|
|
65
|
+
if response.is_success():
|
|
66
|
+
print(f"Redirect URL: {response.get_data()['redirect_url']}")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Tiếng Việt
|
|
72
|
+
|
|
73
|
+
### 🚀 Bắt đầu nhanh (Khuyên dùng)
|
|
74
|
+
|
|
75
|
+
1. **Cài đặt:**
|
|
76
|
+
```bash
|
|
77
|
+
pip install ninepay-sdk python-dotenv
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
2. **Cấu hình môi trường:**
|
|
81
|
+
Copy `.env.example` thành `.env` và điền thông tin của bạn.
|
|
82
|
+
```bash
|
|
83
|
+
cp .env.example .env
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
3. **Sử dụng:**
|
|
87
|
+
```python
|
|
88
|
+
from ninepay import NinePayConfig, NinePayGateway
|
|
89
|
+
|
|
90
|
+
# Tự động load cấu hình từ file .env
|
|
91
|
+
config = NinePayConfig.from_env()
|
|
92
|
+
gateway = NinePayGateway(config)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### ✨ Tính năng chính
|
|
96
|
+
- ✅ **Cấu hình tập trung**: Quản lý qua file `.env` (giống Laravel/PHP)
|
|
97
|
+
- ✅ **Bảo mật**: Tự động tạo và xác thực chữ ký (checksum)
|
|
98
|
+
- ✅ **Đầy đủ**: Hỗ trợ tạo thanh toán, truy vấn đơn hàng và Webhook
|
|
99
|
+
- ✅ **Dễ tích hợp**: Tương thích tốt với Django, Flask, FastAPI
|
|
100
|
+
|
|
101
|
+
### 💡 Ví dụ: Tạo thanh toán
|
|
102
|
+
```python
|
|
103
|
+
from ninepay import CreatePaymentRequest, PaymentMethod, Language
|
|
104
|
+
import time
|
|
105
|
+
|
|
106
|
+
request = CreatePaymentRequest(
|
|
107
|
+
invoice_no=f'INV_{int(time.time())}',
|
|
108
|
+
amount='100000',
|
|
109
|
+
description='Thanh toán đơn hàng #123',
|
|
110
|
+
back_url='https://site.com/cancel',
|
|
111
|
+
return_url='https://site.com/success'
|
|
112
|
+
).with_method(PaymentMethod.ATM_CARD).with_lang(Language.VI)
|
|
113
|
+
|
|
114
|
+
response = gateway.create_payment(request)
|
|
115
|
+
if response.is_success():
|
|
116
|
+
print(f"URL Thanh toán: {response.get_data()['redirect_url']}")
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 🖥 Chạy Demo
|
|
120
|
+
Bạn có thể chạy script demo để kiểm tra nhanh:
|
|
121
|
+
```bash
|
|
122
|
+
python demo.py
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 🧪 Chạy Test
|
|
126
|
+
```bash
|
|
127
|
+
python -m unittest discover tests -v
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 📞 Hỗ trợ
|
|
131
|
+
- Email: support@9pay.vn
|
|
132
|
+
- Website: https://9pay.vn
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
Licensed under MIT.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Examples for 9Pay SDK
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Example: Basic payment creation
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from ninepay import (
|
|
6
|
+
NinePayConfig,
|
|
7
|
+
NinePayGateway,
|
|
8
|
+
CreatePaymentRequest,
|
|
9
|
+
PaymentMethod,
|
|
10
|
+
Currency,
|
|
11
|
+
Language
|
|
12
|
+
)
|
|
13
|
+
import time
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main():
|
|
17
|
+
# Initialize configuration from .env file
|
|
18
|
+
# Make sure you have a .env file with:
|
|
19
|
+
# NINEPAY_MERCHANT_ID=your_merchant_id
|
|
20
|
+
# NINEPAY_SECRET_KEY=your_secret_key
|
|
21
|
+
# NINEPAY_CHECKSUM_KEY=your_checksum_key
|
|
22
|
+
# NINEPAY_ENV=SANDBOX
|
|
23
|
+
config = NinePayConfig.from_env()
|
|
24
|
+
|
|
25
|
+
# Create gateway instance
|
|
26
|
+
gateway = NinePayGateway(config)
|
|
27
|
+
|
|
28
|
+
# Create payment request
|
|
29
|
+
invoice_no = f'INV_{int(time.time())}'
|
|
30
|
+
|
|
31
|
+
request = CreatePaymentRequest(
|
|
32
|
+
invoice_no=invoice_no,
|
|
33
|
+
amount='50000',
|
|
34
|
+
description='Payment for Order #123',
|
|
35
|
+
back_url='https://yoursite.com/payment/cancel',
|
|
36
|
+
return_url='https://yoursite.com/payment/success'
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# Add optional parameters
|
|
40
|
+
request.with_method(PaymentMethod.ATM_CARD) \
|
|
41
|
+
.with_client_ip('127.0.0.1') \
|
|
42
|
+
.with_currency(Currency.VND) \
|
|
43
|
+
.with_lang(Language.VI) \
|
|
44
|
+
.with_expires_time(1440)
|
|
45
|
+
|
|
46
|
+
# Send payment request
|
|
47
|
+
try:
|
|
48
|
+
response = gateway.create_payment(request)
|
|
49
|
+
|
|
50
|
+
if response.is_success():
|
|
51
|
+
data = response.get_data()
|
|
52
|
+
redirect_url = data.get('redirect_url')
|
|
53
|
+
print(f"✓ Payment created successfully!")
|
|
54
|
+
print(f" Invoice No: {invoice_no}")
|
|
55
|
+
print(f" Redirect URL: {redirect_url}")
|
|
56
|
+
print(f"\nPlease redirect user to: {redirect_url}")
|
|
57
|
+
else:
|
|
58
|
+
print(f"✗ Payment creation failed!")
|
|
59
|
+
print(f" Error: {response.get_message()}")
|
|
60
|
+
print(f" Error Code: {response.get_error_code()}")
|
|
61
|
+
|
|
62
|
+
except Exception as e:
|
|
63
|
+
print(f"✗ Exception occurred: {str(e)}")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if __name__ == '__main__':
|
|
67
|
+
main()
|