mpm

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package mpm implements encoding and decoding of EMV as defined in EMV Payment Code.

Index

Examples

Constants

View Source
const (
	// InvalidFormat represents given payload has invalid format.
	InvalidFormat errorCode = iota + 1
	// InvalidCRC represents CRC is invalid.
	InvalidCRC
)
View Source
const (

	// MaxSize represents max size of EMV Payment Code payload.
	MaxSize = 512
)

Variables

This section is empty.

Functions

func Encode

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

Encode encodes to EMV Payment Code payload.

func NewInvalidCRC

func NewInvalidCRC(expected, got uint16) error

NewInvalidCRC creates a new NewInvalidCRC error.

func NewInvalidFormat

func NewInvalidFormat(msg string) error

NewInvalidFormat creates a new NewInvalidFormat error.

Types

type Code

type Code struct {
	PayloadFormatIndicator          string                    `emv:"00"` // The first data object
	PointOfInitiationMethod         PointOfInitiationMethod   `emv:"01"`
	MerchantAccountInformation      []tlv.TLV                 `emv:"MerchantAccountInformation"`
	MerchantCategoryCode            string                    `emv:"52"`
	TransactionCurrency             string                    `emv:"53"`
	TransactionAmount               NullString                `emv:"54"`
	TipOrConvenienceIndicator       TipOrConvenienceIndicator `emv:"55"`
	ValueOfConvenienceFeeFixed      NullString                `emv:"56"`
	ValueOfConvenienceFeePercentage NullString                `emv:"57"`
	CountryCode                     string                    `emv:"58"`
	MerchantName                    string                    `emv:"59"`
	MerchantCity                    string                    `emv:"60"`
	PostalCode                      string                    `emv:"61"`
	AdditionalDataFieldTemplate     string                    `emv:"62"`
	// CRC                             string  `emv:"63"` // The last object under the root. But useless for value.
	MerchantInformation NullMerchantInformation `emv:"64"`
	UnreservedTemplates []tlv.TLV               `emv:"UnreservedTemplates"`
}

Code represents EMV Payment Code payload structure.

func Decode

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

Decode decodes payload and validates as EMV MPM.

Example
package main

import (
	"fmt"
	"log"

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

func main() {
	c := mpm.Code{
		PayloadFormatIndicator:      "01",
		PointOfInitiationMethod:     mpm.PointOfInitiationMethodDynamic,
		MerchantCategoryCode:        "4111",
		TransactionCurrency:         "156",
		CountryCode:                 "CN",
		MerchantName:                "BEST TRANSPORT",
		MerchantCity:                "BEIJING",
		PostalCode:                  "",
		AdditionalDataFieldTemplate: "030412340603***0708A60086670902ME",
		UnreservedTemplates: []tlv.TLV{
			{Tag: "80", Length: "36", Value: "003239401ff0c21a4543a8ed5fbaa30ab02e"},
		},
	}

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

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

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

}
Output:

&{PayloadFormatIndicator:01 PointOfInitiationMethod:12 MerchantAccountInformation:[] MerchantCategoryCode:4111 TransactionCurrency:156 TransactionAmount:{String: Valid:false} TipOrConvenienceIndicator: ValueOfConvenienceFeeFixed:{String: Valid:false} ValueOfConvenienceFeePercentage:{String: Valid:false} CountryCode:CN MerchantName:BEST TRANSPORT MerchantCity:BEIJING PostalCode: AdditionalDataFieldTemplate:030412340603***0708A60086670902ME MerchantInformation:{LanguagePreference: Name: City: Valid:false} UnreservedTemplates:[{Tag:80 Length:36 Value:003239401ff0c21a4543a8ed5fbaa30ab02e}]}

type NullMerchantInformation

type NullMerchantInformation struct {
	LanguagePreference string `emv:"00"`
	Name               string `emv:"01"`
	City               string `emv:"02"`
	Valid              bool
}

NullMerchantInformation represents Data Objects for Merchant Information—Language Template.

func (*NullMerchantInformation) Scan

func (m *NullMerchantInformation) Scan(token []rune) error

func (*NullMerchantInformation) Tokenize

func (m *NullMerchantInformation) Tokenize() (string, error)

Tokenize turns NullMerchantInformation into a string

type NullString

type NullString struct {
	String string
	Valid  bool
}

NullString represents a string that may be null.

func (*NullString) Scan

func (n *NullString) Scan(token []rune) error

func (*NullString) Tokenize

func (n *NullString) Tokenize() (string, error)

Tokenize turns NullString into a string

type PointOfInitiationMethod

type PointOfInitiationMethod string

PointOfInitiationMethod represents Data Objects for Point of Initiation Method.

const (
	PointOfInitiationMethodStatic  PointOfInitiationMethod = "11"
	PointOfInitiationMethodDynamic PointOfInitiationMethod = "12"
)

func (*PointOfInitiationMethod) Scan

func (p *PointOfInitiationMethod) Scan(token []rune) error

func (*PointOfInitiationMethod) Tokenize

func (p *PointOfInitiationMethod) Tokenize() (string, error)

Tokenize turns PointOfInitiationMethod into a string

type TipOrConvenienceIndicator

type TipOrConvenienceIndicator string

TipOrConvenienceIndicator represents Data Objects for Tip or Convenience Indicator.

const (
	TipOrConvenienceIndicatorPrompt     TipOrConvenienceIndicator = "01"
	TipOrConvenienceIndicatorFixed      TipOrConvenienceIndicator = "02"
	TipOrConvenienceIndicatorPercentage TipOrConvenienceIndicator = "03"
)

func (*TipOrConvenienceIndicator) Scan

func (t *TipOrConvenienceIndicator) Scan(token []rune) error

func (*TipOrConvenienceIndicator) Tokenize

func (t *TipOrConvenienceIndicator) Tokenize() (string, error)

Tokenize turns TipOrConvenienceIndicator into a string

type ValidatorFunc

type ValidatorFunc func(*Code) error

ValidatorFunc is an adapter for functions as validator.

Directories

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

Jump to

Keyboard shortcuts

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