client

package module
v0.0.0-...-650de5f Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

Selcompay Go Client

CircleCI Go Report Card go.mod Go version

Description

This Module provides functionality developed to simplify interfacing with SelcomPay API in Go.

Requirements

To access the API, contact SelcomPay

Usage
package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	client "github.com/Golang-Tanzania/selcompay-client"
)

func main() {
	if err := run(); err != nil {
		log.Fatalln(err)
	}
}

func run() error {
	host := "https://apigw.selcommobile.com"
	apiKey := os.Getenv("SELCOM_API_KEY")
    	apiSecret := os.Getenv("SELCOM_SECRET_KEY")

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	logger := func(ctx context.Context, msg string, v ...any) {
		s := fmt.Sprintf("msg: %s", msg)
		for i := 0; i < len(v); i = i + 2 {
			s = s + fmt.Sprintf(", %s: %v", v[i], v[i+1])
		}
		log.Println(s)
	}

	cln := client.New(logger, host, apiKey, apiSecret)

	body := client.OrderInputMinimal{
		Vendor:      "TILLXXXXXX",
		ID:          uuid.NewString(),
		BuyerEmail:  "example@gmail.com",
		BuyerName:   "Joseph",
		BuyerPhone:  "255XXXXXXXXX",
		Amount:      1000,
		Webhook:     "https://link.com/service",
		Currency:    "TZS",
		NumberItems: 1,
	}

	resp, err := cln.CreateOrderMinimal(ctx, body)
	if err != nil {
		return "", err
	}

	fmt.Println(resp)

	return nil
}

Documentation

Overview

Package client provides support to access the Selcom Pay API service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithClient

func WithClient(http *http.Client) func(cln *Client)

WithClient adds a custom client for processing requests. It's recommend to not use the default client and provide your own.

Types

type CardPaymentInput

type CardPaymentInput struct {
	TransactionID    string `json:"transid"`
	Vendor           string `json:"vendor"`
	OrderID          string `json:"order_id"`
	CardToken        string `json:"card_token"`
	BuyerUserID      string `json:"buyer_userid"`
	GatewayBuyerUUID string `json:"gateway_buyer_uuid"`
}

type Client

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

Client represents a client that can talk to the selcompay API service.

func New

func New(logger Logger, host string, apiKey string, apiSecret string, options ...func(cln *Client)) *Client

New constructs a client that can be used to talk to the selcompay api.

func (*Client) CancelOrder

func (cln *Client) CancelOrder(ctx context.Context, orderID string) (Response, error)

CancelOrder Cancels an order before customer completes the payment.

func (*Client) CardPayment

func (cln *Client) CardPayment(ctx context.Context, cardPaymentInput CardPaymentInput) (Response, error)

CardPayment allows the ecommerce website to process an order using stored cards directly without redirecting the user to payment gateway page.

func (*Client) CheckOrder

func (cln *Client) CheckOrder(ctx context.Context, orderID string) (Response, error)

CheckOrder returns status of the order.

func (*Client) CreateOrder

func (cln *Client) CreateOrder(ctx context.Context, order OrderInput) (Response, error)

CreateOrder creates a payment order request to the selcom payment gateway. Responds with the payment url, buyer details.

func (*Client) CreateOrderMinimal

func (cln *Client) CreateOrderMinimal(ctx context.Context, order OrderInputMinimal) (Response, error)

CreateOrderMinimal creates a payment order request to the selcom payment gateway. This is for non-card payments. Ideal for mobile wallet push payments and manual payments.

func (*Client) DeleteStoredCard

func (cln *Client) DeleteStoredCard(ctx context.Context, cardResourceID string, gatewayBuyerUUID string) (Response, error)

DeleteStoredCard deletes the provided billing card informations.

func (*Client) FetchStoredCards

func (cln *Client) FetchStoredCards(ctx context.Context, buyerUserID string, gatewayBuyerUUID string) (Response, error)

FetchStoredCards retursn the stored billing cards for the provided buyer. The gatewayBuyerUUID is generated for each user on their first order creation.

func (*Client) Orders

func (cln *Client) Orders(ctx context.Context, startDate string, endDate string) (Response, error)

Orders returns a list of orders, satisfying the startDate and endDate params.

func (*Client) UtilityLookup

func (cln *Client) UtilityLookup(ctx context.Context, utilityCode, utilityRef, transactionID string) (Response, error)

func (*Client) UtilityPayment

func (cln *Client) UtilityPayment(ctx context.Context, body UtilityPaymentInput) (Response, error)

UtilityPayment process payment for a particular payment service.

func (*Client) UtilityPaymentStatus

func (cln *Client) UtilityPaymentStatus(ctx context.Context, trasactionID string) (Response, error)

UtilityPaymentStatus checks ths status of the utility payment.

func (*Client) WalletPayment

