worldpay

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: MIT Imports: 9 Imported by: 0

README

worldpay-cnp

SCHEMA VERSION 11.4 - Go interface to the WorldPay cnpAPI

API

Client

func Authorization(c Context, authorization *Authorization) LitleOnlineResponse
func Capture(c Context, capture *Capture) LitleOnlineResponse
func RefundReversal(c Context, refundReversal *RefundReversal) LitleOnlineResponse
func Sale(c Context, sale *Sale) LitleOnlineResponse
func Void(c Context, void *Void) LitleOnlineResponse

LitleOnlineResponse

func HasError() bool
func Error() string

Usage

import (
    "context"
    "os"

    "github.com/anedot/worldpay-cnp"
)

func main() {
    client, _ := worldpay.NewClient(
        os.Getenv("WORLDPAY_LOGIN"),
        os.Getenv("WORLDPAY_PASSWORD"),
        os.Getenv("WORLDPAY_URL"),
        os.Getenv("WORLDPAY_MERCHANT_ID"),
    )

    ctx := context.Background()
    void := &worldpay.Void{
        Id:          "12345",
        ReportGroup: "report group",
        LitleTxnId:  "1234567890123456789",
    }

    client.Void(ctx, void)
}

Online Transactions

The wrapper currently only supports "online" transactions.

Authorization
func Authorization(c Context, authorization *Authorization) LitleOnlineResponse
&worldpay.Authorization{
    Id:          "834262",
    ReportGroup: "ABC Division",
    CustomerId:  "038945",
    OrderId:     "65347567",
    Amount:      40000,
    OrderSource: "3dsAuthenticated",
    BillToAddress: Address{
        Name:         "John Smith",
        AddressLine1: "100 Main St",
        City:         "Boston",
        Country:      "USA",
        State:        "MA",
        Zip:          "12345",
        Email:        "jsmith@someaddress.com",
        Phone:        "555-123-4567",
    },
    Card: Card{
        Type:              "VI",
        Number:            "4000000000000002",
        ExpDate:           "1209",
        CardValidationNum: "555",
    },
}
Capture
func Capture(c Context, capture *Capture) LitleOnlineResponse
&worldpay.Capture{
    Id:          "834262",
    ReportGroup: "ABC Division",
    CustomerId:  "038945",
    Partial:     false,
    LitleTxnId:  "13254123434",
    Amount:      5000,
}
Refund Reversal
func RefundReversal(c Context, refundReversal *RefundReversal) LitleOnlineResponse
&worldpay.RefundReversal{
    Id:          "12345",
    CustomerId:  "Customer Id",
    ReportGroup: "Refund Reversals",
    LitleTxnId:  "1234567890123456789",
    Card: Card{
        Type:              "GC",
        Number:            "1234102000003558",
        CardValidationNum: "888",
        ExpDate:           "1210",
    },
    OriginalRefCode:        "123456",
    OriginalAmount:         1900,
    OriginalTxnTime:        "2017-03-21T10:02:46",
    OriginalSystemTraceId:  "678901",
    OriginalSequenceNumber: "123456",
}
Sale
func Sale(c Context, sale *Sale) LitleOnlineResponse
&worldpay.Sale{
    Id:          "1",
    ReportGroup: "ABC Division",
    CustomerId:  "038945",
    OrderId:     "5234234",
    Amount:      40000,
    OrderSource: "3dsAuthenticated",
    BillToAddress: &Address{
        Name:         "John Smith",
        AddressLine1: "100 Main St",
        AddressLine2: "100 Main St",
        AddressLine3: "100 Main St",
        City:         "Boston",
        State:        "MA",
        Zip:          "12345",
        Country:      "US",
        Email:        "jsmith@someaddress.com",
        Phone:        "555-123-4567",
    },
    Card: &Card{
        Type:              "VI",
        Number:            "4005550000081019",
        ExpDate:           "1210",
        CardValidationNum: "555",
    },
}
Void
func Void(c Context, void *Void) LitleOnlineResponse
&worldpay.Void{
    Id:          "12345",
    ReportGroup: "report group",
    LitleTxnId:  "1234567890123456789",
}

