Skip to content

Go SDK

Terminal window
go get github.com/feitpay/feitpay-go
client, err := feitpay.New(os.Getenv("FEITPAY_API_KEY"),
feitpay.WithBaseURL("https://api.feitpay.com"),
feitpay.WithMaxRetries(2),
)
intent, err := client.PaymentIntents.Create(ctx, &feitpay.PaymentIntentCreateParams{
StoreID: "store_YOUR_STORE_ID", Amount: "59.90", Currency: "EUR", IdempotencyKey: "order-123",
})
for pi, err := range client.PaymentIntents.All(ctx, &feitpay.PaymentIntentListParams{
Status: []feitpay.PaymentStatus{feitpay.StatusConfirmed},
}) {
if err != nil {
return err
}
fmt.Println(pi.ID, pi.Fulfillable)
}

Errors are *feitpay.Error with Type, Code, Param, Status, RequestID and RetryAfter; use feitpay.ErrorType(err) for quick checks. The client is safe for concurrent use; reuse one instance.

Services: PaymentIntents (Create, Get, List, All, Cancel, Resolve, Timeline), CheckoutSessions, WebhookEndpoints (Create, List, RotateSecret, SendTest), WebhookDeliveries (Get, Retry), Platform (Capabilities) and Pix (Pricing). For other endpoints, see the API reference.

Set AllowedMethods on a payment in BRL: feitpay.MethodPix alone makes a PIX-only payment, and feitpay.MethodCrypto with feitpay.MethodPix lets the customer choose at checkout. Leave it empty for crypto only.

// A PIX-only payment.
pixOnly, err := client.PaymentIntents.Create(ctx, &feitpay.PaymentIntentCreateParams{
StoreID: "store_YOUR_STORE_ID", Amount: "59.90", Currency: "BRL",
AllowedMethods: []string{feitpay.MethodPix}, IdempotencyKey: "order-1042",
})
// The customer chooses crypto or PIX at checkout.
either, err := client.PaymentIntents.Create(ctx, &feitpay.PaymentIntentCreateParams{
StoreID: "store_YOUR_STORE_ID", Amount: "59.90", Currency: "BRL",
AllowedMethods: []string{feitpay.MethodCrypto, feitpay.MethodPix}, IdempotencyKey: "order-1043",
})

Read fees, minimums and availability from the API instead of hard-coding them. client.Pix.Pricing calls GET /v1/pix/pricing (API keys need the balances:read scope):

pricing, err := client.Pix.Pricing(ctx)
if err != nil {
return err
}
if !pricing.Available {
// PIX is switched off: create crypto-only payments.
}

pricing.Tiers (in order; the first tier whose bound holds applies), MinimumFee, MinimumPayment and PayoutFee are BRL decimal strings. Once the PIX charge is open, intent.Processor.Methods[i].PixCopyPaste is its copia e cola code; once the payment is credited, intent.Processor.Fee is the PIX fee that was deducted. Checkout, statuses, fees and error codes: PIX (Brazil).

event, err := webhook.Verify(body, r.Header.Get(webhook.SignatureHeader), []string{secret, previousSecret}, nil)
if err != nil {
http.Error(w, string(webhook.ReasonOf(err)), http.StatusBadRequest)
return
}
data, _ := event.PaymentData()

webhook.Options{Tolerance: …, Now: …} customises tolerance and time for tests; webhook.GenerateTestHeader creates valid headers.