Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

kuronekouwu/promptparse-go

Repository files navigation

Promptparse Golang

Go Report Card Documentation GitHub release

"All-in-one Golang for PromptPay & EMVCo QR Codes"

That No dependency required. So here we go!

Original library from (Forked from)

maythiwat/promptparse

Insatallation

go get github.com/mrwan200/promptparse-go

Features

  • Parse — PromptPay & EMVCo QR Code data strings into object
  • Generate — QR Code data from pre-made templates (for example: PromptPay AnyID, PromptPay Bill Payment, TrueMoney, etc.)
  • Manipulate — any values from parsed QR Code data (for example: transfer amount, account number) and encodes back into QR Code data
  • Validate — checksum and data structure for known QR Code formats (for example: Slip Verify API Mini QR)

Usage

Parsing data and get value from tag

package main

import (
    "log"

    promptparse "github.com/mrwan200/promptparse-go"
)

func main() {
    parsed := promptparse.Parse("000201010212293...", true, true)
    if parsed == nil {
        log.Println("Invalid payload.")
        return
    }

    // Now get tag transfer ref
    log.Println(parsed.GetTagValue("00", "")) // Result: YYYY/MM/DD HH:mm:ss 01
}

Build QR data and append CRC tag

package main

import (
	"log"

	"github.com/mrwan200/promptparse-go/lib"
)

func main() {
	// Example data
	data := []lib.TLVTag{
		lib.Tag("00", "01"),
		lib.Tag("01", "11"),
	}

	// Set CRC Tag ID '63'
	tag, err := lib.WithCRCTag(lib.Encode(data), "63")
	if err != nil {
		log.Println("Error when create CRC tag")
        return
	}
	log.Println(tag) // Result: YYYY/MM/DD HH:mm:ss 00020101...
}

Generate PromptPay Bill Payment QR

package main

import (
	"log"

	"github.com/mrwan200/promptparse-go/generator"
)

func main() {
	log.Println(generator.BillPayment("1xxxxxxxxxxxx", 300, "INV12345", "", ""))  // Result: YYYY/MM/DD HH:mm:ss 00020101021230490016...
}

Validate & extract data from Slip Verify QR

package main

import (
	"log"

	promptparse "github.com/mrwan200/promptparse-go"
)

func main() {
	slip := promptparse.SlipVerify("0041000600.....")
	if slip == nil {
		log.Println("Invalid slip verify")
		return
	}

	log.Println(slip.SendingBank) // Result: YYYY/MM/DD HH:mm:ss 004
	log.Println(slip.TransRef) // Result: YYYY/MM/DD HH:mm:ss 0141012...
}

Convert BOT Barcode to PromptPay QR Tag 30 (Bill Payment)

package main

import (
	"log"

	promptparse "github.com/mrwan200/promptparse-go"
)

func main() {
	bill := promptparse.ParseBarcode("|310109999999901\r...")
	if bill.BillerID == "" {
		log.Println("Invalid barcode.")
		return
	}

	log.Println(bill.ToQRTag30()) // Reseult: YYYY/MM/DD HH:mm:ss  00020101021....
}

References

See also

License

This project is MIT licensed (see LICENSE)