vietqr

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

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

Go to latest
Published: Jun 13, 2025 License: MIT Imports: 3 Imported by: 0

README

VietQR - Golang

Go Report Card GoDoc Go Version

VietQR Logo

A powerful Golang library for generating VietQR codes for NAPAS payment integration

📋 Table of Contents

🌟 Overview

VietQR is a Golang library that simplifies the generation of QR codes for NAPAS payment integration in Vietnam. It provides a clean and efficient way to create payment QR codes that comply with the NAPAS VietQR standard.

✨ Features

  • 🚀 Simple and intuitive API
  • 💰 Support for all NAPAS VietQR payment fields
  • 🔒 Type-safe implementation
  • 📝 Comprehensive field validation
  • 🎯 QR code generation for various payment scenarios
  • 🔍 QR code parsing and validation
  • 📚 Well-documented code

📥 Installation

go get github.com/ducnpdev/vietqr

�� Quick Start

package main

import (
    "fmt"
    "github.com/ducnpdev/vietqr"
)

func main() {
    // Create a VietQR payment request
    qrRequest := vietqr.RequestGenerateViQR{
        MerchantAccountInformation: vietqr.MerchantAccountInformation{
            AccountNo: "999990335280715",
        },
        TransactionAmount: "505000",
        AdditionalDataFieldTemplate: vietqr.AdditionalDataFieldTemplate{
            Description: "Payment for services",
        },
        Mcc:          "5139",
        ReceiverName: "Company ABC",
    }

    // Generate the VietQR code
    qrContent := vietqr.GenerateViQR(qrRequest)
    fmt.Println("Generated VietQR Content:", qrContent)
}

📖 Usage Examples

Basic Payment QR
qrRequest := vietqr.RequestGenerateViQR{
    MerchantAccountInformation: vietqr.MerchantAccountInformation{
        AccountNo: "999990335280715",
    },
    TransactionAmount: "100000",
    AdditionalDataFieldTemplate: vietqr.AdditionalDataFieldTemplate{
        Description: "Basic payment",
    },
    Mcc:          "5139",
    ReceiverName: "Merchant Name",
}
QR with Additional Data
qrRequest := vietqr.RequestGenerateViQR{
    MerchantAccountInformation: vietqr.MerchantAccountInformation{
        AccountNo: "999990335280715",
    },
    TransactionAmount: "200000",
    AdditionalDataFieldTemplate: vietqr.AdditionalDataFieldTemplate{
        Description: "Detailed payment information",
        // Add more fields as needed
    },
    Mcc:          "5139",
    ReceiverName: "Merchant Name",
}

🔍 QR Code Structure

The VietQR code follows the NAPAS standard structure. Here's an example of the QR code field breakdown:

  • golang vietqr detech qr.
0002
    01
0102
    12
3859
    0010
        A000000727
    0129
        0006
            970437
        0115
            999990335280715
        0208
            QRIBFTTA
5204
    5139
5303
    704
5406
    50500
5802
    VN
6217
    0813
        test noi dung
5907
    Cty ABC
6304
    33C4

�� Documentation

