pawapay

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Pawapay

Pawapay client application written in Go

alt text

Usage

Install Package
go get github.com/Uchencho/pawapay
Documentation

Please see the docs for the most up-to-date documentation of the Pawapay API.

Pawapay
  • Sample Usage
package main

import (
	"log"
	"time"

	"github.com/Uchencho/pawapay"
)

func main() {
	cfg := pawapay.GetConfigFromEnvVars()
	cfg.AllowRequestLogging() // only for debugging, would not advise this for production.
	// Also not absolutely necessary because we store API annotations in the response returned

	/*
		You can also explicitly declare the config
		cfg := pawapay.Config{
				APIKey:      "key",
				BaseURL:     "url",
				LogRequest:  os.Getenv("env") == "production",
				LogResponse: strings.EqualFold(os.Getenv("env"), "production"),
			}
	*/

	service := pawapay.NewService(cfg)

	amt := pawapay.Amount{Currency: "GHS", Value: "500"}
	description := "sending money to all my children" // will be truncated to the first 22 char
	pn := pawapay.PhoneNumber{CountryCode: "233", Number: "704584739348"}

	allCorrespondentMappings, err := pawapay.GetAllCorrespondents()
	if err != nil {
		log.Fatal(err)
	}

	// each mapping, think country, have a number of correspondents, pick the one you are
        // trying to send money to.
	// Ideally you will take this as input and map to the correspondent of your choice
	correspondent := allCorrespondentMappings[0].Correspondents[0]
	req := pawapay.PayoutRequest{
		Amount:        amt,
		PhoneNumber:   pn,
		Description:   description,
		PayoutId:      "uniqueId",
		Correspondent: correspondent.Correspondent,
	}

	resp, err := service.CreatePayout(time.Now, req)
	if err != nil {
		log.Printf("something went wrong, we will confirm through their webhook")

		// even in error, depending on the error, you might have access to the annotation

		log.Printf("request failed with status code %v, response payload %s, error=%s",
			resp.Annotation.ResponseCode, resp.Annotation.ResponsePayload, err)
	}

	log.Printf("response: %+v", resp)
}


NOTE

You also have access to deposit and refund functionalities

Check the client directory to see a sample implementation and pawapay_test.go file to see sample tests

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIAnnotation

type APIAnnotation struct {
	URL             string `json:"url"`
	RequestPayload  string `json:"requestPayload"`
	ResponsePayload string `json:"responsePayload"`
	ResponseCode    int    `json:"responseCode"`
}

APIAnnotation is a representation of provider api request and response

type Address

type Address struct {
	Value string `json:"value"`
}

type Amount

type Amount struct {
	Value    string `json:"value"`
	Currency string `json:"currency"`
}

type Config

type Config struct {
	BaseURL     string
	APIKey      string
	LogRequest  bool
	LogResponse bool
}

Config represents the pawapay config

func GetConfigFromEnvVars

func GetConfigFromEnvVars() Config

GetConfigFromEnvVars returns config configurations from environment variables

func (*Config) AllowLogging

func (c *Config) AllowLogging()

functionality to allow the package log request and responses

func (*Config) AllowRequestLogging

func (c *Config) AllowRequestLogging()

functionality to allow you log request payload. This is only necessary for debugging as all response objects return the api annotation giving all the required details of the request

func (*Config) AllowResponseLogging

func (c *Config) AllowResponseLogging()

functionality to allow you log response payload. This is only necessary for debugging as all response objects return the api annotation giving all the required details of the request

type ConfigProvider

type ConfigProvider func() Config

ConfigProvider pawapay config provider

type Correspondent

type Correspondent struct {
	Correspondent  string          `json:"correspondent"`
	OperationTypes []OperationType `json:"operationTypes"`
}

type CreateBulkDepositResponse

type CreateBulkDepositResponse struct {
	Result     []CreateDepositResponse
	Annotation APIAnnotation
}

type CreateBulkPayoutResponse

type CreateBulkPayoutResponse struct {
	Result     []CreatePayoutResponse
	Annotation APIAnnotation
}

type CreateDepositRequest

type CreateDepositRequest struct {
	DepositId            string `json:"depositId"`
	Amount               string `json:"amount"`
	Currency             string `json:"currency"`
	Country              string `json:"country"`
	Correspondent        string `json:"correspondent"`
	Payer                Payer  `json:"payer"`
	CustomerTimestamp    string `json:"customerTimestamp"`
	StatementDescription string `json:"statementDescription"`
	PreAuthorizationCode string `json:"preAuthorisationCode"`
}

type CreateDepositResponse

type CreateDepositResponse struct {
	DepositId  string `json:"depositId"`
	Status     string `json:"status"`
	Created    string `json:"created"`
	Annotation APIAnnotation
}

type CreatePayoutRequest

