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.
go get github.com/Sanwohq/gopackage 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)
}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.
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",
})| Constant | Provider |
|---|---|
sanwo.ProviderPaystack |
Paystack |
sanwo.ProviderFlutterwave |
Flutterwave |
sanwo.ProviderRazorpay |
Razorpay |
sanwo.ProviderMonnify |
Monnify |
sanwo.ProviderInterswitch |
Interswitch |
sanwo.ProviderCustom |
Custom |
| 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.
MIT