sgqr

package module
v0.1.4 Latest Latest
Warning

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

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

README

SGQR payload builder written in Go

VietQR specification

Document

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDataTooLong = internal.ErrDataTooLong

Functions

func BuildPayload

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

Types

type Pair

type Pair = internal.Pair

func AdditionalData

func AdditionalData(data ...Pair) Pair

func CountryCode

func CountryCode(code string) 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 TransactionAmountFloat

func TransactionAmountFloat(amount float64) 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 Valuer

type Valuer = internal.Valuer

type VietQRInput added in v0.1.1

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

func (VietQRInput) BuildPayload added in v0.1.1

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