Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateReference(prefix string) string
- type AUD
- type Client
- func (c *Client) DoPurchase(ctx context.Context, purchase *PurchaseRequest) (*Purchase, error)
- func (c *Client) GetPurchaseByReference(ctx context.Context, ref string) (*Purchase, error)
- func (c *Client) GetTokenizeHash(redirectURL string) string
- func (c *Client) GetTokenizedCard(ctx context.Context, token string) (*TokenizedCard, error)
- func (c *Client) ParseDirectTokenizeResult(req *http.Request) (*DirectTokenizeResult, error)
- type ClientOpts
- type DirectTokenizeResult
- type Purchase
- type PurchaseRequest
- type TokenizeCode
- type TokenizedCard
- type Transport
- type UnknownError
- type ValidationError
Constants ¶
const ( SandboxEndpoint = "gateway.pmnts-sandbox.io" ProductionEndpoint = "gateway.pmnts.io" )
Endpoints provided for convenience.
Variables ¶
var ( ErrBadHash = errors.New("fatzebra: bad hash") ErrNotFound = errors.New("fatzebra: not found") )
Possible errors returned.
var (
ErrExceedsMaximum = errors.New("fatzebra: transaction exceeds " +
"maximum allowable")
)
Possible errors returned by DoPurchase.
Functions ¶
func GenerateReference ¶
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).
Types ¶
type AUD ¶
type AUD int64
AUD represents the Australian dollars currency.
func NewAUDFromCents ¶
NewAUDFromCents returns the currency representation from a given number of cents.
func NewAUDFromDollars ¶
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) 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 ¶
MarshalJSON implements the JSON marshaller interface.
func (AUD) String ¶
String returns a human readable string representatin of the currency, like $12.34, $0.40, or $1500.00
func (*AUD) UnmarshalJSON ¶
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 ¶
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 ¶
GetPurchaseByReference retrieves a purchase by its reference code.
func (*Client) GetTokenizeHash ¶
GetTokenizeHash returns the hash that is to be sent by the user to redirect them to the given URL.
func (*Client) GetTokenizedCard ¶
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.
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 ¶
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.