type CreatePayoutRequest struct {
	PayoutId             string    `json:"payoutId"`
	Amount               string    `json:"amount"`
	Currency             string    `json:"currency"`
	Country              string    `json:"country"`
	Correspondent        string    `json:"correspondent"`
	Recipient            Recipient `json:"recipient"`
	CustomerTimestamp    string    `json:"customerTimestamp"`
	StatementDescription string    `json:"statementDescription"`
}

type CreatePayoutResponse

type CreatePayoutResponse struct {
	PayoutID   string `json:"payoutId"`
	Status     string `json:"status"`
	Created    string `json:"created"`
	Annotation APIAnnotation
}

type Deposit

type Deposit struct {
	DepositId            string                 `json:"depositId"`
	Status               string                 `json:"status"`
	RequestedAmount      string                 `json:"requestedAmount"`
	DepositedAmount      string                 `json:"depositedAmount"`
	Currency             string                 `json:"currency"`
	Country              string                 `json:"country"`
	Payer                Payer                  `json:"payer"`
	Correspondent        string                 `json:"correspondent"`
	StatementDescription string                 `json:"statementDescription"`
	CustomerTimestamp    string                 `json:"customerTimestamp"`
	Created              string                 `json:"created"`
	RespondedByPayer     string                 `json:"respondedByPayer"`
	CorrespondentIds     map[string]interface{} `json:"correspondentIds"`
	SuspiciousActivity   map[string]interface{} `json:"suspiciousActivityReport"`
	FailureReason        FailureReason          `json:"failureReason"`
	Annotation           APIAnnotation
}

type DepositRequest

type DepositRequest struct {
	DepositId     string
	Amount        Amount
	Description   string
	PhoneNumber   PhoneNumber
	Correspondent string
	PreAuthCode   string
}

type DepositStatusResponse

type DepositStatusResponse struct {
	DepositId  string `json:"depositId"`
	Status     string `json:"status"`
	Annotation APIAnnotation
}

type FailureReason

type FailureReason struct {
	FailureCode    string `json:"failureCode"`
	FailureMessage string `json:"failureMessage"`
}

type InitiateRefundResponse

type InitiateRefundResponse struct {
	RefundId   string `json:"depositId"`
	Status     string `json:"status"`
	Created    string `json:"created"`
	Annotation APIAnnotation
}

type MomoMapping

type MomoMapping struct {
	Country        string          `json:"country"`
	Extension      string          `json:"extension"`
	Correspondents []Correspondent `json:"correspondents"`
}

func GetAllCorrespondents

func GetAllCorrespondents() ([]MomoMapping, error)

type OperationType

type OperationType struct {
	OperationType string `json:"operationType"`
	Status        string `json:"status"`
}

type Payer

type Payer struct {
	Type    string  `json:"type"`
	Address Address `json:"address"`
}

type Payout

type Payout struct {
	Amount               string                 `json:"amount"`
	Correspondent        string                 `json:"correspondent"`
	CorrespondentIds     map[string]interface{} `json:"correspondentIds"`
	Country              string                 `json:"country"`
	Created              string                 `json:"created"`
	Currency             string                 `json:"currency"`
	CustomerTimestamp    string                 `json:"customerTimestamp"`
	PayoutID             string                 `json:"payoutId"`
	Recipient            Recipient              `json:"recipient"`
	StatementDescription string                 `json:"statementDescription"`
	Status               string                 `json:"status"`
	FailureReason        FailureReason          `json:"failureReason"`
	Annotation           APIAnnotation
}

func (Payout) IsFailed

func (t Payout) IsFailed() bool

IsFailed reports if a payout failed

func (Payout) IsNotFound

func (t Payout) IsNotFound() bool

IsNotFound checks a payout response to see if the transaction is not found

func (Payout) IsPending

func (t Payout) IsPending() bool

IsPending reports if a payout is still pending

func (Payout) IsSuccessful

func (t Payout) IsSuccessful() bool

IsSuccessful reports if a payout is successful

type PayoutRequest

type PayoutRequest struct {
	PayoutId      string
	Amount        Amount
	Description   string
	PhoneNumber   PhoneNumber
	Correspondent string
}

type PayoutStatusResponse

type PayoutStatusResponse struct {
	PayoutId   string `json:"payoutId"`
	Status     string `json:"status"`
	Annotation APIAnnotation
}

type PhoneNumber

type PhoneNumber struct {
	CountryCode string `json:"countryCode"`
	Number      string `json:"number"`
}

PhoneNumber holds country code and number, eg countryCode:234, number: 7017238745

type Recipient

type Recipient struct {
	Type    string  `json:"type"`
	Address Address `json:"address"`
}

type Refund

