smobilpay

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 16 Imported by: 0

README

Smobilpay Go SDK

Build codecov Scrutinizer Code Quality Go Report Card GitHub contributors GitHub license PkgGoDev

This package provides an unofficial go client for the Smobilpay API

Installation

smobilpay-go is compatible with modern Go releases in module mode, with Go installed:

go get github.com/NdoleStudio/smobilpay-go

Alternatively the same can be achieved if you use import in a package:

import "github.com/NdoleStudio/smobilpay-go"

Implemented

  • Client
    • GET /ping: API Healthcheck endpoint
    • GET /verifytx: Get the current collection status
    • GET /historystd: Get the transaction history
    • POST /quotestd: Initializes a transaction
    • POST /collectstd: Confirms a transaction
  • Bill
    • GET /bill: Get details of a bill
  • Topup
    • GET /topup: Get available topup packages.
  • Cashin
    • GET /cashin: Get cashin pay item.
  • Cashout
    • GET /cashout: Get Cashout pay item.
  • Product
    • GET /product: Get product pay items.

Usage

Initializing the Client

An instance of the client can be created using New().

package main

import (
    "github.com/NdoleStudio/smobilpay-go"
)

func main()  {
    client := smobilpay.New(
        smobilpay.WithAccessToken(accessToken),
        smobilpay.WithAccessSecret(accessSecret),
    )
}
Error handling

All API calls return an error as the last return object. All successful calls will return a nil error.

status, response, err := client.Ping(context.Background())
if err != nil {
    //handle error
}

Testing

You can run the unit tests for this client from the root directory using the command below:

go test -v

License

This project is licensed under the MIT License - see the LICENSE file for details

Documentation

Index

Constants

