promptpay

package module
v0.0.0-...-0c839c6 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2020 License: GPL-3.0 Imports: 6 Imported by: 1

README

Frontware

PromptPay

Generate QRCode for Thai PromptPay

logo

Golang API to generate QRCode

Build on your computer

Install dependencies

make init

Build

make build

Example

package main

import (
	"fmt"

	pp "github.com/Frontware/promptpay"
)

func main() {
	payment := pp.PromptPay{
		PromptPayID: "0105540087061", // Tax-ID/ID Card/E-Wallet
		Amount:      100.55,          // Positive amount
	}

	qrcode, _ := payment.Gen() // Generate string to be use in QRCode
	fmt.Println(qrcode)        // Print string
}

Try it on Go playground

Documentation

API

PkgGoDev

Specifications

EMV QR Code specification: https://www.emvco.com/wp-content/plugins/pmpro-customizations/oy-getfile.php?u=/wp-content/uploads/documents/EMVCo-Consumer-Presented-QR-Specification-v1.pdf


© 2020 Frontware International. All Rights Reserved.

Documentation

Overview

Package crc16 implements the 16-bit cyclic redundancy check, or CRC-16, checksum. See http://en.wikipedia.org/wiki/Cyclic_redundancy_check for information.

Index

Constants

View Source
const Size = 2

The size of a CRC-16 checksum in bytes.

Variables

View Source
var (
	X25 = &Conf{
		Poly: 0x1021, BitRev: true,
		IniVal: 0xffff, FinVal: 0xffff,
		BigEnd: false,
	}
	PPP    = X25
	Modbus = &Conf{
		Poly: 0x8005, BitRev: true,
		IniVal: 0xffff, FinVal: 0x0,
		BigEnd: false,
	}
	XModem = &Conf{
		Poly: 0x1021, BitRev: false,
		IniVal: 0x0000, FinVal: 0x0,
		BigEnd: true,
	}
	Kermit = &Conf{
		Poly: 0x1021, BitRev: true,
		IniVal: 0x0, FinVal: 0x0,
		BigEnd: false,
	}

	// Modified CRC configuration for PromptPay
	XModemRev = &Conf{
		Poly: 0x1021, BitRev: false,
		IniVal: 0xffff, FinVal: 0x0,
		BigEnd: true,
	}
)

Typical CRC-16 configurations. Mostly used are the CCITT (0x1021) and the IBM/ANSI (0x8005) polynomials, either bit-reversed or not. For more configurations see: http://reveng.sourceforge.net/crc-catalogue/

Functions

func Checksum

func Checksum(c *Conf, data []byte) uint16

Checksum returns the CRC-16 checksum of data using the configuration c.

func Update

func Update(crc uint16, tab *Table, p []byte) uint16

Update returns the CRC-16 checksum of p using the polynomial table tab constructed by MakeTable (bit-reversed order). The resulting CRC is in bit-reversed order (bit-15 corresponds to the X^0 term). Argument crc is the initial value of the CRC register.

func UpdateNBR

func UpdateNBR(crc uint16, tab *Table, p []byte) uint16

UpdateNBR returns the CRC-16 checksum of p using the polynomial table tab constructed by MakeTableNBR (non-bit-reversed order). The resulting CRC is in non-bit-reversed order (bit-0 corresponds to the X^0 term). Argument CRC is the initial value of the CRC register.

Types

type Conf

type Conf struct {
	Poly   uint16 // Polynomial to use.
	BitRev bool   // Bit reversed CRC (bit-15 is X^0)?
	IniVal uint16 // Initial value of CRC register.
	FinVal uint16 // XOR CRC with this at the end.
	BigEnd bool   // Emit *bytes* most significant first (see Hash.Sum)?
	// contains filtered or unexported fields
}

Conf is a CRC configuration. It is passed to functions New and Checksum and specifies the parameters of the calculated checksum. The first time New or Checksum are called with a configuration structure c, they calculate the polynomial table for this configuration; subsequent calls with the same c use the table already calculated. A few commonly used configurations are defined as global variables (X25, PPP, Modbus, etc.)

type Hash16

type Hash16 interface {
	hash.Hash
	Sum16() uint16
}

Hash16 is the common interface implemented by all 16-bit hash functions.

func New

func New(c *Conf) Hash16

New creates a new hash.Hash16 computing the CRC-16 checksum using the configuration c.

type PromptPay

type PromptPay struct {
	PromptPayID string
	Amount      float64
	OneTime     bool
}

PromptPay basic structure accomodating basic information

func (*PromptPay) Gen

func (p *PromptPay) Gen() (string, error)

Gen returns a string to create a PromptPay QRCode. It uses PromptPay structure to generate a string. Two arguments must be provided in order to be able to generate a string. PromptPayID and amount must be provided.

func (*PromptPay) GetPromptPayType

func (p *PromptPay) GetPromptPayType() Type

GetPromptPayType returns PromptPayType. Check whether the PromptPayID is and ID or a phone.

type Table

type Table [256]uint16

Table is a 256-word table representing the polynomial for efficient processing.

func MakeTable

func MakeTable(poly uint16) *Table

MakeTable returns the Table constructed from the specified polynomial. The table is calcuated in bit-reversed order (bit-15 corresponds to the X^0 term). Argument poly must be given bit-reversed (e.g. 0xA001 for the 0x8005 polynomial).

func MakeTableNBR

func MakeTableNBR(poly uint16) *Table

MakeTableNBR returns the Table constructed from the specified polynomial. The table is calculated in non-bit-reversed order (bit-0 corresponds to the X^0 term).

type Type

type Type int

Type type of PromptPay

const (
	// UNKNOWN unknown PromptPay type
	UNKNOWN Type = 0
	// ID tax/card ID
	ID Type = 1
	// PHONE mobile/phone
	PHONE Type = 2
	// EWALLET E-Wallet
	EWALLET Type = 3
)

Jump to

Keyboard shortcuts

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