Skip to main content
This SDK is coming soon. Subscribe to our changelog to be notified when it’s released.
The official Go SDK for FYATU API v3, with idiomatic Go design and error handling.

Requirements

  • Go 1.21 or higher

Installation

go get github.com/fyatu/fyatu-go

Quick Start

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/fyatu/fyatu-go"
)

func main() {
    client := fyatu.NewClient(
        fyatu.WithCredentials("your_app_id", "your_secret_key"),
    )

    // Create a collection
    collection, err := client.Collections.Create(context.Background(), &fyatu.CreateCollectionParams{
        Amount:      10.00,
        Currency:    "USD",
        Reference:   "order_123",
        Description: "Payment for Order #123",
        Customer: &fyatu.Customer{
            Email: "[email protected]",
            Name:  "John Doe",
        },
        RedirectURL: "https://yoursite.com/payment/success",
        WebhookURL:  "https://yoursite.com/webhooks/fyatu",
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(collection.CheckoutURL)
}

Features

  • Idiomatic Go - Follows Go conventions and best practices
  • Context Support - Full context.Context support for cancellation
  • Structured Errors - Type-safe error handling with error codes
  • Automatic Token Management - Handles JWT refresh automatically
  • Thread-Safe - Safe for concurrent use

Configuration Options

client := fyatu.NewClient(
    fyatu.WithCredentials("your_app_id", "your_secret_key"),

    // Optional configuration
    fyatu.WithBaseURL("https://api.fyatu.com/api/v3"),
    fyatu.WithTimeout(30 * time.Second),
    fyatu.WithRetries(3),
    fyatu.WithHTTPClient(customHTTPClient),
)

Available Services

ServiceDescription
client.CollectionsAccept payments via checkout
client.RefundsManage refunds
client.PayoutsSend money to recipients
client.CardholdersManage cardholders
client.CardsIssue and manage virtual cards
client.ESIMPurchase and manage eSIMs
client.AccountAccess account information

Error Handling

import (
    "errors"
    "github.com/fyatu/fyatu-go"
)

payout, err := client.Payouts.Create(ctx, &fyatu.CreatePayoutParams{
    Amount:      100,
    Currency:    "USD",
    RecipientID: "invalid_id",
})
if err != nil {
    var apiErr *fyatu.Error
    if errors.As(err, &apiErr) {
        switch apiErr.Code {
        case fyatu.ErrValidation:
            fmt.Printf("Validation failed: %v\n", apiErr.Details)
        case fyatu.ErrAuthentication:
            fmt.Printf("Authentication failed: %s\n", apiErr.Message)
        case fyatu.ErrInsufficientBalance:
            fmt.Printf("Insufficient balance: %s\n", apiErr.Message)
        default:
            fmt.Printf("API error [%s]: %s\n", apiErr.Code, apiErr.Message)
        }
    } else {
        fmt.Printf("Unexpected error: %v\n", err)
    }
    return
}

Webhook Verification

import (
    "net/http"
    "github.com/fyatu/fyatu-go/webhook"
)

func webhookHandler(w http.ResponseWriter, r *http.Request) {
    signature := r.Header.Get("X-Fyatu-Signature")

    payload, err := io.ReadAll(r.Body)
    if err != nil {
        http.Error(w, "Failed to read body", http.StatusBadRequest)
        return
    }

    valid, err := webhook.VerifySignature(payload, signature, "your_webhook_secret")
    if err != nil || !valid {
        http.Error(w, "Invalid signature", http.StatusUnauthorized)
        return
    }

    var event webhook.Event
    if err := json.Unmarshal(payload, &event); err != nil {
        http.Error(w, "Invalid payload", http.StatusBadRequest)
        return
    }

    fmt.Printf("Received event: %s\n", event.Type)
    w.WriteHeader(http.StatusOK)
}

Pagination

// List all collections with pagination
iter := client.Collections.List(ctx, &fyatu.ListCollectionsParams{
    Limit: 10,
})

for iter.Next() {
    collection := iter.Current()
    fmt.Printf("Collection: %s - %s\n", collection.ID, collection.Status)
}

if err := iter.Err(); err != nil {
    log.Fatal(err)
}

Resources