Dev

Run tests
go test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Name         string `xml:"name"`
	AddressLine1 string `xml:"addressLine1"`
	AddressLine2 string `xml:"addressLine2"`
	AddressLine3 string `xml:"addressLine3"`
	City         string `xml:"city"`
	State        string `xml:"state"`
	Zip          string `xml:"zip"`
	Country      string `xml:"country"`
	Email        string `xml:"email"`
	Phone        string `xml:"phone"`
}

type Authentication

type Authentication struct {
	User     string `xml:"user"`
	Password string `xml:"password"`
}

type Authorization

type Authorization struct {
	XMLName                  xml.Name                  `xml:"authorization"`
	Id                       string                    `xml:"id,attr"`
	ReportGroup              string                    `xml:"reportGroup,attr"`
	CustomerId               string                    `xml:"customerId,attr"`
	OrderId                  string                    `xml:"orderId"`
	Amount                   int                       `xml:"amount"`
	OrderSource              string                    `xml:"orderSource"`
	BillToAddress            Address                   `xml:"billToAddress"`
	Card                     Card                      `xml:"card"`
	CardholderAuthentication *CardholderAuthentication `xml:"cardholderAuthentication"`
}

type AuthorizationResponse

type AuthorizationResponse struct {
	XMLName              xml.Name `xml:"authorizationResponse"`
	Id                   string   `xml:"id,attr"`
	ReportGroup          string   `xml:"reportGroup,attr"`
	CustomerId           string   `xml:"customerId,attr"`
	LitleTxnId           string   `xml:"litleTxnId"`
	OrderId              string   `xml:"orderId"`
	Response             string   `xml:"response"`
	ResponseTime         string   `xml:"responseTime"`
	PostDate             string   `xml:"postDate"`
	Message              string   `xml:"message"`
	AuthCode             string   `xml:"authCode"`
	ApprovedAmount       string   `xml:"approvedAmount"`
	NetworkTransactionId string   `xml:"networkTransactionId"`
}

type Capture

type Capture struct {
	XMLName      xml.Name      `xml:"capture"`
	Id           string        `xml:"id,attr"`
	ReportGroup  string        `xml:"reportGroup,attr"`
	CustomerId   string        `xml:"customerId,attr"`
	Partial      bool          `xml:"partial,attr"`
	LitleTxnId   string        `xml:"litleTxnId"`
	Amount       int           `xml:"amount"`
	EnhancedData *EnhancedData `xml:"enhancedData"`
}

type CaptureResponse

type CaptureResponse struct {
	XMLName      xml.Name `xml:"captureResponse"`
	Id           string   `xml:"id,attr"`
	ReportGroup  string   `xml:"reportGroup,attr"`
	CustomerId   string   `xml:"customerId,attr"`
	LitleTxnId   string   `xml:"litleTxnId"`
	Response     string   `xml:"response"`
	ResponseTime string   `xml:"responseTime"`
	PostDate     string   `xml:"postDate"`
	Message      string   `xml:"message"`
}

type Card

type Card struct {
	Type              string `xml:"type"`
	Number            string `xml:"number"`
	ExpDate           string `xml:"expDate"`
	CardValidationNum string `xml:"cardValidationNum"`
}

type CardholderAuthentication

type CardholderAuthentication struct {
	AuthenticationValue         string `xml:"authenticationValue"`
	AuthenticationTransactionId string `xml:"authenticationTransactionId"`
}

type Client

type Client struct {
	Client     *http.Client
	Login      string
	Password   string
	ApiBase    string
	MerchantId string
	Log        io.Writer
	// contains filtered or unexported fields
}

func NewClient

func NewClient(login, password, apiBase, merchantId string) (*Client, error)

func (*Client) Authorization added in v1.0.0

func (c *Client) Authorization(ctx context.Context, auth *Authorization) (*LitleOnlineResponse, error)

func (*Client) Capture added in v1.0.0

func (c *Client) Capture(ctx context.Context, capture *Capture) (*LitleOnlineResponse, error)

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, payload interface{}) (*http.Request, error)

func (*Client) RefundReversal added in v1.0.0