For detailed documentation about the VietQR standard, please refer to the official NAPAS documentation:

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❤️ by ducnpdev

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CRC16_ARC         = Params{0x8005, 0x0000, true, true, 0x0000, 0xBB3D, "CRC-16/ARC"}
	CRC16_AUG_CCITT   = Params{0x1021, 0x1D0F, false, false, 0x0000, 0xE5CC, "CRC-16/AUG-CCITT"}
	CRC16_BUYPASS     = Params{0x8005, 0x0000, false, false, 0x0000, 0xFEE8, "CRC-16/BUYPASS"}
	CRC16_CCITT_FALSE = Params{0x1021, 0xFFFF, false, false, 0x0000, 0x29B1, "CRC-16/CCITT-FALSE"}
	CRC16_CDMA2000    = Params{0xC867, 0xFFFF, false, false, 0x0000, 0x4C06, "CRC-16/CDMA2000"}
	CRC16_DDS_110     = Params{0x8005, 0x800D, false, false, 0x0000, 0x9ECF, "CRC-16/DDS-110"}
	CRC16_DECT_R      = Params{0x0589, 0x0000, false, false, 0x0001, 0x007E, "CRC-16/DECT-R"}
	CRC16_DECT_X      = Params{0x0589, 0x0000, false, false, 0x0000, 0x007F, "CRC-16/DECT-X"}
	CRC16_DNP         = Params{0x3D65, 0x0000, true, true, 0xFFFF, 0xEA82, "CRC-16/DNP"}
	CRC16_EN_13757    = Params{0x3D65, 0x0000, false, false, 0xFFFF, 0xC2B7, "CRC-16/EN-13757"}
	CRC16_GENIBUS     = Params{0x1021, 0xFFFF, false, false, 0xFFFF, 0xD64E, "CRC-16/GENIBUS"}
	CRC16_MAXIM       = Params{0x8005, 0x0000, true, true, 0xFFFF, 0x44C2, "CRC-16/MAXIM"}
	CRC16_MCRF4XX     = Params{0x1021, 0xFFFF, true, true, 0x0000, 0x6F91, "CRC-16/MCRF4XX"}
	CRC16_RIELLO      = Params{0x1021, 0xB2AA, true, true, 0x0000, 0x63D0, "CRC-16/RIELLO"}
	CRC16_T10_DIF     = Params{0x8BB7, 0x0000, false, false, 0x0000, 0xD0DB, "CRC-16/T10-DIF"}
	CRC16_TELEDISK    = Params{0xA097, 0x0000, false, false, 0x0000, 0x0FB3, "CRC-16/TELEDISK"}
	CRC16_TMS37157    = Params{0x1021, 0x89EC, true, true, 0x0000, 0x26B1, "CRC-16/TMS37157"}
	CRC16_USB         = Params{0x8005, 0xFFFF, true, true, 0xFFFF, 0xB4C8, "CRC-16/USB"}
	CRC16_CRC_A       = Params{0x1021, 0xC6C6, true, true, 0x0000, 0xBF05, "CRC-16/CRC-A"}
	CRC16_KERMIT      = Params{0x1021, 0x0000, true, true, 0x0000, 0x2189, "CRC-16/KERMIT"}
	CRC16_MODBUS      = Params{0x8005, 0xFFFF, true, true, 0x0000, 0x4B37, "CRC-16/MODBUS"}
	CRC16_X_25        = Params{0x1021, 0xFFFF, true, true, 0xFFFF, 0x906E, "CRC-16/X-25"}
	CRC16_XMODEM      = Params{0x1021, 0x0000, false, false, 0x0000, 0x31C3, "CRC-16/XMODEM"}
)

Predefined CRC-16 algorithms. List of algorithms with their parameters borrowed from here - http://reveng.sourceforge.net/crc-catalogue/16.htm

The variables can be used to create Table for the selected algorithm.

Functions

func Checksum

func Checksum(data []byte, table *Table) uint16

Checksum returns CRC checksum of data using scpecified algorithm represented by the Table.

func Complete

func Complete(crc uint16, table *Table) uint16

Complete returns the result of CRC calculation and post-calculation processing of the crc.

func GenerateViQR

func GenerateViQR(req RequestGenerateViQR) string

func Init

func Init(table *Table) uint16

Init returns the initial value for CRC register corresponding to the specified algorithm.

func Update

func Update(crc uint16, data []byte, table *Table) uint16

Update returns the result of adding the bytes in data to the crc.

Types

type AdditionalDataFieldTemplate

type AdditionalDataFieldTemplate struct {
	Description string `json:"description"`
}

type Hash16

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

func New

func New(t *Table) Hash16

New creates a new CRC16 digest for the given table.

type MerchantAccountInformation

type MerchantAccountInformation struct {
	// mặc định là ngân hàng HDBank: 970437
	AcqID     string `json:"acqID"`
	AccountNo string `json:"accountNo"`
}

type Params

type Params struct {
	Poly   uint16
	Init   uint16
	RefIn  bool
	RefOut bool
	XorOut uint16
	Check  uint16
	Name   string
}

Params represents parameters of CRC-16 algorithms. More information about algorithms parametrization and parameter descriptions can be found here - http://www.zlib.net/crc_v3.txt

type RequestGenerateViQR

type RequestGenerateViQR struct {
	// Phiên bản dữ liệu: tag 00
	PayloadFormatIndicator string `json:"payloadFormatIndicator"`

	// Phương thức khởi tạo, phân biệt QR động vào QR tĩnh: tag 01
	// mặc định là QR động: 010212
	PointInitiationMethod string `json:"pointInitiationMethod"`

	// Thông tin định danh ĐVCNTT: tag
	MerchantAccountInformation `json:"merchantAccountInformation"`

	// Merchant Category Code MCC: tag 52
	// identity merchant type
	// apply different fee base on mcc
	Mcc string `json:"mcc"`

	// Mã tiền tệ: tag 53
	// mặc định là VND: 704
	TransactionCurrency string `json:"transactionCurrency"`

	// Số tiền GD: tag 54
	TransactionAmount string `json:"transactionAmount"`

	// Mã quốc gia: tag 58
	// mặc định là VN
	CountryCode string `json:"countryCode"`

	// Merchant Reciever Name: tag 59
	ReceiverName string `json:"recieveName"`

	// Thông tin bổ sung: tag 62
	AdditionalDataFieldTemplate `json:"additionalDataFieldTemplate"`
}

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is a 256-word table representing polinomial and algorithm settings for efficient processing.

func MakeTable

func MakeTable(params Params) *Table

MakeTable returns the Table constructed from the specified algorithm.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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