This Module provides functionality developed to simplify interfacing with SelcomPay API in Go.
To access the API, contact SelcomPay
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
}