emvqr

package module
v0.0.0-...-e031b33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2021 License: MIT Imports: 2 Imported by: 0

README

EMV-QR 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/emvqr"
	qrcode2 "github.com/lizebang/qrcode-terminal"
	"github.com/skip2/go-qrcode"
)

func main() {
	i := &emvqr.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/emvqr
cpu: Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Benchmark_BuildPayload
Benchmark_BuildPayload-8   	  701736	      1441 ns/op	     672 B/op	      10 allocs/op
PASS
ok  	giautm.dev/emvqr	1.695s

References

Documentation

Index

Constants

View Source
const (
	GUIDVietQR = "A000000727"
)

Variables

View Source
var ErrDataTooLong = internal.ErrDataTooLong

Functions

func BuildPayload

func BuildPayload(root ...Pair) (string, error)

func CheckCRC

func CheckCRC(input string) bool

func GetIn

func GetIn(input string, ids ...string) string

Types

type Pair

type Pair = internal.Pair

func AdditionalData

func AdditionalData(data ...Pair) Pair

func CountryCode

func CountryCode(code string) Pair

func Currency

func Currency(id string, isoCode string, amount interface{}) Pair

func Float64

func Float64(id string, value float64) Pair

func List

func List(id string, values ...Pair) Pair

func MerchantAccountInfo

func MerchantAccountInfo(info ...Pair) Pair

func MerchantCategory

func MerchantCategory(code string) Pair

func MerchantCity

func MerchantCity(city string) Pair

func MerchantName

func MerchantName(name string) Pair

func PayloadFormatIndicator

func PayloadFormatIndicator() Pair

func PointOfInitiationMethod

func PointOfInitiationMethod(isDynamic bool) Pair

func PostalCode

func PostalCode(code string) Pair

func String

func String(id, value string) Pair

func TransactionAmount

func TransactionAmount(isoCode string, amount interface{}) Pair

func TransactionAmountUint

func TransactionAmountUint(amount uint64) Pair

func TransactionCurrency

func TransactionCurrency(code string) Pair

func Uint64

func Uint64(id string, value uint64) Pair

type ServiceCode

type ServiceCode string
const (
	// QR Inter-Bank Funds Transfer To Account
	ServiceCodeToAccount ServiceCode = "QRIBFTTA"
	// QR Inter-Bank Funds Transfer To Card
	ServiceCodeToCard ServiceCode = "QRIBFTTC"
)

func (ServiceCode) ToPair

func (s ServiceCode) ToPair(id string) Pair

type Valuer

type Valuer = internal.Valuer

type VietQRInput

type VietQRInput struct {
	AcqID          string `json:"acqID"`
	AccountNo      string `json:"accountNo"`
	Amount         uint64 `json:"amount"`
	AdditionalInfo string `json:"addInfo"`
	IsCard         bool   `json:"isCard"`
}

func (VietQRInput) BuildPayload

func (i VietQRInput) BuildPayload() (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL