dpo

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 10 Imported by: 1

README

Unofficial Go Library for DPO

Unofficial library for working with DPOs APIs for payment processing in Go applications.

NOTE: This is a work in progress and NOT production ready. The APIs are likely to change very frequently until we get to a v1. ymmv...

$ go get github.com/golang-malawi/go-dpo

Please check out the examples

LICENSE

MIT LICENSE


NNDI

Documentation

Overview

Package dpo provides functionality for interacting with DPO Group's payment gateway from Go applications. Currently the module only supports performing payments through DPOs verify token workflow.

Usage: User Agent

You are recommended to set the user agent for the client to some string that identifies your application.

clientToken := os.Getenv("DPO_TOKEN")
client := dpo.NewClient(clientToken, true)
client.SetUserAgent("Example User Agent")

Usage: Error Handling

The dpo package exposes errors that are thrown from DPO API.

Index

Constants

View Source
const (
	TransactionCharged     chargeTokenResponseCode = "000" // TransactionCharged Transaction charged
	TransactionAlreadyPaid chargeTokenResponseCode = "200" // TransactionAlreadyPaid Transaction alreadyp aid
	TokenMissing           chargeTokenResponseCode = "801" // TokenMissing Token missing
	InvalidToken           chargeTokenResponseCode = "802" // InvalidToken Invalid token
	MissingRequestOrName   chargeTokenResponseCode = "803" // MissingRequestOrName Missing request or name
	XMLError               chargeTokenResponseCode = "804" // XMLError Xml error
	DataMismatch           chargeTokenResponseCode = "902" // DataMismatch Data mismatch
	MissingMandatoryFields chargeTokenResponseCode = "950" // MissingMandatoryFields Missing mandatory fields
	TransactionDenied      chargeTokenResponseCode = "999" // TransactionDenied Transaction denied
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocation

type Allocation struct {
	AllocationID   string `xml:"AllocationID"`
	AllocationCode string `xml:"AllocationCode"`
}

Allocation an allocation as defined by DPO

type Allocations

type Allocations struct {
	Allocation Allocation `xml:"Allocation"`
}

Allocations collection of allocations

type CancelTokenRequest

type CancelTokenRequest struct {
	XMLName xml.Name `xml:"API3G"`

	CompanyToken string `xml:"CompanyToken"`
	Request      string `xml:"Request"`
	Token        string `xml:"TransactionToken"`
}

CancelTokenRequest represents a request to cancel a previously created token.

type CancelTokenResponse

type CancelTokenResponse struct {
	XMLName xml.Name `xml:"API3G"`

	Result            string `xml:"Result"`
	ResultExplanation string `xml:"ResultExplanation"`
}

CancelTokenResponse is the result of requesting a cancel token and depending on .Result may be an error or not.

type ChargeCreditCardRequest

type ChargeCreditCardRequest struct {
	XMLName xml.Name `xml:"API3G"`

	CompanyToken     string        `xml:"CompanyToken"`
	Request          string        `xml:"Request"`
	TransactionToken string        `xml:"TransactionToken"`
	CreditCardNumber string        `xml:"CreditCardNumber"`
	CreditCardExpiry string        `xml:"CreditCardExpiry"`
	CreditCardCVV    string        `xml:"CreditCardCVV"`
	CardHolderName   string        `xml:"CardHolderName"`
	ThreeD           ThreeDRequest `xml:"ThreeD"`
}

ChargeCreditCardRequest is a request to charge a users card directly.

type ChargeCreditCardResponse

type ChargeCreditCardResponse struct {
	XMLName xml.Name `xml:"API3G"`

	Result      string `xml:"Result"`
	Explanation string `xml:"ResultExplanation"`
	RedirectURL string `xml:"RedirectUrl,omitempty"`
	BackURL     string `xml:"BackUrl,omitempty"`
	DeclinedURL string `xml:"declinedUrl,omitempty"`
}

ChargeCreditCardResponse response returned from after processing a credit card charge directly.

func (*ChargeCreditCardResponse) IsError

func (c *ChargeCreditCardResponse) IsError() bool

IsError determines whether the card response is an error or not.

type ChargeTokenMobileRequest

type ChargeTokenMobileRequest struct {
	XMLName          xml.Name `xml:"API3G"`
	CompanyToken     string   `xml:"CompanyToken"`
	Request          string   `xml:"Request"`
	TransactionToken string   `xml:"TransactionToken"`
	PhoneNumber      string   `xml:"PhoneNumber"`
	MNO              string   `xml:"MNO"`
	MNOcountry       string   `xml:"MNOcountry"`
}

ChargeTokenMobileRequest is a request to charge a subscriber's mobile money directly.

type ChargeTokenMobileResponse

type ChargeTokenMobileResponse struct {
	XMLName        xml.Name `xml:"API3G"`
	Code           int      `xml:"Code"`
	Explanation    string   `xml:"Explanation"`
	RedirectURL    string   `xml:"RedirectUrl"`
	DeclinedURL    string   `xml:"declinedUrl"`
	Instructions   string   `xml:"Instructions"`
	RedirectOption int      `xml:"RedirectOption"`
}

ChargeTokenMobileResponse is a response from a ChargeTokenMobileRequest

type Client

type Client struct {
	Debug bool   // Determines whether to use test or live url
	Token string // Credentials key for the company

	UserAgent string

	GenerateRef func() string

	RedirectURL string // RedirectURL the url to redirect to when payment flow completes
	BackURL     string // BackURL is the url to redirect to when payment fails or is cancelled
	// contains filtered or unexported fields
}

Client struct represents a client and it's configuration for working with the DPO API. The client provides functions to initiate, verify, cancel and revoke payment tokens. The client uses a basic net/http http.Client.

func NewClient

func NewClient(companyToken string, debug bool) *Client

NewClient creates a new testing/debug client for 3G service companyToken the token to use for API calls debug whether to enable debug-mode or not - debug mode uses the test URLs instead of live URLs.

func NewDebugClient

func NewDebugClient(companyToken string) *Client

NewDebugClient creates a new Client that has debug set to true companyToken the token to use for API calls

func NewLiveClient

func NewLiveClient(companyToken string) *Client

NewLiveClient creates a new Client that has debug set to false companyToken the token to use for API calls

func (*Client) CancelToken

func (c *Client) CancelToken(tokenStr string) (*CancelTokenResponse, error)

CancelToken initiates token cancellations - NOT YET IMPLEMENTED

func (*Client) ChargeCreditCard

func (c *Client) ChargeCreditCard(cardHolder, cardNumber, cvv, cardExpiry string, token *CreateTokenResponse) (*ChargeCreditCardResponse, error)

ChargeCreditCard is used for charging a card directly. Do not use this yet.

func (*Client) CreateToken

func (c *Client) CreateToken(token *CreateTokenRequest) (*CreateTokenResponse, error)

CreateToken creates a token that can be used to perform payments. This is the first step in the payment flow with DPO Once the token is created it must be verified using client.VerifyToken

func (*Client) MakePaymentURL

func (c *Client) MakePaymentURL(token *CreateTokenResponse) string

MakePaymentURL creates a URL which should be passed to the User to redirect to the DPO system to complete the payment Requires a non-nil token created using client.CreateToken

func (*Client) NewCreateTokenRequest

func (c *Client) NewCreateTokenRequest(companyToken string, paymentCurrency string, amount *big.Float) *CreateTokenRequest

NewCreateTokenRequest creates a new token that can be used in client.VerifyToken calls

func (*Client) RefundToken

func (c *Client) RefundToken(tokenStr string, refundAmount *big.Float, refundRef, description string, requiresApproval bool) (*RefundTokenResponse, error)

RefundToken initiates token refunds - NOT YET IMPLEMENTED

func (*Client) SetBackURL

func (c *Client) SetBackURL(url string)

SetBackURL sets the back/cancel URL which is used for all requests that require a back url in most cases this can be overridden by using a similar function call on the request type

func (*Client) SetRedirectURL

func (c *Client) SetRedirectURL(url string)

SetRedirectURL sets the redirect URL which is used for all requests that require a redirect url in most cases this can be overridden by using a similar function call on the request type

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(userAgent string)

SetUserAgent sets the user agent to be used with all HTTP requests to the DPO API

func (*Client) VerifyToken

func (c *Client) VerifyToken(token *CreateTokenResponse) (*VerifyTokenResponse, error)

VerifyToken verifies the token with DPO site to prepare it for use for actual payment process

type CreateTokenRequest

type CreateTokenRequest struct {
	XMLName xml.Name `xml:"API3G"`

	CompanyToken string                 `xml:"CompanyToken"`
	Request      string                 `xml:"Request"`
	Transaction  CreateTokenTransaction `xml:"Transaction"`
	Services     []Service              `xml:"Services>Service"`
}

CreateTokenRequest is a request to create a token that will be used to process (i.e. initiate, complete, cancel, revoke) payments.

func (*CreateTokenRequest) AddService

func (c *CreateTokenRequest) AddService(typeCode, description string, serviceDate time.Time)

AddService adds a service to the CreateTokenRequests slice of services which indicates which services the payment will be made for.

func (*CreateTokenRequest) SetBackURL

func (c *CreateTokenRequest) SetBackURL(backURL string)

SetBackURL sets the URL that DPO will redirect to when user cancels the payment flow or an error occurs

func (*CreateTokenRequest) SetRedirectURL

func (c *CreateTokenRequest) SetRedirectURL(redirectURL string)

SetRedirectURL sets the URL that DPO will redirect to when user completes the payment flow

type CreateTokenResponse

type CreateTokenResponse struct {
	XMLName xml.Name `xml:"API3G"`

	Result            string      `xml:"Result"`
	ResultExplanation string      `xml:"ResultExplanation"`
	TransToken        string      `xml:"TransToken,omitempty"`
	TransRef          string      `xml:"TransRef,omitempty"`
	Allocations       Allocations `xml:"Allocations,omitempty"`
}

CreateTokenResponse is returned after processing a CreateTokenRequest and depending on the Result may be an error response or not

func (*CreateTokenResponse) IsError

func (c *CreateTokenResponse) IsError() bool

IsError determines whether the CreateTokenResponse is an error or not.

type CreateTokenTransaction

type CreateTokenTransaction struct {
	PaymentAmount    string `xml:"PaymentAmount"`
	PaymentCurrency  string `xml:"PaymentCurrency"`
	CompanyRef       string `xml:"CompanyRef"`
	RedirectURL      string `xml:"RedirectURL"`
	BackURL          string `xml:"BackURL"`
	CompanyRefUnique int    `xml:"CompanyRefUnique"`
	PTL              string `xml:"PTL"`
}

CreateTokenTransaction TODO: add docs

type RefundTokenRequest

type RefundTokenRequest struct {
	XMLName xml.Name `xml:"API3G"`

	CompanyToken   string    `xml:"CompanyToken"`
	Request        string    `xml:"Request"`
	Token          string    `xml:"TransactionToken"`
	RefundAmount   big.Float `xml:"refundAmount"`   // RefundAmount Requested refund amount. (Mandatory)
	RefundDetails  string    `xml:"refundDetails"`  // RefundDetails Requested refund description. (Mandatory)
	RefundRef      string    `xml:"refundRef"`      // refundRef Refund reference.	(Optional)
	RefundApproval int8      `xml:"refundApproval"` // refundApproval In case it being sent, refund will be checked by a checker (Optional)
}

RefundTokenRequest represents a request to initiate a refund

type RefundTokenResponse

type RefundTokenResponse struct {
	XMLName xml.Name `xml:"API3G"`

	Result            string `xml:"Result"`
	ResultExplanation string `xml:"ResultExplanation"`
}

RefundTokenResponse represents response from initiating a refund request.

type Service

type Service struct {
	ServiceType        string `xml:"ServiceType"`
	ServiceDescription string `xml:"ServiceDescription"`
	ServiceDate        string `xml:"ServiceDate"`
}

Service is a product or service that users can pay for through DPO

type ThreeDRequest

type ThreeDRequest struct {
	Enrolled    string `xml:"Enrolled"`
	Paresstatus string `xml:"Paresstatus"`
	Eci         string `xml:"Eci"`
	Xid         string `xml:"Xid"`
	Cavv        string `xml:"Cavv"`
	Signature   string `xml:"Signature"`
	Veres       string `xml:"Veres"`
	Pares       string `xml:"Pares"`
}

ThreeDRequest request data for 3D systems

type VerifyTokenRequest

type VerifyTokenRequest struct {
	XMLName xml.Name `xml:"API3G"`

	CompanyToken     string `xml:"CompanyToken"`
	TransactionToken string `xml:"TransactionToken"`
	Request          string `xml:"Request"`
}

VerifyTokenRequest is a request to verify a token that was requested as a CreateTokenRequest

type VerifyTokenResponse

type VerifyTokenResponse struct {
	XMLName xml.Name `xml:"API3G"`

	Result            string `xml:"Result"`
	ResultExplanation string `xml:"ResultExplanation"`
}

VerifyTokenResponse is returned after processing a VerifyTokenRequet and depending on the .Result may be an error response or not

Directories

Path Synopsis
examples
fiber Module

Jump to

Keyboard shortcuts

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