func (c *Client) RefundReversal(ctx context.Context, refundReversal *RefundReversal) (*LitleOnlineResponse, error)

func (*Client) Sale added in v1.0.0

func (c *Client) Sale(ctx context.Context, sale *Sale) (*LitleOnlineResponse, error)

func (*Client) Send

func (c *Client) Send(req *http.Request, v interface{}) error

func (*Client) SetLog

func (c *Client) SetLog(log io.Writer)

func (*Client) Void added in v1.0.0

func (c *Client) Void(ctx context.Context, void *Void) (*LitleOnlineResponse, error)

type CustomBilling

type CustomBilling struct {
	Phone      string `xml:"phone"`
	Descriptor string `xml:"descriptor"`
}

type DetailTax

type DetailTax struct {
	TaxIncludedInTotal bool   `xml:"taxIncludedInTotal"`
	TaxAmount          int    `xml:"taxAmount"`
	TaxRate            string `xml:"taxRate"`
	TaxTypeIdentifier  string `xml:"taxTypeIdentifier"`
	CardAcceptorTaxId  string `xml:"cardAcceptorTaxId"`
}

type EnhancedData

type EnhancedData struct {
	CustomerReference      string         `xml:"customerReference"`
	SalesTax               int            `xml:"salesTax"`
	TaxExempt              bool           `xml:"taxExempt"`
	DiscountAmount         int            `xml:"discountAmount"`
	ShippingAmount         int            `xml:"shippingAmount"`
	DutyAmount             int            `xml:"dutyAmount"`
	ShipFromPostalCode     string         `xml:"shipFromPostalCode"`
	DestinationPostalCode  string         `xml:"destinationPostalCode"`
	DestinationCountryCode string         `xml:"destinationCountryCode"`
	InvoiceReferenceNumber string         `xml:"invoiceReferenceNumber"`
	OrderDate              string         `xml:"orderDate"`
	DetailTax              DetailTax      `xml:"detailTax"`
	LineItemData           []LineItemData `xml:"lineItemData"`
}

type FraudResult

type FraudResult struct {
	AVSResult            string `xml:"avsResult"`
	CardValidationResult string `xml:"cardValidationResult"`
	AuthenticationResult string `xml:"authenticationResult"`
}

type LineItemData

type LineItemData struct {
	ItemSequenceNumber   int       `xml:"itemSequenceNumber"`
	ItemDescription      string    `xml:"itemDescription"`
	ProductCode          string    `xml:"productCode"`
	Quantity             int       `xml:"quantity"`
	UnitOfMeasure        string    `xml:"unitOfMeasure"`
	TaxAmount            int       `xml:"taxAmount"`
	LineItemTotal        int       `xml:"lineItemTotal"`
	LineItemTotalWithTax int       `xml:"lineItemTotalWithTax"`
	ItemDiscountAmount   int       `xml:"itemDiscountAmount"`
	CommodityCode        string    `xml:"commodityCode"`
	UnitCost             float64   `xml:"unitCost"`
	DetailTax            DetailTax `xml:"detailTax"`
}

type LitleOnlineRequest

type LitleOnlineRequest struct {
	XMLName        xml.Name        `xml:"litleOnlineRequest"`
	Version        string          `xml:"version,attr"`
	XmlNamespace   string          `xml:"xmlns,attr"`
	MerchantId     string          `xml:"merchantId,attr"`
	Authentication Authentication  `xml:"authentication"`
	Authorization  *Authorization  `xml:"authorization"`
	Capture        *Capture        `xml:"capture"`
	Sale           *Sale           `xml:"sale"`
	RefundReversal *RefundReversal `xml:"refundReversal"`
	Void           *Void           `xml:"void"`
}

type LitleOnlineResponse

type LitleOnlineResponse struct {
	XMLName                xml.Name                `xml:"litleOnlineResponse"`
	Version                string                  `xml:"version,attr"`
	XmlNS                  string                  `xml:"xmlns,attr"`
	Response               string                  `xml:"response,attr"`
	Message                string                  `xml:"message,attr"`
	AuthorizationResponse  *AuthorizationResponse  `xml:"authorizationResponse,omitempty"`
	CaptureResponse        *CaptureResponse        `xml:"captureResponse,omitempty"`
	SaleResponse           *SaleResponse           `xml:"saleResponse,omitempty"`
	RefundReversalResponse *RefundReversalResponse `xml:"refundReversalResponse,omitempty"`
	VoidResponse           *VoidResponse           `xml:"voidResponse,omitempty"`
}

