Installation

Install swervpay-go sdk into your new or existing Go application.

Shell
$ go get github.com/swerv-ltd/swervpay-go

Usage

Go
package main

import (
    "context"
	"fmt"
	"github.com/swerv-ltd/swervpay-go"
	"os"
)

func main() {


    ctx := context.Background()

	businessId := os.Getenv("SWERVPAY_BUSINESS_ID")
	secretKey := os.Getenv("SWERVPAY_SECRET_KEY")

	client := swervpay.NewSwervpayClient(&swervpay.SwervpayClientOption{
		BusinessID: businessId,
		SecretKey:  secretKey,
	})

	customers, err := client.Customer.Gets(ctx, &swervpay.PageAndLimitQuery{
		Page:  1,
		Limit: 10,
	})

	if err != nil {
		panic(err)
	}

	for _, customer := range *customers {
		fmt.Printf("%v\n", customer)
	}

	customer, err := client.Customer.Get(ctx, "cus_123456")

	if err != nil {
		panic(err)
	}

	fmt.Printf("%v\n", customer)

	newCustomer, err := client.Customer.Create(ctx, &swervpay.CreateCustomerBody{
		Firstname:  "John",
		Lastname:   "Doe",
		Middlename: "Doe",
		Email:      "[email protected]",
		Country:    "Nigeria",
	})

	if err != nil {
		panic(err)
	}

	fmt.Println("Created Customer id: " + newCustomer.ID)
	fmt.Printf("%v\n", newCustomer)


    banks, err := client.Other.Banks(ctx)

	if err != nil {
		panic(err)
	}

	for _, bank := range *banks {
		fmt.Printf("%v\n", bank)
	}

	resolveAccount, err := client.Other.ResolveAccountNumber(ctx, swervpay.ResolveAccountNumberBody{
		BankCode:      "044",
		AccountNumber: "0690000031",
	})

	if err != nil {
		panic(err)
	}

	fmt.Printf("%v\n", resolveAccount)


    transactions, err := client.Transaction.Gets(ctx, &swervpay.PageAndLimitQuery{
		Page:  1,
		Limit: 10,
	})

	if err != nil {
		panic(err)
	}

	for _, transaction := range *transactions {
		fmt.Printf("%v\n", transaction)
	}

	transaction, err := client.Transaction.Get(ctx, "txn_123456")

	if err != nil {
		panic(err)
	}

	fmt.Printf("%v\n", transaction)
}

See more examples