Skip to main content

Documentation Index

Fetch the complete documentation index at: https://waffo.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

Requirements

  • Go 1.20+
  • No external dependencies (standard library only)

Installation

go get github.com/waffo-com/waffo-go

Initialization

package main

import (
    "log"
    waffo "github.com/waffo-com/waffo-go"
    "github.com/waffo-com/waffo-go/config"
)

func main() {
    cfg, err := config.NewConfigBuilder().
        APIKey("your-api-key").
        PrivateKey("your-base64-encoded-private-key").
        WaffoPublicKey("waffo-public-key").
        MerchantID("your-merchant-id").
        Environment(config.Sandbox).
        Build()
    if err != nil {
        log.Fatal(err)
    }

    client := waffo.New(cfg)
}

Payments

import (
    "context"
    "github.com/google/uuid"
    "github.com/waffo-com/waffo-go/types/order"
)

ctx := context.Background()
paymentRequestID := uuid.New().String()[:32]

resp, err := client.Order().Create(ctx, &order.CreateOrderParams{
    PaymentRequestID: paymentRequestID,
    MerchantOrderID:  "ORDER-" + uuid.New().String()[:8],
    OrderAmount:      "99.99",
    OrderCurrency:    "USD",
    OrderDescription: "Premium Subscription",
    NotifyURL:        "https://your-site.com/webhook",
}, nil)

if err != nil {
    log.Fatal(err)
}

if resp.IsSuccess() {
    data := resp.GetData()
    fmt.Printf("Order ID: %s\n", data.AcquiringOrderID)
}

Webhook handling

import "github.com/waffo-com/waffo-go/core"

handler := client.Webhook().
    OnPayment(func(n *core.PaymentNotification) {
        fmt.Printf("Payment %s: %s\n", n.PaymentRequestID, n.OrderStatus)
    }).
    OnRefund(func(n *core.RefundNotification) {
        fmt.Printf("Refund %s: %s\n", n.RefundRequestID, n.RefundStatus)
    })

// HTTP handler
func webhookHandler(w http.ResponseWriter, r *http.Request) {
    body, _ := io.ReadAll(r.Body)
    signature := r.Header.Get("X-SIGNATURE")

    result := handler.HandleWebhook(string(body), signature)

    w.Header().Set("X-SIGNATURE", result.ResponseSignature)
    w.Header().Set("Content-Type", "application/json")
    w.WriteHeader(200)
    w.Write([]byte(result.ResponseBody))
}

Error handling

import "github.com/waffo-com/waffo-go/core"

resp, err := client.Order().Create(ctx, params, nil)
if err != nil {
    var unknownErr *core.WaffoUnknownStatusError
    if errors.As(err, &unknownErr) {
        // Important note: The payment may have succeeded! Please confirm using the query API.
    }
    var waffoErr *core.WaffoError
    if errors.As(err, &waffoErr) {
        // Client-side error
    }
}

Source code and documentation