Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sanwo Go SDK

A server-side HTML generator for Sanwo payment checkouts. This package does not make HTTP requests — it produces HTML and inline JavaScript that loads the Sanwo embed script from the CDN and calls Sanwo.create() / .checkout() in the browser.

Installation

go get github.com/Sanwohq/go

Quick Start

package main

import (
	"fmt"
	"net/http"

	sanwo "github.com/Sanwohq/go"
)

func main() {
	s, err := sanwo.New(sanwo.Config{
		Provider:  sanwo.ProviderPaystack,
		PublicKey: "pk_test_xxxxxxxxxxxx",
	})
	if err != nil {
		panic(err)
	}

	http.HandleFunc("/pay", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "text/html; charset=utf-8")

		// Load the Sanwo embed script.
		fmt.Fprint(w, s.RenderScript())

		// Render a checkout button (amount in minor units: 50000 = NGN 500).
		btn, err := s.RenderCheckout(sanwo.CheckoutOptions{
			Amount:      50000,
			Email:       "customer@example.com",
			Description: "Premium Plan",
		})
		if err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		fmt.Fprint(w, btn)
	})

	fmt.Println("Listening on :8080")
	http.ListenAndServe(":8080", nil)
}

Custom Amount Widget

Render an input that lets the customer choose the amount:

html, err := s.RenderCustomAmount(sanwo.CustomAmountOptions{
	Email:     "customer@example.com",
	MinAmount: 10000,  // NGN 100 minimum
	MaxAmount: 500000, // NGN 5000 maximum
})

If Email is omitted an email input field is rendered automatically.

Custom Provider with Template

s, err := sanwo.New(sanwo.Config{
	Provider:  sanwo.ProviderCustom,
	PublicKey: "pk_test_xxxxxxxxxxxx",
	Template:  `<form><input name="amount" /><button type="submit">Pay</button></form>`,
})

Or use a remote template:

s, err := sanwo.New(sanwo.Config{
	Provider:    sanwo.ProviderCustom,
	PublicKey:   "pk_test_xxxxxxxxxxxx",
	TemplateURL: "https://example.com/checkout-template.html",
})

Supported Providers

Constant Provider
sanwo.ProviderPaystack Paystack
sanwo.ProviderFlutterwave Flutterwave
sanwo.ProviderRazorpay Razorpay
sanwo.ProviderMonnify Monnify
sanwo.ProviderInterswitch Interswitch
sanwo.ProviderCustom Custom

Configuration

Field Type Default Description
Provider string One of the Provider* constants (required)
PublicKey string Your provider's public/publishable key (required)
Currency string "NGN" Default ISO 4217 currency code
Debug bool false Log checkout events to the browser console
TemplateURL string "" URL to a custom payment template
Template string "" Inline HTML template string

All amounts are in minor units (kobo / cents). For example, NGN 500.00 = 50000.

License

MIT

About

Sanwo payment SDK for Go

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages