Go
GO SDK
Go SDK
Official Fern-generated Go client for the Suward merchant API. Uses pointer helpers (String, Bool, Int) for optional fields and typed asset ID constants.
Install
Install · Go
go get github.com/crylabsorg/suward-sdk-goInitialize and create a payment
Pass option.WithAPIKey to client.NewClient. All optional fields use pointer helpers: suwardsdkgo.String(), suwardsdkgo.Bool(). Asset IDs are typed constants, e.g. suwardsdkgo.CryptopayAssetIDUsdcBase.
main.go
package main import ( "context" "fmt" suwardsdkgo "github.com/crylabsorg/suward-sdk-go" "github.com/crylabsorg/suward-sdk-go/client" "github.com/crylabsorg/suward-sdk-go/option") func main() { c := client.NewClient(option.WithAPIKey("YOUR_API_KEY")) // "USDC_BASE" asset := suwardsdkgo.CryptopayAssetIDUsdcBase payment, err := c.Payments.CreatePayment( context.Background(), &suwardsdkgo.CryptopayCreatePaymentRequest{ Amount: suwardsdkgo.String("49.99"), Asset: &asset, ExternalID: suwardsdkgo.String("order-10472"), WebhookURL: suwardsdkgo.String("https://shop.example.com/webhooks/suward"), }, ) if err != nil { panic(err) } fmt.Println(*payment.ID, *payment.Address, payment.Status)}Get a payment
get-payment.go
p, err := c.Payments.GetPayment( context.Background(), &suwardsdkgo.GetV1PaymentsPaymentIDRequest{ PaymentID: "pay_3Nk8Qd", },)if err != nil { panic(err)}fmt.Println(*p.Status, *p.Amount)Full method surface
c.Payments
- ListPayments(ctx, order, limit, lastId)→(*ListPaymentsResponse, error)
- CreatePayment(ctx, CreatePaymentRequest)→(*PaymentResponse, error)
- GetPayment(ctx, paymentID)→(*PaymentResponse, error)
- ActivatePayment(ctx, paymentID)→(*PublicPaymentResponse, error)
- CancelPayment(ctx, paymentID)→(*PaymentResponse, error)
- SimulatePayment(ctx, paymentID, SimulatePaymentRequest)→(*PaymentResponse, error)
c.StaticWallets
- ListStaticWallets(ctx, order, limit, lastId)→(*ListStaticWalletsResponse, error)
- CreateStaticWallet(ctx, CreateStaticWalletRequest)→(*StaticWalletResponse, error)
- GetStaticWallet(ctx, staticWalletID)→(*StaticWalletResponse, error)
- DeleteStaticWallet(ctx, staticWalletID)→error
- UpdateStaticWallet(ctx, staticWalletID, UpdateStaticWalletRequest)→(*StaticWalletResponse, error)
- ListStaticWalletDeposits(ctx, staticWalletID, order, limit, lastId)→(*ListStaticDepositsResponse, error)
- SimulateStaticWalletDeposit(ctx, staticWalletID, SimulateStaticDepositRequest)→(*StaticDepositResponse, error)
Verify webhooks
The Go SDK does not ship a built-in signature verifier. Use crypto/ed25519 from the standard library to verify the signature over the raw request body. The public key is your project's webhookPublicKey from the dashboard.
webhook-handler.go
// imports: crypto/ed25519, encoding/hex, encoding/json, io, net/http, os, strings func suwardWebhook(w http.ResponseWriter, r *http.Request) { body, _ := io.ReadAll(r.Body) // "ed25519=<hex>" sig := r.Header.Get("X-Suward-Signature") sigBytes, _ := hex.DecodeString(strings.TrimPrefix(sig, "ed25519=")) pubKey, _ := hex.DecodeString(os.Getenv("SUWARD_WEBHOOK_PUBLIC_KEY")) if !ed25519.Verify(pubKey, body, sigBytes) { w.WriteHeader(http.StatusUnauthorized) return } var event struct { Type string `json:"type"` EventID string `json:"eventId"` } json.Unmarshal(body, &event) // event.Type: "payment.accepted" | "payment.success" | "payment.failed" if event.Type == "payment.success" { /* mark order paid */ } // non-2xx retried; dedupe on event.EventID w.WriteHeader(http.StatusOK)}Error handling
Use errors.As to unwrap *core.APIError. Inspect StatusCode, Message, and Body for machine-readable details.
error-handling.go
import ( "errors" "github.com/crylabsorg/suward-sdk-go/core") payment, err := c.Payments.CreatePayment(ctx, req)if err != nil { var apiErr *core.APIError if errors.As(err, &apiErr) { // inspect apiErr.StatusCode, apiErr.Message, apiErr.Body } return err}