SGQR payload builder written in Go
VietQR specification
Data Objects Under the Root of a QR Code
Name | ID | Format | Length | Presence | Comment |
---|---|---|---|---|---|
Payload Format Indicator | "00" | N | "02" | M | Refer to Ref A. |
Point of Initiation Method | "01" | N | "02" | O | "11" for static, "22" for dynamic Refer to Ref A. |
Merchant Account Information | "02"-"51" | ans | Each var. up to "99" | M | At least one Merchant Account Information data object shall be present. Refer to Ref A. |
Transaction Currency | "53" | N | "03" | M | Fixed to "704" Refer to Ref A. |
Country Code | "58" | ans | "02" | M | Fixed to "VN" Refer to Ref A. |
Additional Data Field Template | "62" | S | var. up to "99" | O | Refer to Ref A. |
CRC | "63" | ans | "04" | M | Refer to Ref A. |
Data Objects for Additional Data Field Template (ID "62")
Name | ID | Format | Length | Presence |
---|---|---|---|---|
Purpose of Transaction | "08" | ans | var. up to "25" | O |
VietQR - Merchant Account Information (ID "38")
Data Object | Input Characters | Remarks |
---|---|---|
Merchant Account Information | "3856" | Floating ID "38". This ID is allocated for this QR only Refer to Ref B. |
- Global Unique Identifier - Beneficiary Organization * ACQ ID / BNB ID * Merchant ID / Consumer ID - Service Code |
"0010A000000727" "012600069704150112113366668888" "0208QRIBFTTA" |
Reversed domain 970415 - NAPAS BIN 113366668888 QRIBFTTA / QRIBFTTC |
Sample code
package main
import (
"fmt"
"giautm.dev/sgqr"
qrcode2 "github.com/lizebang/qrcode-terminal"
"github.com/skip2/go-qrcode"
)
func main() {
i := &sgqr.VietQRInput{
AcqID: "970415",
AccountNo: "113366668888",
Amount: 79000,
AdditionalInfo: "Ung Ho Quy Vac Xin",
}
payload, err := i.BuildPayload()
if err != nil {
panic(err)
}
fmt.Println("Data", payload)
qrcode2.QRCode(payload, qrcode2.BrightWhite, qrcode2.NormalBlack, qrcode.Medium)
}
Performance
goos: darwin
goarch: amd64
pkg: giautm.dev/sgqr
cpu: Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Benchmark_BuildPayload
Benchmark_BuildPayload-8 1558408 771.8 ns/op 594 B/op 8 allocs/op
PASS
ok giautm.dev/sgqr 2.447s