type Refund struct {
	RefundId             string                 `json:"refundId"`
	Status               string                 `json:"status"`
	Amount               string                 `json:"amount"`
	Currency             string                 `json:"currency"`
	Country              string                 `json:"country"`
	Recipient            Recipient              `json:"recipient"`
	Correspondent        string                 `json:"correspondent"`
	StatementDescription string                 `json:"statementDescription"`
	CustomerTimestamp    string                 `json:"customerTimestamp"`
	Created              string                 `json:"created"`
	ReceivedByRecipient  string                 `json:"receivedByRecipient"`
	CorrespondentIds     map[string]interface{} `json:"correspondentIds"`
	FailureReason        FailureReason          `json:"failureReason"`
	Annotation           APIAnnotation
}

type RefundRequest

type RefundRequest struct {
	RefundId  string `json:"refundId"`
	DepositId string `json:"depositId"`
	Amount    string `json:"amount"`
}

type RefundStatusResponse

type RefundStatusResponse struct {
	RefundId   string `json:"refundId"`
	Status     string `json:"status"`
	Annotation APIAnnotation
}

type ResendCallbackRequest

type ResendCallbackRequest struct {
	PayoutId  string `json:"payoutId,omitempty"`
	DepositId string `json:"depositId,omitempty"`
	RefundId  string `json:"refundId,omitempty"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is a representation of a pawapay service

func NewService

func NewService(c Config) Service

NewService returns a new pawapay service

func (*Service) CreateBulkPayout

func (s *Service) CreateBulkPayout(timeProvider TimeProviderFunc, data []PayoutRequest) (CreateBulkPayoutResponse, error)

CreateBulkPayout provides the functionality of creating a bulk payout See docs https://docs.pawapay.co.uk/#operation/createPayout for more details

func (*Service) CreatePayout

func (s *Service) CreatePayout(timeProvider TimeProviderFunc, payoutReq PayoutRequest) (CreatePayoutResponse, error)

CreatePayout provides the functionality of creating a payout See docs https://docs.pawapay.co.uk/#operation/createPayout for more details

func (*Service) FailEnqueued

func (s *Service) FailEnqueued(payoutId string) (PayoutStatusResponse, error)

FailEnqueued provides the functionality of failing an already created payout See docs https://docs.pawapay.co.uk/#operation/payoutsFailEnqueued for more details

func (*Service) GetDeposit

func (s *Service) GetDeposit(depositId string) (Deposit, error)

GetDeposit provides the functionality of retrieving a deposit See docs https://docs.pawapay.co.uk/#operation/getDeposit for more details

func (*Service) GetPayout

func (s *Service) GetPayout(payoutId string) (Payout, error)

GetPayout provides the functionality of retrieving a payout See docs https://docs.pawapay.co.uk/#operation/getPayout for more details

func (*Service) GetRefund

func (s *Service) GetRefund(refundId string) (Refund, error)

GetRefund provides the functionality of retrieving an initiated refund See docs https://docs.pawapay.co.uk/#operation/getRefund for more details

func (*Service) InitiateBulkDeposit

func (s *Service) InitiateBulkDeposit(timeProvider TimeProviderFunc, data []DepositRequest) (CreateBulkDepositResponse, error)

CreateBulkDeposit provides the functionality of creating a bulk deposit See docs https://docs.pawapay.co.uk/#operation/createDeposits for more details

func (*Service) InitiateDeposit

func (s *Service) InitiateDeposit(timeProvider TimeProviderFunc, depositReq DepositRequest) (CreateDepositResponse, error)

InitiateDeposit provides the functionality of initiating a deposit for the sender to confirm See docs https://docs.pawapay.co.uk/#operation/createDesposit for more details

func (*Service) RequestRefund

func (s *Service) RequestRefund(refundId, depositId string, amount Amount) (InitiateRefundResponse, error)

RequestRefund provides the functionality of requesting a refund for an initiated deposit See docs https://docs.pawapay.co.uk/#operation/depositWebhook for more details

func (*Service) ResendDepositCallback

func (s *Service) ResendDepositCallback(depositId string) (DepositStatusResponse, error)

ResendDepositCallback provides the functionality of resending a callback (webhook) for a deposit See docs https://docs.pawapay.co.uk/#operation/depositsResendCallback for more details

func (*Service) ResendPayoutCallback

func (s *Service) ResendPayoutCallback(payoutId string) (PayoutStatusResponse, error)

ResendPayoutCallback provides the functionality of resending a callback (webhook) See docs https://docs.pawapay.co.uk/#operation/payoutsResendCallback for more details

func (*Service) ResendRefundCallback

func (s *Service) ResendRefundCallback(refundId string) (RefundStatusResponse, error)

ResendRefundCallback provides the functionality of resending a callback (webhook) See docs https://docs.pawapay.co.uk/#operation/refundsResendCallback for more details

type TimeProviderFunc

type TimeProviderFunc func() time.Time

TimeProviderFunc represents a provider of time

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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