Skip to content

Go

The sanwo Go package generates checkout HTML and JavaScript for any Go web application. It works with net/http, Gin, Echo, Fiber, or any framework that serves HTML.

Terminal window
go get github.com/Sanwohq/go
package main
import (
"net/http"
"html/template"
sanwo "github.com/Sanwohq/go"
)
var tmpl = template.Must(template.New("page").Parse(`<!DOCTYPE html>
<html>
<body>
{{.Scripts}}
{{.Checkout}}
</body>
</html>`))
func main() {
s := sanwo.New(sanwo.Config{
Provider: sanwo.ProviderPaystack,
PublicKey: "pk_test_xxxxx",
Currency: "NGN",
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
tmpl.Execute(w, map[string]template.HTML{
"Scripts": s.RenderScript(),
"Checkout": s.RenderCheckout(sanwo.CheckoutOptions{
Amount: 500000,
Email: "customer@example.com",
ButtonText: "Pay ₦5,000",
}),
})
})
http.ListenAndServe(":8080", nil)
}

Create a new Sanwo client.

s := sanwo.New(sanwo.Config{
Provider: sanwo.ProviderPaystack,
PublicKey: "pk_test_xxxxx",
Currency: "NGN", // default "NGN"
Debug: false, // default false
})

Returns a <script> tag that loads the Sanwo embed script from CDN. Include once per page.

RenderCheckout(opts CheckoutOptions) template.HTML

Section titled “RenderCheckout(opts CheckoutOptions) template.HTML”

Returns a checkout button with inline JavaScript.

html := s.RenderCheckout(sanwo.CheckoutOptions{
Amount: 500000,
Email: "user@example.com",
ButtonText: "Pay Now",
ButtonClass: "sanwo-button",
Description: "Order #123",
Currency: "NGN",
FirstName: "John",
LastName: "Doe",
Callback: "onPaymentComplete",
})
Field Type Required Default Description
Amount int Yes — Amount in minor units (kobo, cents)
Email string Yes — Customer email
ButtonText string No "Pay Now" Button label
ButtonClass string No "sanwo-button" CSS class
Description string No — Payment description
Reference string No Auto-generated Transaction reference
Currency string No Config value Currency code
FirstName string No — Customer first name
LastName string No — Customer last name
Phone string No — Customer phone
Callback string No — JS callback function name

RenderCustomAmount(opts CustomAmountOptions) template.HTML

Section titled “RenderCustomAmount(opts CustomAmountOptions) template.HTML”

Returns a custom-amount widget where users enter their own amount.

html := s.RenderCustomAmount(sanwo.CustomAmountOptions{
Email: "donor@example.com",
ButtonText: "Donate",
Placeholder: "Enter amount",
})

Returns the current configuration as a map.

sanwo.ProviderPaystack
sanwo.ProviderFlutterwave
sanwo.ProviderRazorpay
sanwo.ProviderMonnify
sanwo.ProviderInterswitch
sanwo.ProviderCustom
s := sanwo.New(sanwo.Config{
Provider: sanwo.ProviderCustom,
PublicKey: "your_key",
TemplateURL: "https://example.com/my-provider-template.html",
// or: Template: `<div id="payment-form">...</div>`,
})
<script>
function onPaymentComplete(result) {
if (result.status === 'successful') {
window.location.href = '/thank-you?ref=' + result.reference;
}
}
</script>
s.RenderCheckout(sanwo.CheckoutOptions{
Amount: 500000,
Email: "user@example.com",
Callback: "onPaymentComplete",
})

Sanwohq/go on GitHub.