Skip to content

Go

github.com/oura-pay/oura-go · source

Requires Go 1.21+. No third-party dependencies. This SDK holds your secret key, so use it only on a server.

Install

go get github.com/oura-pay/oura-go

Accept a payment

import oura "github.com/oura-pay/oura-go"

client, err := oura.NewClient(os.Getenv("OURA_SECRET_KEY"))
if err != nil {
    log.Fatal(err)
}

payment, err := client.Payments.Create(oura.CreateParams{
    Amount:    245000,                      // NPR 2,450.00 in paisa
    Methods:   []string{"esewa", "khalti"},
    ReturnURL: "https://himalstore.com.np/orders/1042",
}, "") // empty idempotency key -> random UUID

http.Redirect(w, r, payment["checkout_url"].(string), http.StatusSeeOther)

Other calls

client.Payments.Retrieve("pay_123")
client.Payments.List(20, "pay_123")
client.Payments.Cancel("pay_123")
client.Payments.Create(params, "order_1042")

An idempotency key is generated for every create. Pass your own, tied to your order, to make retries safe across restarts. See Idempotency.

Configuration

Point the client at a local API while developing:

client, err := oura.NewClient(key, oura.WithBaseURL("http://localhost:8080"))

Webhooks

Verify with oura.ConstructEvent(raw, header, secret, oura.DefaultToleranceSeconds) and oura.VerifyWebhook(raw, header, secret, 300). Both compare in constant time and reject stale timestamps. Always pass the raw request body. Full example: Webhooks.

Errors

Every non-2xx response raises *oura.Error with the error code, HTTP status and message. See Errors.