gpay

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: 25 Imported by: 0

README

google-pay / paytokens

Go package for handle Google Pay tokens.

Usage

Install using :

go get github.com/nooize/paytokens.

Usage example :

 
import  "github.com/nooize/paytokens/google-pay"

...
	
  merchantId := "12345678901234567890"
  payToken := []byte("{ ... encrypted token ... }")
  
  decoder, err := gpay.New(
    merchantId,
    gpay.MerchantPrivateKeyLocation("private.pem"),
	gpay.TestMode(),
  )
  if err != nil {
	// handle error
  }
  
  decryptedToken, err := decoder.Decrypt(payToken)
  if err != nil {
    // handle error
  }

if you always decrypt with single merchant ID, you can use default decryptor.

To use default decryptor, simply define environment variable:

  • GOOGLE_PAY_MERCHANT_ID
  • GOOGLE_PAY_MERCHANT_PRIVATE_KEY

Usage with default decoder :


import  "github.com/nooize/paytokens"

...
	
  payToken := []byte("{ ... encrypted token ... }")
  
  decryptedToken, err := gpay.Decrypt(payToken)
  if err != nil {
   // handle error
  }

Manage root signed certificates

GOOGLE_PAY_ROOT_SIGNED_KEYS_FILE

Documentation

Index

Constants

View Source
const (
	EcV1            tokenProtocol = "ECv1"
	EcV2            tokenProtocol = "ECv2"
	EcV2SigningOnly tokenProtocol = "ECv2SigningOnly"
	GoogleSenderId                = "Google"
	Card            PaymentMethod = "CARD"
	TokenizedCard   PaymentMethod = "TOKENIZED_CARD"
	PanOnly         AuthMethod    = "PAN_ONLY"
	Cryptogram3ds   AuthMethod    = "CRYPTOGRAM_3DS"

	EnvMerchantId         = "GOOGLE_PAY_MERCHANT_ID"
	EnvMerchantPrivateKey = "GOOGLE_PAY_MERCHANT_PRIVATE_KEY"
	EnvRootSignedKetsFile = "GOOGLE_PAY_ROOT_SIGNED_KEYS_FILE"
)
View Source
const (
	TestRootKeysUrl       = "https://payments.developers.google.com/paymentmethodtoken/test/keys.json"
	ProductionRootKeysUrl = "https://payments.developers.google.com/paymentmethodtoken/keys.json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthMethod

type AuthMethod string

func (*AuthMethod) String

func (m *AuthMethod) String() string

func (*AuthMethod) UnmarshalJSON

func (m *AuthMethod) UnmarshalJSON(bytes []byte) error

type GooglePayToken

type GooglePayToken struct {
	MessageId           string        `json:"messageId"`
	MessageExpiration   string        `json:"messageExpiration"`
	PaymenMethod        PaymentMethod `json:"paymentMethod"`
	GatewayMerchantId   string        `json:"gatewayMerchantId,omitempty"`
	PaymenMethodDetails struct {
		AuthMethod      AuthMethod `json:"authMethod"`
		Pan             string     `json:"pan"`
		ExpirationMonth time.Month `json:"expirationMonth"`
		ExpirationYear  uint       `json:"expirationYear"`
		Cryptogram      string     `json:"cryptogram,omitempty"`
		EciIndicator    string     `json:"eciIndicator,omitempty"`
	} `json:"paymentMethodDetails"`
}

func Decrypt

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

func (*GooglePayToken) HasCryptogram

func (t *GooglePayToken) HasCryptogram() bool

type IGooglePayHandler

type IGooglePayHandler interface {
	Decrypt([]byte) (*GooglePayToken, error)
	MerchantId() string
}

IGooglePayHandler is the interface for Google Pay handlers

func New

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

New create new google pay handler instance with custom parameters

type IOption

type IOption func(*googlePayHandler) error

IOption is the interface option functions used when create new handler instance

func LiveMode added in v1.0.10

func LiveMode() IOption

LiveMode option func to define production mode for tokens

func MerchantPemPrivateKey

func MerchantPemPrivateKey(data []byte) IOption

MerchantPemPrivateKey option func to define merchant private key from pem encoded data

func MerchantPrivateKey

func MerchantPrivateKey(key *ecdsa.PrivateKey) IOption

MerchantPrivateKey option func to define merchant private key

func MerchantPrivateKeyLocation

func MerchantPrivateKeyLocation(path string) IOption

MerchantPrivateKeyLocation option func to define merchant private key from file

func TestMode added in v1.0.10

func TestMode() IOption

TestMode option func to define test mode for tokens

type PaymentMethod

type PaymentMethod string

func (*PaymentMethod) String

func (m *PaymentMethod) String() string

func (*PaymentMethod) UnmarshalJSON

func (m *PaymentMethod) UnmarshalJSON(bytes []byte) error

Jump to

Keyboard shortcuts

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