func (cln *Client) WalletPayment(ctx context.Context, transactionID string, orderID string, phone string) (Response, error)

WalletPayment api allows the ecommerce website to process an order using mobile wallets directly. trigger this api call to reiceve a PUSH ussd.

type Error

type Error struct {
	TransactionID string           `json:"transid"`
	Reference     string           `json:"reference"`
	ResultCode    string           `json:"resultcode"`
	Result        string           `json:"result"`
	Message       string           `json:"message"`
	Data          []map[string]any `json:"data"`
	// contains filtered or unexported fields
}

func (Error) Error

func (re Error) Error() string

Error is the implementation of the error interface.

type Logger

type Logger func(context.Context, string, ...any)

Logger represents a function that will be called to add information to the user's application logs.

type OrderInput

type OrderInput struct {
	Vendor                string `json:"vendor"`
	ID                    string `json:"order_id"`
	BuyerEmail            string `json:"buyer_email"`
	BuyerName             string `json:"buyer_name"`
	BuyerUserID           string `json:"buyer_userid,omitempty"`
	BuyerPhone            string `json:"buyer_phone"`
	GatewayBuyerUUID      string `json:"gateway_buyer_uuid"`
	Amount                int    `json:"amount"`
	Currency              string `json:"currency"`
	PaymentMethods        string `json:"payment_methods"`
	RedirectURL           string `json:"redirect_url,omitempty"`
	CancelURL             string `json:"cancel_url,omitempty"`
	Webhook               string `json:"webhook,omitempty"`
	BillingFirstName      string `json:"billing.firstname"`
	BillingLastName       string `json:"billing.lastname"`
	BillingAddress1       string `json:"billing.address_1"`
	BillingAddress2       string `json:"billing.address_2,omitempty"`
	BillingCity           string `json:"billing.city"`
	BillingStateRegion    string `json:"billing.state_or_region"`
	BillingPostCodePOBox  string `json:"billing.postcode_or_pobox"`
	BillingCountry        string `json:"billing.country"`
	BillingPhone          string `json:"billing.phone"`
	ShippingFirstName     string `json:"shipping.firstname,omitempty"`
	ShippingLastName      string `json:"shipping.lastname,omitempty"`
	ShippingAddress1      string `json:"shipping.address_1,omitempty"`
	ShippingAddress2      string `json:"shipping.address_2,omitempty"`
	ShippingCity          string `json:"shipping.city,omitempty"`
	ShippingStateRegion   string `json:"shipping.state_or_region,omitempty"`
	ShippingPostCodePOBox string `json:"shipping.postcode_or_pobox,omitempty"`
	ShippingCountry       string `json:"shipping.country,omitempty"`
	ShippingPhone         string `json:"shipping.phone,omitempty"`
	BuyerRemarks          string `json:"buyer_remarks,omitempty"`
	MerchantRemarks       string `json:"merchant_remarks,omitempty"`
	NumberItems           int    `json:"no_of_items,omitempty"`
	HeaderColour          string `json:"header_colour,omitempty"`
	LinkColour            string `json:"link_colour,omitempty"`
	ButtonColour          string `json:"button_colour,omitempty"`
	Expiry                int    `json:"expiry,omitempty"`
}

OrderInput represents the input for the checkout order call.

type OrderInputMinimal

type OrderInputMinimal struct {
	Vendor          string `json:"vendor"`
	ID              string `json:"order_id"`
	BuyerEmail      string `json:"buyer_email"`
	BuyerName       string `json:"buyer_name"`
	BuyerPhone      string `json:"buyer_phone"`
	Amount          int    `json:"amount"`
	Currency        string `json:"currency"`
	RedirectURL     string `json:"redirect_url,omitempty"`
	CancelURL       string `json:"cancel_url,omitempty"`
	Webhook         string `json:"webhook,omitempty"`
	BuyerRemarks    string `json:"buyer_remarks,omitempty"`
	MerchantRemarks string `json:"merchant_remarks,omitempty"`
	NumberItems     int    `json:"no_of_items,omitempty"`
	HeaderColour    string `json:"header_colour,omitempty"`
	LinkColour      string `json:"link_colour,omitempty"`
	ButtonColour    string `json:"button_colour,omitempty"`
	Expiry          int    `json:"expiry,omitempty"`
}

type Response

type Response struct {
	Reference  string           `json:"reference"`
	ResultCode string           `json:"resultcode"`
	Result     string           `json:"result"`
	Message    string           `json:"message"`
	Data       []map[string]any `json:"data"`
}

type UtilityPaymentInput

type UtilityPaymentInput struct {
	TransactionID    string  `json:"transid"`
	UtilityCode      string  `json:"utilitycode"`
	UtilityReference string  `json:"utilref"`
	Amount           float64 `json:"amount"`
	Vendor           string  `json:"vendor"`
	Pin              string  `json:"pin"`
	Phone            string  `json:"msisdn"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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