apay

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 28 Imported by: 0

README

paytokens

paytokens is a Go package for handle Google Pay and Apple Pay transactions.

Apple Pay token decryption depends on native libssl, so you need to install it before use this package. You may need to confogure your PKG_CONFIG_PATH to include OpenSSL.

Getting up and running with the example

Documentation

Index

Constants

View Source
const (
	RootCertificateUrl = "https://www.apple.com/certificateauthority/AppleRootCA-G3.cer"
)
View Source
const (
	// TransactionTimeWindow is the window of time, in minutes, where
	// transactions can fit to limit replay attacks
	TransactionTimeWindow = 5 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplePaySessionURL

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

func ParseApplePaySessionURL

func ParseApplePaySessionURL(str string) (*ApplePaySessionURL, error)

func (*ApplePaySessionURL) String

func (u *ApplePaySessionURL) String() string

func (*ApplePaySessionURL) UnmarshalJSON

func (u *ApplePaySessionURL) UnmarshalJSON(bytes []byte) error

func (*ApplePaySessionURL) Validate

func (u *ApplePaySessionURL) Validate() error

type ApplePayToken

type ApplePayToken struct {

	// ApplicationPrimaryAccountNumber is the device-specific account number of the card that funds this
	// transaction
	ApplicationPrimaryAccountNumber string `json:"applicationPrimaryAccountNumber"`

	// expirationDate is the card expiration date in the format YYMMDD
	// use ExpirationTime function to access the time.Time value
	ExpirationDate expirationDate `json:"applicationExpirationDate"`

	// CurrencyCode is the ISO 4217 numeric currency code, as a string to preserve leading zeros
	CurrencyCode string `json:"currencyCode"`

	// TransactionAmount is the value of the transaction
	TransactionAmount uint `json:"transactionAmount"`

	// CardholderName is the name on the card
	CardholderName string `json:"cardholderName,omitempty"`

	// DeviceManufacturerIdentifier is a hex-encoded device manufacturer identifier
	DeviceManufacturerIdentifier string `json:"deviceManufacturerIdentifier"`

	// PaymentDataType is either 3DSecure or, if using Apple Pay in China, EMV
	PaymentDataType string `json:"paymentDataType"`

	// PaymentData contains detailed payment data
	PaymentData struct {

		// OnlinePaymentCryptogram is the 3-D Secure cryptogram
		OnlinePaymentCryptogram string `json:"onlinePaymentCryptogram,omitempty"`

		// ECIIndicator is the Electronic Commerce Indicator for the status of 3-D Secure
		ECIIndicator string `json:",omitempty"`

		// EMVData is the output from the Secure Element
		EMVData []byte `json:",omitempty"`

		// EncryptedPINData is the PIN encrypted with the bank's key
		EncryptedPINData string `json:",omitempty"`
	}
}

ApplePayToken is the decrypted form of Response.Token.PaymentData.Data

func Decrypt

func Decrypt(data []byte) (*ApplePayToken, error)

func (*ApplePayToken) Cryptogram

func (t *ApplePayToken) Cryptogram() string

func (*ApplePayToken) ExpirationTime

func (t *ApplePayToken) ExpirationTime() time.Time

func (*ApplePayToken) HasCryptogram

func (t *ApplePayToken) HasCryptogram() bool

type IApplePayHandler

type IApplePayHandler interface {
	Decrypt([]byte) (*ApplePayToken, error)
	Session(ApplePaySessionURL, string, string) ([]byte, error)
	MerchantId() string
}

IApplePayHandler is the interface for Apple Pay handlers

func New

func New(merchantId string, options ...IOption) (IApplePayHandler, error)

type IOption

type IOption func(*applePayHandler) error

func MerchantCertificate

func MerchantCertificate(crt tls.Certificate) IOption

func MerchantCertificateLocation

func MerchantCertificateLocation(path string) IOption

func ProcessingCertificate

func ProcessingCertificate(crt tls.Certificate) IOption

func ProcessingCertificateLocation

func ProcessingCertificateLocation(path string) IOption

Jump to

Keyboard shortcuts

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