Documentation Index
Fetch the complete documentation index at: https://docs.toffeepay.com/llms.txt
Use this file to discover all available pages before exploring further.
Install
go get github.com/toffeepay/sdk-go
Configuration
import sdk "github.com/toffeepay/sdk-go"
toffee := sdk.New(sdk.Config{
AccessToken: "your-access-token",
})
Sandbox
toffee := sdk.New(sdk.Config{
AccessToken: "your-sandbox-token",
Environment: sdk.Sandbox,
})
Checkout
Shorthand for creating a payment session:session, err := toffee.Checkout(ctx, &sdk.CreateSessionRequest{
Item: &sdk.Item{Title: "Gem Pack 50", Price: 100, Currency: "USD"},
GameId: "your-game-id",
UserId: "user-id",
ReturnUrl: "https://example.com/return",
})
fmt.Println(session.GetUrl()) // redirect the user here
Refund
Shorthand for creating a refund:refund, err := toffee.Refund(ctx, &sdk.CreateRefundRequest{
PaymentId: "pay_123",
})
Idempotency
Pass an idempotency key to protect against duplicate operations:session, err := toffee.Checkout(ctx, &sdk.CreateSessionRequest{
Item: &sdk.Item{Title: "Gem Pack 50", Price: 100, Currency: "USD"},
GameId: "game_1",
UserId: "user_1",
ReturnUrl: "https://example.com/return",
}, sdk.WithIdempotencyKey("unique-key-123"))
refund, err := toffee.Refund(ctx, &sdk.CreateRefundRequest{
PaymentId: "pay_123",
}, sdk.WithIdempotencyKey("refund-key-456"))
Resources
Sessions
resp, err := toffee.Sessions.Create(ctx, &sdk.CreateSessionRequest{...})
session := resp.GetSession()
resp, err := toffee.Sessions.Get(ctx, &sdk.GetSessionRequest{Id: "sess_123"})
session := resp.GetSession()
resp, err := toffee.Sessions.Status(ctx, &sdk.GetSessionStatusRequest{Id: "sess_123"})
// resp.GetId(), resp.GetStatus()
resp, err := toffee.Sessions.List(ctx, &sdk.ListSessionsRequest{GameId: "game_1"})
sessions := resp.GetSessions()
_, err = toffee.Sessions.Cancel(ctx, &sdk.CancelSessionRequest{Id: "sess_123"})
Payments
resp, err := toffee.Payments.Get(ctx, &sdk.GetPaymentRequest{Id: "pay_123"})
payment := resp.GetPayment()
resp, err := toffee.Payments.List(ctx, &sdk.ListPaymentsRequest{GameId: "game_1"})
payments := resp.GetPayments()
_, err = toffee.Payments.Complete(ctx, &sdk.CompletePaymentRequest{Id: "pay_123"})
_, err = toffee.Payments.Cancel(ctx, &sdk.CancelPaymentRequest{Id: "pay_123"})
Refunds
resp, err := toffee.Refunds.Create(ctx, &sdk.CreateRefundRequest{PaymentId: "pay_123"})
refund := resp.GetRefund()
resp, err := toffee.Refunds.Get(ctx, &sdk.GetRefundRequest{Id: "ref_123"})
refund := resp.GetRefund()
resp, err := toffee.Refunds.List(ctx, &sdk.ListRefundsRequest{PaymentId: &paymentId})
refunds := resp.GetRefunds()
Accounts
resp, err := toffee.Accounts.Get(ctx, &sdk.GetAccountRequest{Id: "acc_123"})
account := resp.GetAccount()
resp, err := toffee.Accounts.List(ctx, &sdk.ListAccountsRequest{GameId: "game_1"})
accounts := resp.GetAccounts()
Deposits
resp, err := toffee.Deposits.Get(ctx, &sdk.GetDepositRequest{Id: "dep_123"})
deposit := resp.GetDeposit()
resp, err := toffee.Deposits.List(ctx, &sdk.ListDepositsRequest{AccountId: "acc_123"})
deposits := resp.GetDeposits()