@imbatcat/vietnam-qr-pay 1.5.1

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.
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) xuannghia <xuannghia.dev@gmail.com> (https://xuannghia.dev)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,250 @@
1
+ # Vietnam QR Pay
2
+
3
+ Thư viện hỗ trợ encode/decode mã QR của VietQR (QR Ngân hàng, QR Đa năng Momo/ZaloPay) & VNPayQR
4
+
5
+ [![npm](https://img.shields.io/npm/v/vietnam-qr-pay.svg)](https://www.npmjs.com/package/vietnam-qr-pay)
6
+ [![download](https://img.shields.io/npm/dt/vietnam-qr-pay.svg)](https://www.npmjs.com/package/vietnam-qr-pay)
7
+ [![bundlephobia](https://img.shields.io/bundlephobia/minzip/vietnam-qr-pay.svg)](https://bundlephobia.com/package/vietnam-qr-pay)
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install vietnam-qr-pay
13
+ ```
14
+
15
+
16
+ ## Encode - Tạo mã QR
17
+
18
+ ### VietQR Tĩnh
19
+ ```javascript
20
+
21
+ import { QRPay, BanksObject } from 'vietnam-qr-pay';
22
+
23
+ const qrPay = QRPay.initVietQR({
24
+ bankBin: BanksObject.acb.bin,
25
+ bankNumber: '257678859', // Số tài khoản
26
+ })
27
+ const content = qrPay.build()
28
+
29
+ console.log(content)
30
+ // 00020101021138530010A0000007270123000697041601092576788590208QRIBFTTA53037045802VN6304AE9F
31
+
32
+ ```
33
+
34
+ ### VietQR Động
35
+
36
+ ```javascript
37
+ import { QRPay, BanksObject } from 'vietnam-qr-pay';
38
+
39
+ const qrPay = QRPay.initVietQR({
40
+ bankBin: BanksObject.acb.bin,
41
+ bankNumber: '257678859', // Số tài khoản
42
+ amount: '10000', // Số tiền
43
+ purpose: 'Chuyen tien', // Nội dung chuyển tiền
44
+ })
45
+ const content = qrPay.build()
46
+
47
+ console.log(content)
48
+ // 00020101021238530010A0000007270123000697041601092576788590208QRIBFTTA53037045405100005802VN62150811Chuyen tien630453E6
49
+
50
+ ```
51
+
52
+ ### QR Đa năng của MoMo và ZaloPay
53
+
54
+ Hiện tại, QR Đa năng của MoMo và ZaloPay đang thông qua Ngân hàng Bản Việt (BVBank) để nhận tiền.
55
+
56
+ Mỗi tài khoản MoMo/ZaloPay sẽ được gán một STK tương ứng tại BVBank. Tiền chuyển đến STK này sẽ được chuyển tiếp đến ví MoMo/ZaloPay.
57
+
58
+ Bạn có thể lấy STK này tại trang chi tiết của QR Nhận tiền trong ứng dụng MoMo/ZaloPay.
59
+
60
+ #### MoMo
61
+
62
+ ```javascript
63
+ import { QRPay, BanksObject } from 'vietnam-qr-pay';
64
+
65
+ // Số tài khoản trong ví MoMo
66
+ const accountNumber = '99MM24011M34875080'
67
+
68
+ const momoQR = QRPay.initVietQR({
69
+ bankBin: BanksObject.banviet.bin,
70
+ bankNumber: accountNumber,
71
+ // amount: '10000', // Số tiền (không bắt buộc)
72
+ // purpose: 'Chuyen tien', // Nội dung (không bắt buộc)
73
+ })
74
+
75
+ // Trong mã QR của MoMo có chứa thêm 1 mã tham chiếu tương ứng với STK
76
+ momoQR.additionalData.reference = 'MOMOW2W' + accountNumber.slice(10)
77
+
78
+ // Mã QR của MoMo có thêm 1 trường ID 80 với giá trị là 3 số cuối của SỐ ĐIỆN THOẠI của tài khoản nhận tiền
79
+ momoQR.setUnreservedField('80', '046')
80
+
81
+ const content = momoQR.build()
82
+
83
+ // 00020101021138620010A00000072701320006970454011899MM24011M348750800208QRIBFTTA53037045802VN62190515MOMOW2W3487508080030466304EBC8
84
+
85
+ ```
86
+
87
+ <img src="test/momo.svg" width="160">
88
+
89
+ #### ZaloPay
90
+
91
+ > Trong mã QR của ZaloPay có chứa một số thông tin bổ sung ở trường ID 26. Tuy nhiên chưa rõ chức năng của các thông tin này (có thể là dùng để định danh từng mã QR đc tạo trên hệ thống của ZaloPay). Trong ví dụ dưới sẽ bỏ qua các thông tin này.
92
+
93
+ ```javascript
94
+ import { QRPay, BanksObject } from 'vietnam-qr-pay';
95
+
96
+ // Số tài khoản trong ví ZaloPay
97
+ const accountNumber = '99ZP24009M07248267'
98
+
99
+ const zaloPayQR = QRPay.initVietQR({
100
+ bankBin: BanksObject.banviet.bin,
101
+ bankNumber: accountNumber,
102
+ // amount: '10000', // Số tiền (không bắt buộc)
103
+ // purpose: 'Chuyen tien', // Nội dung (không bắt buộc)
104
+ })
105
+
106
+ const content = zaloPayQR.build()
107
+ // 00020101021138620010A00000072701320006970454011899ZP24009M072482670208QRIBFTTA53037045802VN6304073C
108
+ ```
109
+
110
+ <img src="test/zalopay.svg" width="160">
111
+
112
+
113
+ ### VNPay
114
+
115
+ ```javascript
116
+ const qrPay = QRPay.initVNPayQR({
117
+ merchantId: '0102154778',
118
+ merchantName: 'TUGIACOMPANY',
119
+ store: 'TU GIA COMPUTER',
120
+ terminal: 'TUGIACO1',
121
+ })
122
+ const content = qrPay.build()
123
+ console.log(content)
124
+ // 00020101021126280010A0000007750110010531314453037045408210900005802VN5910CELLPHONES62600312CPSHN ONLINE0517021908061613127850705ONLHN0810CellphoneS63047685
125
+
126
+ ```
127
+
128
+
129
+ ## Decode mã QR
130
+
131
+ ### VietQR
132
+ ```javascript
133
+ import { QRPay } from 'vietnam-qr-pay';
134
+
135
+ const qrContent = '00020101021238530010A0000007270123000697041601092576788590208QRIBFTTA5303704540410005802VN62150811Chuyen tien6304BBB8'
136
+ const qrPay = new QRPay(qrContent);
137
+ console.log(qrPay.isValid) // true
138
+ console.log(qrPay.provider.name) // VIETQR
139
+ console.log(qrPay.consumer.bankBin) // 970416
140
+ console.log(qrPay.consumer.bankNumber) // 257678859
141
+ console.log(qrPay.amount) // 1000
142
+ console.log(qrPay.additionalData.purpose) // Chuyen tien
143
+
144
+ ```
145
+
146
+ ### VNPay
147
+ ```javascript
148
+ import { QRPay } from 'vietnam-qr-pay';
149
+
150
+ const qrContent = '00020101021126280010A0000007750110010531314453037045408210900005802VN5910CELLPHONES62600312CPSHN ONLINE0517021908061613127850705ONLHN0810CellphoneS63047685'
151
+ const qrPay = new QRPay(qrContent);
152
+ console.log(qrPay.isValid) // true
153
+ console.log(qrPay.provider.name) // VNPAY
154
+ console.log(qrPay.merchant.merchantId) // 0105313144
155
+ console.log(qrPay.amount) // 21090000
156
+ console.log(qrPay.additionalData.store) // CPSHN ONLINE
157
+ console.log(qrPay.additionalData.terminal) // ONLHN
158
+ console.log(qrPay.additionalData.purpose) // CellphoneS
159
+ console.log(qrPay.additionalData.reference) // 02190806161312785
160
+
161
+ ```
162
+
163
+
164
+ ## `QRPay` class
165
+
166
+
167
+ ```javascript
168
+ import { QRPay } from 'vietnam-qr-pay';
169
+ ```
170
+
171
+ | Name | Type | Description |
172
+ | --- | --- | --- |
173
+ | `isValid` | `boolean` | Kiểm tra tính hợp lệ của mã QR |
174
+ | `initMethod` | `string` | Phương thức khởi tạo (`11` - QR Tĩnh, `12` - QR động) |
175
+ | `provider` | `Provider` | Thông tin nhà cung cấp |
176
+ | `merchant` | `Merchant` | Thông tin merchant |
177
+ | `consumer` | `Consumer` | Thông tin người thanh toán |
178
+ | `amount` | `string` | Số tiền giao dịch |
179
+ | `currency` | `string` | Mã tiền tệ (VNĐ: 704) |
180
+ | `nation` | `string` | Mã quốc gia |
181
+ | `additionalData` | `AdditionalData` | Thông tin bổ sung |
182
+ | `crc` | `string` | Mã kiểm tra |
183
+ | `build()` | `method` | Tạo lại mã QR mới |
184
+
185
+ ### `Provider` class
186
+
187
+ Thông tin đơn vị cung cấp mã QR (VietQR, VNPay)
188
+
189
+
190
+ | Name | Type | Description |
191
+ | --- | --- | --- |
192
+ | `guid` | `string` | Mã định danh toàn cầu |
193
+ | `name` | `string` | Tên nhà cung cấp |
194
+
195
+ ### `Merchant` class
196
+
197
+ Thông tin merchant (Đơn vị chấp nhận thanh toán)
198
+
199
+ | Name | Type | Description |
200
+ | --- | --- | --- |
201
+ | `id` | `string` | Mã định danh đơn vị CNTT |
202
+ | `name` | `string` | Tên đơn vị CNTT |
203
+
204
+ ### `Consumer` class
205
+
206
+ Thông tin người thanh toán
207
+
208
+ | Name | Type | Description |
209
+ | --- | --- | --- |
210
+ | `bankBin` | `string` | Mã ngân hàng |
211
+ | `bankNumber` | `string` | Số tài khoản |
212
+
213
+ ### `AdditionalData` class
214
+
215
+ Thông tin bổ sung
216
+
217
+ | Name | Type | Description |
218
+ | --- | --- | --- |
219
+ | `billNumber` | `string` | Số hóa đơn |
220
+ | `mobileNumber` | `string` | Số điện thoại di động |
221
+ | `store` | `string` | Tên cửa hàng |
222
+ | `loyaltyNumber` | `string` | Mã khách hàng thân thiết |
223
+ | `reference` | `string` | Mã Tham chiếu |
224
+ | `customerLabel` | `string` | Mã khách hàng |
225
+ | `terminal` | `string` | Tên điểm bản |
226
+ | `purpose` | `string` | Nội dung giao dịch |
227
+
228
+ ### `build()` method
229
+
230
+ Trả về nội dung mã QR mới
231
+
232
+ ```javascript
233
+ import { QRPay } from 'vietnam-qr-pay';
234
+
235
+
236
+ const qrContent = '00020101021238530010A0000007270123000697041601092576788590208QRIBFTTA5303704540410005802VN62150811Chuyen tien6304BBB8'
237
+ const qrPay = new QRPay(qrContent);
238
+
239
+ // qrPay.amount === "10000"
240
+ // qrPay.additionalData.purpose === "Chuyen tien"
241
+
242
+ qrPay.amount = '999999';
243
+ qrPay.additionalData.purpose = 'Cam on nhe';
244
+
245
+ const newQRContent = qrPay.build();
246
+ /*
247
+ 00020101021238530010A0000007270123000697041601092576788590208QRIBFTTA530370454069999995802VN62140810Cam on nhe6304E786
248
+ */
249
+
250
+ ```
@@ -0,0 +1,10 @@
1
+ import { BankKey } from './bank-key';
2
+ export interface BankApp {
3
+ bank: BankKey;
4
+ scheme?: string;
5
+ packageId?: string;
6
+ appStoreId?: string;
7
+ supportVietQR?: boolean;
8
+ supportVNPayQR?: boolean;
9
+ }
10
+ export declare const BankApps: BankApp[];