rpay-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.
rpay_sdk-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RPAY (https://rpay.vn)
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,169 @@
1
+ Metadata-Version: 2.4
2
+ Name: rpay-sdk
3
+ Version: 1.0.0
4
+ Summary: Official RPAY Payment & Banking SDK for Python — VietQR, 15 Vietnamese Bank Gateways (POS/V1/V2/V3), Bank Invoices, 18-Network USDT/USDC Crypto Gateway, Multi-Domain & HMAC-SHA256 Webhooks.
5
+ Author-email: RPAY Team <support@rpay.vn>
6
+ License: MIT
7
+ Project-URL: Homepage, https://rpay.vn
8
+ Project-URL: Documentation, https://rpay.vn/docs
9
+ Project-URL: Repository, https://github.com/rpayvn/rpay-sdk-python
10
+ Keywords: rpay,rpay-sdk,vietqr,sepay,payment-gateway,vietnam-bank-api,vietcombank,mbbank,acb,usdt,usdc,trc20,bep20,webhook,hmac-sha256
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
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
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Office/Business :: Financial
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Dynamic: license-file
27
+
28
+ # rpay-sdk (Python) — Thư viện Tích hợp Thanh toán Tự động RPAY (Bank VietQR VNĐ & Crypto USDT/USDC)
29
+
30
+ Thư viện Python chính thức cho cổng thanh toán **RPAY (`https://api.rpay.vn` & hệ thống Web con / Multi-Domain)** dành cho **FastAPI, Flask, Django, Tornado & Cronjob Workers**.
31
+
32
+ - **Zero-Config (Tự động đọc `.env` / `os.environ`)**: Không cần viết code khởi tạo rườm rà.
33
+ - **Không phụ thuộc ngoài (Zero External Dependencies)**: Chỉ dùng thư viện chuẩn của Python (`urllib.request`, `hmac`, `hashlib`, `json`).
34
+ - **Hợp nhất Cả Bank (15 cổng VietQR VNĐ) & Crypto (USDT/USDC trên 18 mạng lưới)**: Dùng chung 4 hàm `rpay.pay(...)`, `rpay.check(...)`, `rpay.lsgd(...)`, `rpay.qr(...)`.
35
+ - **Hỗ trợ Đa Tên Miền (`Multi-Domain`)**: `rpay.for_domain("pay.shopa.vn")` hoặc truyền `domain="pay.shopb.com"` ngay trong từng hàm.
36
+
37
+ ---
38
+
39
+ ## 1. Cài đặt & Cấu hình `.env`
40
+
41
+ ```bash
42
+ pip install rpay-sdk
43
+ ```
44
+
45
+ Khai báo biến môi trường trong `.env` (hoặc `os.environ`):
46
+
47
+ ```env
48
+ RPAY_DOMAIN=https://api.rpay.vn
49
+ RPAY_BANK_TOKEN=rpay_vcb_live_123456_abcdef123456
50
+ RPAY_MERCHANT_ID=MRCH-0001
51
+ RPAY_USDT_API_KEY=ukey_live_xxxxxxxxxxxxxxxx
52
+ RPAY_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxx
53
+ ```
54
+
55
+ ---
56
+
57
+ ## 2. 4 Hàm Cốt lõi Dễ Dùng Nhất (`pay`, `check`, `lsgd`, `qr`)
58
+
59
+ ```python
60
+ import rpay_sdk as rpay
61
+
62
+ # 1. Tạo hóa đơn Ngân hàng (VietQR VNĐ)
63
+ bank_order = rpay.pay(
64
+ channel="bank",
65
+ amount=250000,
66
+ orderId="DH1001",
67
+ description="Nạp tiền tài khoản",
68
+ callbackUrl="https://webcuaban.com/api/webhooks/rpay",
69
+ )
70
+
71
+ # 2. Tạo hóa đơn Crypto (USDT / USDC trên 18 mạng lưới)
72
+ crypto_order = rpay.pay(
73
+ channel="usdt",
74
+ network="TRC20", # TRC20, BEP20, ERC20, SOLANA, TON, POLYGON, ARBITRUM, BASE...
75
+ token="USDT",
76
+ amount=50,
77
+ orderId="DH1002",
78
+ callbackUrl="https://webcuaban.com/api/webhooks/rpay",
79
+ )
80
+
81
+ print(bank_order["invoiceCode"], bank_order["paymentUrl"], bank_order["qrImageUrl"])
82
+
83
+ # 3. Kiểm tra & Gạch nợ tức thì (Tự phân biệt RPINV... của Bank và USINV.../USTX... của USDT)
84
+ checked = rpay.check(bank_order["invoiceCode"])
85
+ if checked["isPaid"]:
86
+ print("Khách đã thanh toán:", checked["paidAmount"], checked["currency"])
87
+
88
+ # 4. Tạo nhanh mã VietQR động
89
+ qr = rpay.qr(bank="MB", account="0123456789", amount=150000, memo="DH1001")
90
+ print(qr["qrDataUrl"], qr["qrImageUrl"])
91
+ ```
92
+
93
+ ---
94
+
95
+ ## 3. Lấy Lịch sử Giao dịch (LSGD) & Đối soát Chống Trùng (`rpay.lsgd` & `rpay.match_payment`)
96
+
97
+ ```python
98
+ import rpay_sdk as rpay
99
+
100
+ processed_ids = set()
101
+
102
+ # Lấy đồng thời cả LSGD Ngân hàng (V2) + LSGD USDT trong 1 lệnh:
103
+ history = rpay.lsgd(channel="all", bank="VCB", limit=50)
104
+
105
+ matches = rpay.match_payment(
106
+ history["transactions"],
107
+ order_code="DH1001",
108
+ expected_amount=250000,
109
+ processed_ids=processed_ids,
110
+ mutate_processed_ids=True, # Tự động thêm transactionID vào processed_ids
111
+ )
112
+
113
+ if matches:
114
+ tx = matches[0]
115
+ print(f"Đã khớp đơn qua {tx['channel']}: +{tx['amount']} {tx['currency']} (Mã GD: {tx['transactionID']})")
116
+ ```
117
+
118
+ ---
119
+
120
+ ## 4. Tích hợp Nhận Webhook `HMAC-SHA256` (FastAPI / Flask / Django)
121
+
122
+ ### Ví dụ với FastAPI:
123
+
124
+ ```python
125
+ from fastapi import FastAPI, HTTPException, Request
126
+ import rpay_sdk as rpay
127
+
128
+ app = FastAPI()
129
+
130
+ @app.post("/api/webhooks/rpay")
131
+ async def rpay_webhook(request: Request):
132
+ raw_body = await request.body()
133
+ event = rpay.verify_webhook(
134
+ raw_body=raw_body,
135
+ headers=dict(request.headers),
136
+ )
137
+ if not event["verified"]:
138
+ raise HTTPException(status_code=401, detail=event["reason"])
139
+
140
+ # Tự động chuẩn hóa chung cho cả Bank Invoice (VND) và Crypto Invoice (USDT/USDC):
141
+ print("Kênh:", event["channel"], "Đơn:", event["orderId"], "Thực nhận:", event["paidAmount"], event["currency"])
142
+ return {"success": True, "received": True}
143
+ ```
144
+
145
+ ---
146
+
147
+ ## 5. Dùng trên Nhiều Tên Miền (`Multi-Domain`)
148
+
149
+ ```python
150
+ import rpay_sdk as rpay
151
+
152
+ shop_a = rpay.for_domain("pay.shopa.vn", bank_token="rpay_vcb_live_shopA...")
153
+ shop_b = rpay.for_domain("pay.shopb.com", bank_token="rpay_mb_live_shopB...")
154
+
155
+ inv_a = shop_a.pay(channel="bank", amount=200000, orderId="A-01")
156
+ inv_b = shop_b.pay(channel="usdt", network="BEP20", amount=30, orderId="B-01")
157
+ ```
158
+
159
+ ---
160
+
161
+ ## 6. Xuất bản lên PyPI
162
+
163
+ ```bash
164
+ cd C:\Users\kotin\Desktop\rpayv2\plugin\python
165
+ python -m unittest discover -s tests
166
+ pip install build twine
167
+ python -m build
168
+ twine upload dist/*
169
+ ```
@@ -0,0 +1,142 @@
1
+ # rpay-sdk (Python) — Thư viện Tích hợp Thanh toán Tự động RPAY (Bank VietQR VNĐ & Crypto USDT/USDC)
2
+
3
+ Thư viện Python chính thức cho cổng thanh toán **RPAY (`https://api.rpay.vn` & hệ thống Web con / Multi-Domain)** dành cho **FastAPI, Flask, Django, Tornado & Cronjob Workers**.
4
+
5
+ - **Zero-Config (Tự động đọc `.env` / `os.environ`)**: Không cần viết code khởi tạo rườm rà.
6
+ - **Không phụ thuộc ngoài (Zero External Dependencies)**: Chỉ dùng thư viện chuẩn của Python (`urllib.request`, `hmac`, `hashlib`, `json`).
7
+ - **Hợp nhất Cả Bank (15 cổng VietQR VNĐ) & Crypto (USDT/USDC trên 18 mạng lưới)**: Dùng chung 4 hàm `rpay.pay(...)`, `rpay.check(...)`, `rpay.lsgd(...)`, `rpay.qr(...)`.
8
+ - **Hỗ trợ Đa Tên Miền (`Multi-Domain`)**: `rpay.for_domain("pay.shopa.vn")` hoặc truyền `domain="pay.shopb.com"` ngay trong từng hàm.
9
+
10
+ ---
11
+
12
+ ## 1. Cài đặt & Cấu hình `.env`
13
+
14
+ ```bash
15
+ pip install rpay-sdk
16
+ ```
17
+
18
+ Khai báo biến môi trường trong `.env` (hoặc `os.environ`):
19
+
20
+ ```env
21
+ RPAY_DOMAIN=https://api.rpay.vn
22
+ RPAY_BANK_TOKEN=rpay_vcb_live_123456_abcdef123456
23
+ RPAY_MERCHANT_ID=MRCH-0001
24
+ RPAY_USDT_API_KEY=ukey_live_xxxxxxxxxxxxxxxx
25
+ RPAY_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxx
26
+ ```
27
+
28
+ ---
29
+
30
+ ## 2. 4 Hàm Cốt lõi Dễ Dùng Nhất (`pay`, `check`, `lsgd`, `qr`)
31
+
32
+ ```python
33
+ import rpay_sdk as rpay
34
+
35
+ # 1. Tạo hóa đơn Ngân hàng (VietQR VNĐ)
36
+ bank_order = rpay.pay(
37
+ channel="bank",
38
+ amount=250000,
39
+ orderId="DH1001",
40
+ description="Nạp tiền tài khoản",
41
+ callbackUrl="https://webcuaban.com/api/webhooks/rpay",
42
+ )
43
+
44
+ # 2. Tạo hóa đơn Crypto (USDT / USDC trên 18 mạng lưới)
45
+ crypto_order = rpay.pay(
46
+ channel="usdt",
47
+ network="TRC20", # TRC20, BEP20, ERC20, SOLANA, TON, POLYGON, ARBITRUM, BASE...
48
+ token="USDT",
49
+ amount=50,
50
+ orderId="DH1002",
51
+ callbackUrl="https://webcuaban.com/api/webhooks/rpay",
52
+ )
53
+
54
+ print(bank_order["invoiceCode"], bank_order["paymentUrl"], bank_order["qrImageUrl"])
55
+
56
+ # 3. Kiểm tra & Gạch nợ tức thì (Tự phân biệt RPINV... của Bank và USINV.../USTX... của USDT)
57
+ checked = rpay.check(bank_order["invoiceCode"])
58
+ if checked["isPaid"]:
59
+ print("Khách đã thanh toán:", checked["paidAmount"], checked["currency"])
60
+
61
+ # 4. Tạo nhanh mã VietQR động
62
+ qr = rpay.qr(bank="MB", account="0123456789", amount=150000, memo="DH1001")
63
+ print(qr["qrDataUrl"], qr["qrImageUrl"])
64
+ ```
65
+
66
+ ---
67
+
68
+ ## 3. Lấy Lịch sử Giao dịch (LSGD) & Đối soát Chống Trùng (`rpay.lsgd` & `rpay.match_payment`)
69
+
70
+ ```python
71
+ import rpay_sdk as rpay
72
+
73
+ processed_ids = set()
74
+
75
+ # Lấy đồng thời cả LSGD Ngân hàng (V2) + LSGD USDT trong 1 lệnh:
76
+ history = rpay.lsgd(channel="all", bank="VCB", limit=50)
77
+
78
+ matches = rpay.match_payment(
79
+ history["transactions"],
80
+ order_code="DH1001",
81
+ expected_amount=250000,
82
+ processed_ids=processed_ids,
83
+ mutate_processed_ids=True, # Tự động thêm transactionID vào processed_ids
84
+ )
85
+
86
+ if matches:
87
+ tx = matches[0]
88
+ print(f"Đã khớp đơn qua {tx['channel']}: +{tx['amount']} {tx['currency']} (Mã GD: {tx['transactionID']})")
89
+ ```
90
+
91
+ ---
92
+
93
+ ## 4. Tích hợp Nhận Webhook `HMAC-SHA256` (FastAPI / Flask / Django)
94
+
95
+ ### Ví dụ với FastAPI:
96
+
97
+ ```python
98
+ from fastapi import FastAPI, HTTPException, Request
99
+ import rpay_sdk as rpay
100
+
101
+ app = FastAPI()
102
+
103
+ @app.post("/api/webhooks/rpay")
104
+ async def rpay_webhook(request: Request):
105
+ raw_body = await request.body()
106
+ event = rpay.verify_webhook(
107
+ raw_body=raw_body,
108
+ headers=dict(request.headers),
109
+ )
110
+ if not event["verified"]:
111
+ raise HTTPException(status_code=401, detail=event["reason"])
112
+
113
+ # Tự động chuẩn hóa chung cho cả Bank Invoice (VND) và Crypto Invoice (USDT/USDC):
114
+ print("Kênh:", event["channel"], "Đơn:", event["orderId"], "Thực nhận:", event["paidAmount"], event["currency"])
115
+ return {"success": True, "received": True}
116
+ ```
117
+
118
+ ---
119
+
120
+ ## 5. Dùng trên Nhiều Tên Miền (`Multi-Domain`)
121
+
122
+ ```python
123
+ import rpay_sdk as rpay
124
+
125
+ shop_a = rpay.for_domain("pay.shopa.vn", bank_token="rpay_vcb_live_shopA...")
126
+ shop_b = rpay.for_domain("pay.shopb.com", bank_token="rpay_mb_live_shopB...")
127
+
128
+ inv_a = shop_a.pay(channel="bank", amount=200000, orderId="A-01")
129
+ inv_b = shop_b.pay(channel="usdt", network="BEP20", amount=30, orderId="B-01")
130
+ ```
131
+
132
+ ---
133
+
134
+ ## 6. Xuất bản lên PyPI
135
+
136
+ ```bash
137
+ cd C:\Users\kotin\Desktop\rpayv2\plugin\python
138
+ python -m unittest discover -s tests
139
+ pip install build twine
140
+ python -m build
141
+ twine upload dist/*
142
+ ```
@@ -0,0 +1,55 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "rpay-sdk"
7
+ version = "1.0.0"
8
+ description = "Official RPAY Payment & Banking SDK for Python — VietQR, 15 Vietnamese Bank Gateways (POS/V1/V2/V3), Bank Invoices, 18-Network USDT/USDC Crypto Gateway, Multi-Domain & HMAC-SHA256 Webhooks."
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.8"
12
+ authors = [
13
+ { name = "RPAY Team", email = "support@rpay.vn" }
14
+ ]
15
+ keywords = [
16
+ "rpay",
17
+ "rpay-sdk",
18
+ "vietqr",
19
+ "sepay",
20
+ "payment-gateway",
21
+ "vietnam-bank-api",
22
+ "vietcombank",
23
+ "mbbank",
24
+ "acb",
25
+ "usdt",
26
+ "usdc",
27
+ "trc20",
28
+ "bep20",
29
+ "webhook",
30
+ "hmac-sha256"
31
+ ]
32
+ classifiers = [
33
+ "Development Status :: 5 - Production/Stable",
34
+ "Intended Audience :: Developers",
35
+ "License :: OSI Approved :: MIT License",
36
+ "Programming Language :: Python :: 3",
37
+ "Programming Language :: Python :: 3.8",
38
+ "Programming Language :: Python :: 3.9",
39
+ "Programming Language :: Python :: 3.10",
40
+ "Programming Language :: Python :: 3.11",
41
+ "Programming Language :: Python :: 3.12",
42
+ "Programming Language :: Python :: 3.13",
43
+ "Topic :: Office/Business :: Financial",
44
+ "Topic :: Software Development :: Libraries :: Python Modules"
45
+ ]
46
+ dependencies = []
47
+
48
+ [project.urls]
49
+ Homepage = "https://rpay.vn"
50
+ Documentation = "https://rpay.vn/docs"
51
+ Repository = "https://github.com/rpayvn/rpay-sdk-python"
52
+
53
+ [tool.setuptools.packages.find]
54
+ where = ["."]
55
+ include = ["rpay_sdk*"]
@@ -0,0 +1,77 @@
1
+ from __future__ import annotations
2
+ from .client import RPayClient, RPayError, create_client, rpay
3
+ from .constants import (
4
+ RPAY_BANKS,
5
+ RPAY_DEFAULT_BASE_URL,
6
+ RPAY_DEFAULT_TIMEOUT_SEC,
7
+ RPAY_USDT_NETWORKS,
8
+ resolve_bank_spec,
9
+ resolve_usdt_network_spec,
10
+ )
11
+ from .unified import (
12
+ detect_payment_channel,
13
+ match_unified_transactions,
14
+ normalize_unified_invoice,
15
+ normalize_unified_transaction,
16
+ )
17
+ from .webhooks import (
18
+ build_canonical_payload_string,
19
+ hmac_sha256_hex,
20
+ safe_compare_signature,
21
+ sign_canonical_payload,
22
+ sign_raw_body,
23
+ verify_webhook,
24
+ )
25
+
26
+ # Module-level shorthands so `import rpay_sdk as rpay; rpay.pay(...)` works seamlessly
27
+ init = rpay.init
28
+ configure = rpay.configure
29
+ for_domain = rpay.for_domain
30
+ pay = rpay.pay
31
+ create_invoice = rpay.create_invoice
32
+ check = rpay.check
33
+ check_invoice = rpay.check_invoice
34
+ status = rpay.status
35
+ get_invoice = rpay.get_invoice
36
+ lsgd = rpay.lsgd
37
+ get_history = rpay.get_history
38
+ qr = rpay.qr
39
+ match_payment = rpay.match_payment
40
+ route = rpay.route
41
+
42
+ __all__ = [
43
+ "rpay",
44
+ "RPayClient",
45
+ "RPayError",
46
+ "create_client",
47
+ "init",
48
+ "configure",
49
+ "for_domain",
50
+ "pay",
51
+ "create_invoice",
52
+ "check",
53
+ "check_invoice",
54
+ "status",
55
+ "get_invoice",
56
+ "lsgd",
57
+ "get_history",
58
+ "qr",
59
+ "match_payment",
60
+ "route",
61
+ "verify_webhook",
62
+ "sign_canonical_payload",
63
+ "sign_raw_body",
64
+ "hmac_sha256_hex",
65
+ "safe_compare_signature",
66
+ "build_canonical_payload_string",
67
+ "RPAY_BANKS",
68
+ "RPAY_USDT_NETWORKS",
69
+ "RPAY_DEFAULT_BASE_URL",
70
+ "RPAY_DEFAULT_TIMEOUT_SEC",
71
+ "resolve_bank_spec",
72
+ "resolve_usdt_network_spec",
73
+ "detect_payment_channel",
74
+ "normalize_unified_invoice",
75
+ "normalize_unified_transaction",
76
+ "match_unified_transactions",
77
+ ]