Skip to content

Golang-Tanzania/selcompay-client

Repository files navigation

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
}

About

Go SDK for accessing selcom APIs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published