package module
v0.0.0-...-eab833e Latest Latest

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

Go to latest
Published: Aug 16, 2021 License: MIT Imports: 16 Imported by: 0




View Source
const (
	SandboxEndpoint    = "gateway.pmnts-sandbox.io"
	ProductionEndpoint = "gateway.pmnts.io"

Endpoints provided for convenience.


View Source
var (
	ErrBadHash  = errors.New("fatzebra: bad hash")
	ErrNotFound = errors.New("fatzebra: not found")

Possible errors returned.

View Source
var (
	ErrExceedsMaximum = errors.New("fatzebra: transaction exceeds " +
		"maximum allowable")

Possible errors returned by DoPurchase.


func GenerateReference

func GenerateReference(prefix string) string

GenerateReference generates a random reference code, with a very very very small chance of collision. A prefix is recommended for customer support reasons. For instance, a person mistakes your company for another, they contact the wrong company. It makes it easier to tell that they're contacting the wrong company if the reference code is missing the prefix).


type AUD

type AUD int64

AUD represents the Australian dollars currency.

func NewAUDFromCents

func NewAUDFromCents(cents int64) AUD

NewAUDFromCents returns the currency representation from a given number of cents.

func NewAUDFromDollars

func NewAUDFromDollars(dollars float64) AUD

NewAUDFromDollars returns AUD using the given amount of dollars that are float64. WARNING: You shouldn't be performing any form of arithmetic or transformation with currency in float form.

func (AUD) Cents

func (a AUD) Cents() int64

Cents returns the number of cents the currency represents.

func (AUD) Float64

func (a AUD) Float64() float64

Float64 returns the number of dollars the currency represents as a float. WARNING: You shouldn't be performing any form of arithmetic or transformation with currency in float form.

func (AUD) MarshalJSON

func (a AUD) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON marshaller interface.

func (AUD) String

func (a AUD) String() string

String returns a human readable string representatin of the currency, like $12.34, $0.40, or $1500.00

func (*AUD) UnmarshalJSON

func (a *AUD) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the JSON unmarshaller interface.

type Client

type Client struct {
	// contains filtered or unexported fields

Client represents a client.

func NewClient

func NewClient(opts *ClientOpts) *Client

NewClient returns a new client with the given options.

func (*Client) DoPurchase

func (c *Client) DoPurchase(ctx context.Context,
	purchase *PurchaseRequest) (*Purchase, error)

DoPurchase issues a purchase with a tokenized card. Note that no error is returned if the authorization is rejected, check the response instead. Capture must be set to true for a purchase rather than a hold. Note that purchases with validation errors are not recorded in the transaction history.

func (*Client) GetPurchaseByReference

func (c *Client) GetPurchaseByReference(ctx context.Context,
	ref string) (*Purchase, error)

GetPurchaseByReference retrieves a purchase by its reference code.

func (*Client) GetTokenizeHash

func (c *Client) GetTokenizeHash(redirectURL string) string

GetTokenizeHash returns the hash that is to be sent by the user to redirect them to the given URL.

func (*Client) GetTokenizedCard

func (c *Client) GetTokenizedCard(ctx context.Context,
	token string) (*TokenizedCard, error)

GetTokenizedCard returns a tokenized card given its token.

func (*Client) ParseDirectTokenizeResult

func (c *Client) ParseDirectTokenizeResult(
	req *http.Request) (*DirectTokenizeResult, error)

ParseDirectTokenizeResult parses and validates the direct tokenize result received as a request. Details such as the card number, card holder and expiry date are not provided as they're not validated, and thus should not be trusted.

type ClientOpts

type ClientOpts struct {
	Username  string
	Password  string
	Secret    string
	Host      string
	MaxAmount AUD // Provides last chance protection against charging
	// unintentionally large amounts in a single transaction.
	Client *http.Client

ClientOpts represents the options usd to construct a Fat Zebra client.

type DirectTokenizeResult

type DirectTokenizeResult struct {
	TokenizeCode     TokenizeCode `json:"r"`
	CardToken        string       `json:"token"`
	VerificationCode string       `json:"v"`
	Errors           []string     `json:"errors[]"`

DirectTokenizeResult represents the result of a direct tokenize request.

func (*DirectTokenizeResult) Validate

func (d *DirectTokenizeResult) Validate(c *Client) error

Validate returns the validation result of the given verification code.

type Purchase

type Purchase struct {
	Authorization   string    `json:"authorization"`
	ID              string    `json:"id"`
	CardNumber      string    `json:"card_number"`
	CardHolder      string    `json:"card_holder"`
	CardExpiry      string    `json:"card_expiry"`
	CardToken       string    `json:"card_token"`
	CardType        string    `json:"card_type"`
	CardCategory    string    `json:"card_category"`
	CardSubcategory string    `json:"card_subcategory"`
	Amount          AUD       `json:"amount"`
	Successful      bool      `json:"successful"`
	Message         string    `json:"message"`
	Reference       string    `json:"reference"`
	Currency        string    `json:"currency"`
	TransactionID   string    `json:"transaction_id"`
	SettlementDate  string    `json:"settlement_date"`
	TransactionDate time.Time `json:"transaction_date"`
	ResponseCode    string    `json:"response_code"`
	Captured        bool      `json:"captured"`
	CapturedAmount  int       `json:"captured_amount"`
	RRN             string    `json:"rrn"`
	CVVMatch        string    `json:"cvv_match"`

Purchase represents a purchase.

type PurchaseRequest

type PurchaseRequest struct {
	CardToken  string `json:"card_token,omitempty"`
	CVV        string `json:"cvv,omitempty"`
	Amount     AUD    `json:"amount"`
	Reference  string `json:"reference"`
	Capture    bool   `json:"capture"`
	CustomerIP string `json:"customer_ip"` // Yes, this is required.

PurchaseRequest represents a tokenized card purchase.

type TokenizeCode

type TokenizeCode int

TokenizeCode represents a tokenize return code.

const (
	TokenizeSuccessful          TokenizeCode = 1
	TokenizeValidationError     TokenizeCode = 97
	TokenizeInvalidVerification TokenizeCode = 99
	TokenizeGatewayError        TokenizeCode = 999

Valid tokenize return codes.

func (TokenizeCode) String

func (c TokenizeCode) String() string

String returns a string representation of a tokenize return code.

func (*TokenizeCode) UnmarshalJSON

func (t *TokenizeCode) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the tokenize response code from JSON.

type TokenizedCard

type TokenizedCard struct {
	Token            string `json:"token"`
	CardHolder       string `json:"card_holder"`
	CardNumber       string `json:"card_number"`
	CardExpiry       string `json:"card_expiry"`
	CardType         string `json:"card_type"`
	CardCategory     string `json:"card_category"`
	CardSubcategory  string `json:"card_subcategory"`
	CardIssuer       string `json:"card_issuer"`
	CardCountry      string `json:"card_country"`
	Authorized       bool   `json:"authorized"`
	TransactionCount int    `json:"transaction_count"`

TokenizedCard represents a tokenized card.

type Transport

type Transport struct {
	// contains filtered or unexported fields

Transport represents the transport that injects credentials.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements round trips as required by http.RoundTrippr

type UnknownError

type UnknownError struct {
	Underlying error

UnknownError represents an unknown error, you should assume that the the payment could have succeeded.

func (*UnknownError) Error

func (e *UnknownError) Error() string

type ValidationError

type ValidationError struct {
	Reference  string
	Errors     []string
	StatusCode int

ValidationError represents a purchase validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface.

func (*ValidationError) Zap

func (e *ValidationError) Zap(l *zap.SugaredLogger)

Zap logs the information in the error response to a zap logger.

Jump to

Keyboard shortcuts

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