View Source
const (
	// BillMerchantENEO is the merchant name for ENEO
	BillMerchantENEO = "ENEO"

	// BillMerchantCamwater is the merchant name for camwater
	BillMerchantCamwater = "CAMWATER"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bill

type Bill struct {
	PayItemID           string      `json:"payItemId"`
	ServiceNumber       string      `json:"serviceNumber"`
	ServiceID           string      `json:"serviceid"`
	Merchant            string      `json:"merchant"`
	AmountType          string      `json:"amountType"`
	LocalCurrency       string      `json:"localCur"`
	AmountLocalCurrency string      `json:"amountLocalCur"`
	BillNumber          string      `json:"billNumber"`
	CustomerNumber      string      `json:"customerNumber"`
	BillMonth           string      `json:"billMonth"`
	BillYear            string      `json:"billYear"`
	BillDate            time.Time   `json:"billDate"`
	BillDueDate         time.Time   `json:"billDueDate"`
	PayItemDescription  string      `json:"payItemDescr"`
	BillType            string      `json:"billType"`
	PenaltyAmount       string      `json:"penaltyAmount"`
	PayOrder            int         `json:"payOrder"`
	OptionalString      interface{} `json:"optStrg"`
	OptionalNumber      interface{} `json:"optNmb"`
}

Bill is the details for a bill payment

type BillGetParams

type BillGetParams struct {
	ServiceID     string
	Merchant      string
	ServiceNumber string
}

BillGetParams are the parameters for getting a bill

type Client

type Client struct {
	Topup   *topupService
	Bill    *billService
	Cashout *cashoutService
	Cashin  *cashinService
	Product *productService
	// contains filtered or unexported fields
}

Client is the smobilpay API client. Do not instantiate this client with Client{}. Use the New method instead.

func New

func New(options ...Option) *Client

New creates and returns a new *Client from a slice of Option.

func (*Client) Collect

func (client *Client) Collect(ctx context.Context, params *CollectParams, options ...RequestOption) (*Transaction, *Response, error)

Collect confirms a transaction

https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html

func (*Client) CollectSync added in v0.0.2

func (client *Client) CollectSync(ctx context.Context, params *CollectParams, options ...RequestOption) (*Transaction, *Response, error)

CollectSync confirms a transaction in sync by retrying every 15 seconds for 5 minutes

https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html

func (*Client) Ping

func (client *Client) Ping(ctx context.Context, options ...RequestOption) (*PingStatus, *Response, error)

Ping checks if the API is available

https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html

func (*Client) Quote

func (client *Client) Quote(ctx context.Context, params *QuoteParams, options ...RequestOption) (*Quote, *Response, error)

Quote initializes a transaction

https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html

func (*Client) TransactionHistory

func (client *Client) TransactionHistory(ctx context.Context, from time.Time, to time.Time, options ...RequestOption) ([]*Transaction, *Response, error)

TransactionHistory gets the history of transactions

https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html

func (*Client) Verify

func (client *Client) Verify(ctx context.Context, paymentTransactionNumber string, options ...RequestOption) (*Transaction, *Response, error)

Verify gets the current collection status

https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html

type CollectParams

type CollectParams struct {
	QuoteID               string `json:"quoteId"`
	CustomerPhoneNumber   string `json:"customerPhonenumber"`
	CustomerEmailAddress  string `json:"customerEmailaddress"`
	CustomerName          string `json:"customerName"`
	CustomerAddress       string `json:"customerAddress"`
	CustomerNumber        string `json:"customerNumber"`
	ServiceNumber         string `json:"serviceNumber"`
	ExternalTransactionID string `json:"trid"`
}

CollectParams is the input needed to confirm a transaction

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is options for constructing a client

func WithAccessSecret

func WithAccessSecret(accessSecret string) Option

WithAccessSecret sets the access secret for the smobilpay api

func WithAccessToken

func WithAccessToken(accessToken string) Option

WithAccessToken sets the access token for the smobilpay api

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL set's the base url for the smobilpay API

func WithCollectSyncVerifyInterval added in v0.0.3

func WithCollectSyncVerifyInterval(interval time.Duration) Option

WithCollectSyncVerifyInterval sets the interval for calling the `/verifytx` endpoint to check the status of pending transactions

func WithCollectSyncVerifyRetryCount added in v0.0.3

func WithCollectSyncVerifyRetryCount(retryCount uint) Option

WithCollectSyncVerifyRetryCount sets the number of retries for calling the `/verifytx` endpoint to check the status of pending transactions

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets the underlying HTTP client used for API requests. By default, http.DefaultClient is used.

type PayItem added in v0.0.3

type PayItem struct {
	ServiceID           string      `json:"serviceid"`
	Merchant            string      `json:"merchant"`
	PayItemID           string      `json:"payItemId"`
	AmountType          string      `json:"amountType"`
	LocalCurrency       string      `json:"localCur"`
	Name                string      `json:"name"`
	AmountLocalCurrency interface{} `json:"amountLocalCur"`
	Description         string      `json:"description"`
	PayItemDescription  interface{} `json:"payItemDescr"`
	OptionalString      interface{} `json:"optStrg"`
	OptionalNumber      interface{} `json:"optNmb"`
}

PayItem represents a payment item

type PingStatus

type PingStatus struct {
	Time    time.Time `json:"time"`
	Version string    `json:"version"`
	Nonce   string    `json:"nonce"`
	Key     string    `json:"key"`
}

PingStatus is the response when pinging the smobilpay API

type Quote

type Quote struct {
	QuoteID             string      `json:"quoteId"`
	ExpiresAt           time.Time   `json:"expiresAt"`
	PayItemID           string      `json:"payItemId"`
	AmountLocalCurrency string      `json:"amountLocalCur"`
	PriceLocalCurrency  string      `json:"priceLocalCur"`
	PriceSystemCurrency string      `json:"priceSystemCur"`
	LocalCurrency       string      `json:"localCur"`
	SystemCurrency      string      `json:"systemCur"`
	Promotion           interface{} `json:"promotion"`
}

Quote represents an initialized transaction

type QuoteParams

type QuoteParams struct {
	PayItemID string `json:"payItemId"`
	Amount    string `json:"amount"`
}

QuoteParams is the input needed to initialize a transaction

type RequestOption

type RequestOption interface {
	// contains filtered or unexported methods
}

RequestOption is options for constructing an API request

func WithRequestNonce

func WithRequestNonce(nonce string) RequestOption

WithRequestNonce sets the nonce in the s3pAuth_nonce header

func WithRequestTimestamp

func WithRequestTimestamp(timestamp time.Time) RequestOption

WithRequestTimestamp sets the timestamp in the s3pAuth_timestamp header

type Response

type Response struct {
	HTTPResponse *http.Response
	Body         *[]byte
}

Response captures the http response

func (*Response) Error

func (r *Response) Error() error

Error ensures that the response can be decoded into a string inc ase it's an error response

type Transaction

type Transaction struct {
	PaymentTransactionNumber string      `json:"ptn"`
	Timestamp                time.Time   `json:"timestamp"`
	AgentBalance             string      `json:"agentBalance"`
	ReceiptNumber            string      `json:"receiptNumber"`
	VerificationCode         string      `json:"veriCode"`
	ClearingDate             string      `json:"clearingDate"`
	PriceLocalCurrency       string      `json:"priceLocalCur"`
	PriceSystemCurrency      string      `json:"priceSystemCur"`
	LocalCurrency            string      `json:"localCur"`
	SystemCurrency           string      `json:"systemCur"`
	ExternalTransactionID    *string     `json:"trid"`
	Pin                      interface{} `json:"pin"`
	Status                   string      `json:"status"`
	PayItemDescription       *string     `json:"payItemDescr"`
	PayItemID                string      `json:"payItemId"`
}

Transaction represents a transaction

func (*Transaction) IsFailed

func (transaction *Transaction) IsFailed() bool

IsFailed checks if a transaction failed

func (*Transaction) IsPending added in v0.0.2

func (transaction *Transaction) IsPending() bool

IsPending checks if a transaction is pending

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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