Skip to content

Latest commit

 

History

History
75 lines (57 loc) · 1.85 KB

README.md

File metadata and controls

75 lines (57 loc) · 1.85 KB

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
}