1.3.3 • Published 1 month ago

vietnam-qr-pay v1.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

Vietnam QR Pay

Thư viện hỗ trợ encode/decode mã QR của VietQR & VNPayQR

Install

npm install vietnam-qr-pay

Encode - Tạo mã QR

VietQR Tĩnh

import { QRPay, BanksObject } from 'vietnam-qr-pay';

const qrPay = QRPay.initVietQR({
  bankBin: BanksObject.acb.bin,
  bankNumber: '257678859', // Số tài khoản
})
const content = qrPay.build()

console.log(content)
// 00020101021138530010A0000007270123000697041601092576788590208QRIBFTTA53037045802VN6304AE9F
 

VietQR Động

import { QRPay, BanksObject } from 'vietnam-qr-pay';

const qrPay = QRPay.initVietQR({
  bankBin: BanksObject.acb.bin,
  bankNumber: '257678859', // Số tài khoản
  amount: '10000', // Số tiền
  purpose: 'Chuyen tien', // Nội dung chuyển tiền
})
const content = qrPay.build()

console.log(content)
// 00020101021238530010A0000007270123000697041601092576788590208QRIBFTTA53037045405100005802VN62150811Chuyen tien630453E6

VNPay

const qrPay = QRPay.initVNPayQR({
  merchantId: '0102154778',
  merchantName: 'TUGIACOMPANY',
  store: 'TU GIA COMPUTER',
  terminal: 'TUGIACO1',
})
const content = qrPay.build()
console.log(content)
// 00020101021126280010A0000007750110010531314453037045408210900005802VN5910CELLPHONES62600312CPSHN ONLINE0517021908061613127850705ONLHN0810CellphoneS63047685

Decode mã QR

VietQR

import { QRPay } from 'vietnam-qr-pay';

const qrContent = '00020101021238530010A0000007270123000697041601092576788590208QRIBFTTA5303704540410005802VN62150811Chuyen tien6304BBB8'
const qrPay = new QRPay(qrContent);
console.log(qrPay.isValid) // true
console.log(qrPay.provider.name) // VIETQR
console.log(qrPay.consumer.bankBin) // 970416
console.log(qrPay.consumer.bankNumber) // 257678859
console.log(qrPay.amount) // 1000
console.log(qrPay.additionalData.purpose) // Chuyen tien

VNPay

import { QRPay } from 'vietnam-qr-pay';

const qrContent = '00020101021126280010A0000007750110010531314453037045408210900005802VN5910CELLPHONES62600312CPSHN ONLINE0517021908061613127850705ONLHN0810CellphoneS63047685'
const qrPay = new QRPay(qrContent);
console.log(qrPay.isValid) // true
console.log(qrPay.provider.name) // VNPAY
console.log(qrPay.merchant.merchantId) // 0105313144
console.log(qrPay.amount) // 21090000
console.log(qrPay.additionalData.store) // CPSHN ONLINE
console.log(qrPay.additionalData.terminal) // ONLHN
console.log(qrPay.additionalData.purpose) // CellphoneS
console.log(qrPay.additionalData.reference) // 02190806161312785

QRPay class

import { QRPay } from 'vietnam-qr-pay';
NameTypeDescription
isValidbooleanKiểm tra tính hợp lệ của mã QR
initMethodstringPhương thức khởi tạo (11 - QR Tĩnh, 12 - QR động)
providerProviderThông tin nhà cung cấp
merchantMerchantThông tin merchant
consumerConsumerThông tin người thanh toán
amountstringSố tiền giao dịch
currencystringMã tiền tệ (VNĐ: 704)
nationstringMã quốc gia
additionalDataAdditionalDataThông tin bổ sung
crcstringMã kiểm tra
build()methodTạo lại mã QR mới

Provider class

Thông tin đơn vị cung cấp mã QR (VietQR, VNPay)

NameTypeDescription
guidstringMã định danh toàn cầu
namestringTên nhà cung cấp

Merchant class

Thông tin merchant (Đơn vị chấp nhận thanh toán)

NameTypeDescription
idstringMã định danh đơn vị CNTT
namestringTên đơn vị CNTT

Consumer class

Thông tin người thanh toán

NameTypeDescription
bankBinstringMã ngân hàng
bankNumberstringSố tài khoản

AdditionalData class

Thông tin bổ sung

NameTypeDescription
billNumberstringSố hóa đơn
mobileNumberstringSố điện thoại di động
storestringTên cửa hàng
loyaltyNumberstringMã khách hàng thân thiết
referencestringMã Tham chiếu
customerLabelstringMã khách hàng
terminalstringTên điểm bản
purposestringNội dung giao dịch

build() method

Trả về nội dung mã QR mới

import { QRPay } from 'vietnam-qr-pay';


const qrContent = '00020101021238530010A0000007270123000697041601092576788590208QRIBFTTA5303704540410005802VN62150811Chuyen tien6304BBB8'
const qrPay = new QRPay(qrContent);

// qrPay.amount === "10000"
// qrPay.additionalData.purpose === "Chuyen tien"

qrPay.amount = '999999';
qrPay.additionalData.purpose = 'Cam on nhe';

const newQRContent = qrPay.build();
/* 
00020101021238530010A0000007270123000697041601092576788590208QRIBFTTA530370454069999995802VN62140810Cam on nhe6304E786
*/
1.3.3

1 month ago

1.3.2

2 months ago

1.3.1

6 months ago

1.3.0

8 months ago

1.2.0

1 year ago

1.1.9

1 year ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago