jpqr

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package jpqr implements encoding and decoding of JPQR as defined in JPQR MPM Guideline.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(payload []byte) (*mpm.Code, error)

Decode decodes payload and validates as JPQR.

Example
package main

import (
	"fmt"
	"log"

	"go.mercari.io/go-emv-code/mpm"
	"go.mercari.io/go-emv-code/mpm/jpqr"
	"go.mercari.io/go-emv-code/tlv"
)

func main() {
	c := mpm.Code{
		PayloadFormatIndicator:  "01",
		PointOfInitiationMethod: mpm.PointOfInitiationMethodStatic,
		MerchantAccountInformation: []tlv.TLV{
			{Tag: "29", Length: "30", Value: "0012D156000000000510A93FO3230Q"},
			{Tag: "31", Length: "28", Value: "0012D15600000001030812345678"},
			{Tag: "26", Length: "68", Value: "0019jp.or.paymentsjapan011300000000000010204000103060000010406000001"},
		},
		MerchantCategoryCode: "5812",
		TransactionCurrency:  "392",
		CountryCode:          "JP",
		MerchantName:         "xxx",
		MerchantCity:         "xxx",
		PostalCode:           "1066143",
		MerchantInformation: mpm.NullMerchantInformation{
			LanguagePreference: "JA",
			Name:               "メルペイ カフェ",
			Valid:              true,
		},
	}

	buf, err := jpqr.Encode(&c)
	if err != nil {
		log.Fatal(err)
	}

	dst, err := jpqr.Decode(buf)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%+v\n", dst)

}
Output:

&{PayloadFormatIndicator:01 PointOfInitiationMethod:11 MerchantAccountInformation:[{Tag:29 Length:30 Value:0012D156000000000510A93FO3230Q} {Tag:31 Length:28 Value:0012D15600000001030812345678} {Tag:26 Length:68 Value:0019jp.or.paymentsjapan011300000000000010204000103060000010406000001}] MerchantCategoryCode:5812 TransactionCurrency:392 TransactionAmount:{String: Valid:false} TipOrConvenienceIndicator: ValueOfConvenienceFeeFixed:{String: Valid:false} ValueOfConvenienceFeePercentage:{String: Valid:false} CountryCode:JP MerchantName:xxx MerchantCity:xxx PostalCode:1066143 AdditionalDataFieldTemplate: MerchantInformation:{LanguagePreference:JA Name:メルペイ カフェ City: Valid:true} UnreservedTemplates:[]}

func Encode

func Encode(c *mpm.Code) ([]byte, error)

Encode encodes to EMV Payment Code payload.

Types

type ID

type ID struct {
	Prefix string `lv:"00"`
	LV1    string `lv:"01"`
	LV2    string `lv:"02"`
	LV3    string `lv:"03"`
	LV4    string `lv:"04"`
}

ID represents a parsed JPQR-ID.

func ParseID

func ParseID(c *mpm.Code) (*ID, error)

ParseID validates and parses given *mpm.Code as JPQR-ID.

func ParseIDFromString added in v0.1.4

func ParseIDFromString(v string) (*ID, error)

ParseIDFromString validates and parses given string as JPQR-ID.

func (*ID) String

func (i *ID) String() string

String returns the accumulated string.

Jump to

Keyboard shortcuts

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