func (*LitleOnlineResponse) Error

func (r *LitleOnlineResponse) Error() string

func (*LitleOnlineResponse) HasError

func (r *LitleOnlineResponse) HasError() bool

Error method implementation for ErrorResponse struct

type RefundReversal

type RefundReversal struct {
	XMLName                xml.Name `xml:"refundReversal"`
	Id                     string   `xml:"id,attr"`
	ReportGroup            string   `xml:"reportGroup,attr"`
	CustomerId             string   `xml:"customerId,attr"`
	LitleTxnId             string   `xml:"litleTxnId"`
	Card                   Card     `xml:"card"`
	OriginalRefCode        string   `xml:"originalRefCode"`
	OriginalAmount         float64  `xml:"originalAmount"`
	OriginalTxnTime        string   `xml:"originalTxnTime"`
	OriginalSystemTraceId  string   `xml:"originalSystemTraceId"`
	OriginalSequenceNumber string   `xml:"originalSequenceNumber"`
}

type RefundReversalResponse

type RefundReversalResponse struct {
	XMLName      xml.Name `xml:"refundReversalResponse"`
	Id           string   `xml:"id,attr"`
	ReportGroup  string   `xml:"reportGroup,attr"`
	CustomerId   string   `xml:"customerId,attr"`
	LitleTxnId   string   `xml:"litleTxnId"`
	Response     string   `xml:"response"`
	ResponseTime string   `xml:"responseTime"`
	PostDate     string   `xml:"postDate"`
	Message      string   `xml:"message"`
}

type Sale

type Sale struct {
	XMLName                  xml.Name                  `xml:"sale"`
	Id                       string                    `xml:"id,attr"`
	ReportGroup              string                    `xml:"reportGroup,attr"`
	CustomerId               string                    `xml:"customerId,attr"`
	OrderId                  string                    `xml:"orderId"`
	Amount                   int                       `xml:"amount"`
	OrderSource              string                    `xml:"orderSource"`
	BillToAddress            *Address                  `xml:"billToAddress"`
	Card                     *Card                     `xml:"card"`
	CardholderAuthentication *CardholderAuthentication `xml:"cardholderAuthentication"`
	CustomBilling            *CustomBilling            `xml:"customBilling"`
	EnhancedData             *EnhancedData             `xml:"enhancedData"`
}

type SaleResponse

type SaleResponse struct {
	XMLName      xml.Name     `xml:"saleResponse"`
	Id           string       `xml:"id,attr"`
	ReportGroup  string       `xml:"reportGroup,attr"`
	CustomerId   string       `xml:"customerId,attr"`
	LitleTxnId   string       `xml:"litleTxnId"`
	Response     string       `xml:"response"`
	OrderId      string       `xml:"orderId"`
	ResponseTime string       `xml:"responseTime"`
	PostDate     string       `xml:"postDate"`
	Message      string       `xml:"message"`
	AuthCode     string       `xml:"authCode"`
	FraudResult  *FraudResult `xml:"fraudResult"`
}

type Void

type Void struct {
	XMLName     xml.Name `xml:"void"`
	Id          string   `xml:"id,attr"`
	ReportGroup string   `xml:"reportGroup,attr"`
	LitleTxnId  string   `xml:"litleTxnId"`
}

type VoidResponse

type VoidResponse struct {
	XMLName      xml.Name `xml:"voidResponse"`
	Id           string   `xml:"id,attr"`
	ReportGroup  string   `xml:"reportGroup,attr"`
	LitleTxnId   string   `xml:"litleTxnId"`
	Response     string   `xml:"response"`
	ResponseTime string   `xml:"responseTime"`
	PostDate     string   `xml:"postDate"`
	Message      string   `xml:"message"`
}

Jump to

Keyboard shortcuts

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