SDKs & Integrations
Go

Go SDK

The official Novasend SDK for Go is designed to be simple, performant, and dependency-free. It exclusively uses Go's standard library.

Installation

Get the Go module:

go get github.com/novasend/novasend-go

Configuration

Initialize the client with your credentials (available on the Novasend Portal (opens in a new tab)). We recommend using os.Getenv to load your keys.

import (
    "os"
    "time"
    novasend "github.com/novasend/novasend-go"
)
 
client, err := novasend.NewClient(novasend.Config{
    APIKey:    os.Getenv("NOVASEND_API_KEY"),
    SecretKey: os.Getenv("NOVASEND_SECRET_KEY"),
    BaseURL:   os.Getenv("NOVASEND_BASE_URL"),
    Language:  "en",
    Timeout:   30 * time.Second,
})

Usage

Wallet Payment (Redirection)

resp, err := client.CreateWalletPayment(ctx, &novasend.WalletPaymentRequest{
    Reference:    "ref_999",
    Amount:       1500,
    MSISDN:       "+2250100000000",
    CustomerName: "Moussa Traoré",
    Country:      "CI",
    Action: novasend.PaymentAction{
        SuccessURL: "https://your-app.com/success",
        FailureURL: "https://your-app.com/fail",
    },
})
 
if err == nil {
    fmt.Println("Payment URL:", resp.PaymentURL)
}

Check Status

status, err := client.GetPaymentStatus(ctx, "ref_999")
if err == nil {
    fmt.Println("Status:", status.Status)
}

Webhooks

Verify webhook signatures using the standard library (HMAC-SHA256).

wh, _ := novasend.NewWebhooks(os.Getenv("NOVASEND_WEBHOOK_SECRET"))
 
http.HandleFunc("/webhook", func(w http.ResponseWriter, r *http.Request) {
    body, _ := io.ReadAll(r.Body)
    sig := r.Header.Get("X-Signature-Value")
 
    event, err := wh.VerifySignature(body, sig)
    if err != nil {
        w.WriteHeader(http.StatusUnauthorized)
        return
    }
    // Process event
    w.WriteHeader(http.StatusOK)
})

Error Handling

The SDK uses a custom APIError type to provide access to the details returned by Novasend.

if err != nil {
    var apiErr *novasend.APIError
    if errors.As(err, &apiErr) {
        fmt.Printf("API error %d: %s\n", apiErr.StatusCode, apiErr.Message)
    }
}

The Go SDK has zero external dependencies, ensuring a lightweight footprint and maximum security for your binaries.