promptpayqr

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

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 10 Imported by: 0

README

promptpay-qr-go

GoLang Library to generate QR Code payload for PromptPay inspired from dtinth/promptpay-qr

Requirement

GoLang 1.12.x

Install

go get -u github.com/kazekim/promptpay-qr-go

Implement

package main

import (
    "bytes"
    "fmt"
    "github.com/kazekim/promptpay-qr-go"
    "image"
    "image/png"
    "os"
)

func main() {

  // Image is return in []byte. You should convert to image by yourself.
    qr, err := promptpayqr.QRForTargetWithAmount("0899999999","500" )

    if err != nil {
	    panic(err)
    }

  // I give an example of image convert here.
    byteToImage(*qr)

}


func byteToImage(imgByte []byte) {
    img, _, _ := image.Decode(bytes.NewReader(imgByte))

    //save the imgByte to file
    out, err := os.Create("./QRImg.png")

    if err != nil {
	    fmt.Println(err)
	    os.Exit(1)
    }

    err = png.Encode(out, img)

    if err != nil {
	    fmt.Println(err)
	    os.Exit(1)
    }
}

Please use this function

qr, err := promptpayqr.QRWithPromptpayLogoForTargetWithAmount("0899999999","500" )

Contributing

Everyone can contribute it. Feel free to improve it and make it better.

License

The MIT License (MIT)

Documentation

Index

Constants

View Source
const (
	ID_PAYLOAD_FORMAT                        = "00"
	ID_POI_METHOD                            = "01"
	ID_MERCHANT_INFORMATION_BOT              = "29"
	ID_MERCHANT_INFORMATION_BOT_BILL_PAYMENT = "30"
	ID_TRANSACTION_CURRENCY                  = "53"
	ID_TRANSACTION_AMOUNT                    = "54"
	ID_COUNTRY_CODE                          = "58"
	ID_DATA_OBJECTS                          = "62"
	ID_CRC                                   = "63"

	PAYLOAD_FORMAT_EMV_QRCPS_MERCHANT_PRESENTED_MODE = "01"
	POI_METHOD_STATIC                                = "11"
	POI_METHOD_DYNAMIC                               = "12"
	MERCHANT_INFORMATION_TEMPLATE_ID_GUID            = "00"
	BOT_ID_MERCHANT_PHONE_NUMBER                     = "01"
	BOT_ID_MERCHANT_TAX_ID                           = "02"
	BOT_ID_MERCHANT_EWALLET_ID                       = "03"
	BOT_ID_TAG30_AID                                 = "00"
	BOT_ID_TAG30_BILLER_ID                           = "01"
	BOT_ID_TAG30_REF1                                = "02"
	BOT_ID_TAG30_REF2                                = "03"
	BOT_ID_TAG62_TERMINAL_ID                         = "07"
	GUID_PROMPTPAY                                   = "A000000677010111"
	GUID_PROMPTPAY_BILL_PAYMENT                      = "A000000677010112"
	TRANSACTION_CURRENCY_THB                         = "764"
	COUNTRY_CODE_TH                                  = "TH"
)

Variables

This section is empty.

Functions

func QRForBillPayment

func QRForBillPayment(billerID string, ref1 string, ref2 string, terminalID string, amount string) (*[]byte, error)

func QRForTarget

func QRForTarget(target string) (*[]byte, error)

func QRForTargetWithAmount

func QRForTargetWithAmount(target, amount string) (string, error)

func QRWithPromptpayLogoForTargetWithAmount

func QRWithPromptpayLogoForTargetWithAmount(target, amount string) (*[]byte, error)

Types

type PromptPayQR

type PromptPayQR struct {
}

func New

func New() *PromptPayQR

func (*PromptPayQR) GenerateBillPaymentPayload

func (qr *PromptPayQR) GenerateBillPaymentPayload(billerID string, ref1 string, ref2 string, terminalID *string, amount *string) string

func (*PromptPayQR) GeneratePayload

func (qr *PromptPayQR) GeneratePayload(target string, amount *string) string

type QRCodeGenerator

type QRCodeGenerator struct{}

QRCodeGenerator is a struct that provides methods to generate QR code payloads.

func NewQRCodeGenerator

func NewQRCodeGenerator() *QRCodeGenerator

NewQRCodeGenerator creates a new instance of QRCodeGenerator.

func (*QRCodeGenerator) GenerateBillPaymentPayload

func (q *QRCodeGenerator) GenerateBillPaymentPayload(billerID, ref1, ref2 string, terminalID, amount *string) string

GenerateBillPaymentPayload generates a QR code payload for bill payment.

func (*QRCodeGenerator) GeneratePayload

func (q *QRCodeGenerator) GeneratePayload(target string, amount *string) string

GeneratePayload generates a QR code payload for a target with an optional amount.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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