khqr

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 6 Imported by: 0

README

bakong-khqr (Unofficial)

A Go package for generating payment transactions compliant with the Bakong KHQR standard.

Download Mobile App

Requirement

Installation

go get github.com/chhunneng/bakong-khqr

Usage

The bakong-khqr package provides methods for generating QR codes, deeplinks, and verifying payment transactions using the Bakong KHQR standard.

Importing the Package
import "github.com/chhunneng/bakong-khqr"
Creating a Payment Transaction

Example:

package main

import (
    "fmt"
    "github.com/chhunneng/bakong-khqr"
)

func main() {
    // Initialize KHQR instance with Bakong Developer Token
    khqr := bakong_khqr.New("eyJhbGciOiJIUzI1NiIsI...nMhgG87BWeDg9Lu-_CKe1SMqC0")

    // Generate QR code data for a transaction
    qr, err := khqr.CreateQR(
        "your_name@wing", "Your Name", "Phnom Penh", 10000, "KHR", "MShop", "85512345678", "TRX019283775", "Cashier-01", false
    )
    if err != nil {
        fmt.Println("Error creating QR:", err)
        return
    }
    fmt.Println("QR Code:", qr)

    // Generate Deeplink
    deeplink, err := khqr.GenerateDeeplink(qr, "https://bakong.nbc.org.kh", "https://bakong.nbc.gov.kh/images/logo.svg", "YourApp")
    if err != nil {
        fmt.Println("Error generating deeplink:", err)
        return
    }
    fmt.Println("Deeplink:", deeplink)

    // Get MD5 Hash
    md5 := khqr.GenerateMD5(qr)
    fmt.Println("MD5 Hash:", md5)

    // Check Payment Status
    status, err := khqr.CheckPayment(md5)
    if err != nil {
        fmt.Println("Error checking payment:", err)
        return
    }
    fmt.Println("Payment Status:", status)
}
Bulk Transaction Verification

To check multiple transactions:

bulkStatus, err := khqr.CheckBulkPayments([]string{
    "dfcabf4598d1c405a75540a3d4ca099d",
    "5154e4f795634ff1a0ae4b48e53a6d9c",
    // Add more MD5 hashes as needed
})
if err != nil {
    fmt.Println("Error checking bulk payments:", err)
}
fmt.Println("Successful Transactions:", bulkStatus)
Parameters for CreateQR Method
  • bankAccount: Associated bank account for the transaction.
  • merchantName: Name of the merchant.
  • merchantCity: City where the merchant is located.
  • amount: Transaction amount.
  • currency: Transaction currency (e.g., USD, KHR).
  • storeLabel: Label or name of the store.
  • phoneNumber: Merchant's contact number.
  • billNumber: Reference number for the bill.
  • terminalLabel: Terminal label for the transaction.
  • static: Whether the QR is static or dynamic.

Note: Using static mode will create a Static QR Code for payment, allowing unlimited transactions, usage, and a zero amount included.

  • qr: QR code data generated by the CreateQR method.
  • callback: Callback URL for post-payment redirection.
  • appIconUrl: Icon URL for the app.
  • appName: Application name.

Bakong Official Documentation

Development API: https://sit-api-bakong.nbc.gov.kh/

Production API: https://api-bakong.nbc.gov.kh/

License

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

Contributing

If you would like to contribute to this project, please fork the repository and submit a pull request.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KHQR

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

Define the KHQR struct

func NewKHQR

func NewKHQR(bakongToken string) *KHQR

Initialize the KHQR struct

func (*KHQR) CheckBulkPayments

func (khqr *KHQR) CheckBulkPayments(md5List []string) ([]string, error)

Method to check bulk payments

func (*KHQR) CheckPayment

func (khqr *KHQR) CheckPayment(md5 string) (string, error)

Method to check payment status

func (*KHQR) CreateQR

func (khqr *KHQR) CreateQR(bankAccount string, merchantName string, merchantCity string, amount float64, currency string, storeLabel string, phoneNumber string, billNumber string, terminalLabel string, static bool) (string, error)

Method to create QR code

func (khqr *KHQR) GenerateDeeplink(qr string, callback string, appIconUrl string, appName string) (string, error)

Method to generate deep link

func (*KHQR) GenerateMD5

func (khqr *KHQR) GenerateMD5(qr string) string

Method to generate MD5 hash

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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