Skip to content

Golang-Tanzania/azampay

Repository files navigation

AZAMPAY



A golang client to access the Azam Payment Gateway. Made with love for gophers ❤️.

Introduction

AzamPay is specialized in the development of end-to-end online payment management solutions for companies operating in East Africa. They provide an API which allows developers to integrate their system's to Azampay's gateway.

This is a Golang client which significantly simplifies access and integration to Azampay's gateway.

Features of azampay

  • Make mobile network checkouts
  • Make bank checkouts
  • Manage callback URLs after a transaction is confirmed
  • Return a list of registered partners of the provided merchant
  • Create post checkout URLs for payments
  • Transfer of money from other countries to Tanzania
  • Lookup the name associated with a bank account or Mobile Money account
  • Retrieve the status of a disbursement transaction made through AzamPay

Pre-Requisites

  • Sign up for a developer account with Azampay
  • Register an app to get credentials
  • Use the provided credentials to access the API.

Installation

Note: Ensure you have initialized your go code with go mod init

Install the package with the go get command as shown below:

go get github.com/Golang-Tanzania/azampay@latest

Then import it as follows:

package main 

import (
    "github.com/Golang-Tanzania/azampay"
)

Authentication

Token Generation

appName := "Your app name from azamm pay"
clientId := "Client id from azam pay"
clientSecret := "Client secret from azam pay"
tokenKey := "Your token from azam pay"
client, err := azampay.NewClient(appName, clientId, clientSecret, tokenKey)

if err != nil {
		panic(err)
}

ctx := context.Background()
_, err = client.GetAccessToken(ctx)

if err != nil {
		fmt.Println(err)
	}

Transactions

MNO Checkout

// example MNO checkout
	exampleMNOCheckout := azampay.MnoPayload{
		AccountNumber: "0654001122",
		Amount:        "2000",
		Currency:      "TZS",
		ExternalID:    "123",
		Provider:      "Tigo",
	}

	res, err := client.MnoCheckout(ctx, exampleMNOCheckout)

	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(res)

Bank Checkout

// example Bank checkout
exampleBankCheckout := azampay.BankCheckoutPayload{
		Amount:                "10000",
		CurrencyCode:          "TZS",
		MerchantAccountNumber: "123321",
		MerchantMobileNumber:  "0700000000",
		MerchantName:          "somebody",
		OTP:                   "1234",
		Provider:              "CRDB",
		ReferenceID:           "123",
	}

	res, err := client.BankCheckout(ctx, exampleBankCheckout)

	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(res)

Payment Partners

// example get registered partners of the provided merchant 
rp, err := client.PaymentPartners(ctx)

if err != nil {
	fmt.Println(err)
}

fmt.Println(res)

Post Checkout

// example Post Checkout 
payload := azampay.PostCheckoutPayload{
		AppName:            "example",
		Amount:             "10000",
		ClientID:           "1234",
		Currency:           "TZS",
		ExternalID:         "30characterslong",
		Language:           "SW",
		RedirectFailURL:    "yoururl",
		RedirectSuccessURL: "yourrul",
		RequestOrigin:      "yourorigin",
		VendorName:         "VendorName",
		VendorID:           "e9b57fab-1850-44d4-8499-71fd15c845a0",
	}

	shoppingList := []azampay.Item{
		{Name: "Mandazi"},
		{Name: "Sambusa"},
		{Name: "Mkate"},
	}
    payload.Cart.Items = shoppingList
	
	res ,err := client.PostCheckout(ctx,payload) 

	if err != nil {
		fmt.Println(res)
	}

	fmt.Println(res)

Disburse

//example Transfer of money from other countries to Tanzania
disbursePayload := azampay.DisbursePayload{
		Source: azampay.Source{
			CountryCode:   "US",
			FullName:      "John Doe",
			BankName:      "Bank of America",
			AccountNumber: "123456789",
			Currency:      "USD",
		},
		Destination: azampay.Destination{
			CountryCode:   "TZ",
			FullName:      "Jane Doe",
			BankName:      "Azania Bank",
			AccountNumber: "987654321",
			Currency:      "TZS",
		},
		TransferDetails: azampay.TransferDetails{
			Type:   "SWIFT",
			Amount: 5000,
			Date:   time.Date(2023, 7, 11, 0, 0, 0, 0, time.UTC),
		},
		ExternalReferenceID: "123",
		Remarks:             "Payment for goods",
	}



	res ,err := client.Disburse(ctx, disbursePayload)
	if err != nil {

		fmt.Println(err)
	}

	fmt.Println(res)

Name Lookup

// example to lookup the name associated with a bank account or Mobile Money account.
res, err := client.NameLookUp(ctx, azampay.NameLookupPayload{
		AccountNumber: "0654000000",
		BankName:      "Tigo",
	})

	if err != nil {
       fmt.Println(err)

	}

fmt.Println(res)

Get Transaction Status

// example to retrieve the status of a disbursement transaction made through AzamPay.
queries := azampay.TransactionStatusQueries{

    BankName : "YOUR_MNO_NAME_HERE"
    PgReferenceID : "YOUR_TRANSACTION_ID_HERE"
}
res, err := client.TransactionalStatus(ctx,queries )

if err != nil {
	fmt.Println(err)
}

fmt.Println(res)

Issues

If you notice any issues with the package kindly notify us as soon as possible.

Credits

License

The MIT License (MIT). Please see License File for more information.

Contributors

Languages