zazu

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 10 Imported by: 0

README

zazu-go

Go SDK for the Zazu API.

go get github.com/getzazu/zazu-go
import zazu "github.com/getzazu/zazu-go"

client, err := zazu.New(zazu.WithAPIKey(os.Getenv("ZAZU_API_KEY")))
if err != nil { ... }

entity, err := client.Entity.Get(ctx)

page, err := client.Accounts.List(ctx, zazu.AccountListParams{})
for _, account := range page.Data {
    fmt.Println(account["id"], account["name"])
}

// Initiate a transfer — it lands in your workspace's in-app approval
// queue; the API never executes a transfer itself.
draft, err := client.TransferDrafts.Create(ctx, zazu.Attributes{
    "account_id":        accountID,
    "beneficiary_id":    beneficiaryID,
    "amount":            "150.00",
    "payment_reference": "INV-000042",
})

Response shape

Response bodies are returned as-is from the API — snake_case keys in a map[string]any, no struct mapping. The same shape ships across every Zazu SDK (Ruby, TypeScript, Python, Go, ...) so the cassette contract is one-to-one.

Errors

Non-2xx responses come back as *zazu.Error with Status, Kind (authentication, forbidden, not_found, validation, rate_limit, server, api), the API's Type/Message/Param, and the RequestID. Transport failures are *zazu.ConnectionError.

Tests

Tests replay the canonical cassettes recorded by zazu-ruby. The cassettes are downloaded from the Ruby SDK's release tarball and served from an httptest.Server. Same interactions, same assertions, every language.

scripts/fetch-cassettes.sh
go test ./...

The SDK family

Documentation

Overview

Package zazu is the Go SDK for the Zazu API.

Response bodies are returned as-is from the API — snake_case keys, no struct mapping. The same shape ships across every Zazu SDK (Ruby, TypeScript, Python, Go, ...) so the cassette contract is one-to-one.

Index

Constants

View Source
const MaxPerPage = 100

MaxPerPage is the API's hard page-size cap.

View Source
const (
	// Version is the SDK version, sent in the User-Agent header.
	Version = "0.1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountListParams

type AccountListParams struct {
	ListParams
	Status       string
	CurrencyCode string
}

AccountListParams filters GET /api/accounts.

type AccountsService

type AccountsService struct {
	// contains filtered or unexported fields
}

AccountsService — accounts and their transactions.

func (*AccountsService) Get

func (s *AccountsService) Get(ctx context.Context, id string) (*Response, error)

Get calls GET /api/accounts/:id.

func (*AccountsService) GetTransaction

func (s *AccountsService) GetTransaction(ctx context.Context, accountID, transactionID string) (*Response, error)

GetTransaction calls GET /api/accounts/:account_id/transactions/:id.

func (*AccountsService) List

func (s *AccountsService) List(ctx context.Context, params AccountListParams) (*Page, error)

List calls GET /api/accounts.

func (*AccountsService) ListTransactions

func (s *AccountsService) ListTransactions(ctx context.Context, accountID string, params TransactionListParams) (*Page, error)

ListTransactions calls GET /api/accounts/:account_id/transactions.

type Attributes

type Attributes map[string]any

Attributes is a request body for create/update calls — snake_case keys, exactly what the API accepts (see the per-endpoint docs).

type BeneficiariesService

type BeneficiariesService struct {
	// contains filtered or unexported fields
}

BeneficiariesService — read-only directory of saved transfer recipients. Each beneficiary embeds its bank accounts; the one flagged `default` is used when a transfer names only the beneficiary_id. Beneficiaries are created and managed in the Zazu dashboard.

func (*BeneficiariesService) Get

Get calls GET /api/beneficiaries/:id.

func (*BeneficiariesService) List

func (s *BeneficiariesService) List(ctx context.Context, params ListParams) (*Page, error)

List calls GET /api/beneficiaries.

type CheckoutSessionsService

type CheckoutSessionsService struct {
	// contains filtered or unexported fields
}

CheckoutSessionsService — one-off hosted checkout sessions. No list, update, or delete; sessions are created and inspected by id.

func (*CheckoutSessionsService) Create

func (s *CheckoutSessionsService) Create(ctx context.Context, attributes Attributes) (*Response, error)

Create calls POST /api/checkout_sessions. Required attributes: account_id, amount, success_url.

func (*CheckoutSessionsService) Get

Get calls GET /api/checkout_sessions/:id.

type Client

type Client struct {
	Accounts         *AccountsService
	Beneficiaries    *BeneficiariesService
	CheckoutSessions *CheckoutSessionsService
	Customers        *CustomersService
	Entity           *EntityService
	Invoices         *InvoicesService
	PaymentLinks     *PaymentLinksService
	TransferDrafts   *TransferDraftsService
	WebhookEndpoints *WebhookEndpointsService
	// contains filtered or unexported fields
}

Client is the SDK entry point. Resources hang off it as fields.

client, err := zazu.New(zazu.WithAPIKey("sk_live_..."))
page, err := client.Accounts.List(ctx, zazu.ListParams{})

func New

func New(opts ...Option) (*Client, error)

New builds a Client. An API key is required — pass WithAPIKey or set ZAZU_API_KEY.

func (*Client) Request

func (c *Client) Request(ctx context.Context, method, path string, params url.Values, body any) (*Response, error)

Request performs an HTTP request against the API. Non-2xx responses are returned as *Error. Body (when non-nil) is JSON-encoded.

type ConfigurationError

type ConfigurationError struct{ Message string }

ConfigurationError is returned by New when the client can't be built.

func (*ConfigurationError) Error

func (e *ConfigurationError) Error() string

type ConnectionError

type ConnectionError struct{ Message string }

ConnectionError wraps transport-level failures (timeouts, DNS, refused).

func (*ConnectionError) Error

func (e *ConnectionError) Error() string

type CustomerListParams

type CustomerListParams struct {
	ListParams
	Query string // matches company name, person name, email
}

CustomerListParams filters GET /api/customers.

type CustomersService

type CustomersService struct {
	// contains filtered or unexported fields
}

CustomersService — individuals or businesses the entity invoices.

func (*CustomersService) Create

func (s *CustomersService) Create(ctx context.Context, attributes Attributes) (*Response, error)

Create calls POST /api/customers.

func (*CustomersService) Delete

func (s *CustomersService) Delete(ctx context.Context, id string) (*Response, error)

Delete calls DELETE /api/customers/:id.

func (*CustomersService) Get

func (s *CustomersService) Get(ctx context.Context, id string) (*Response, error)

Get calls GET /api/customers/:id.

func (*CustomersService) List

func (s *CustomersService) List(ctx context.Context, params CustomerListParams) (*Page, error)

List calls GET /api/customers.

func (*CustomersService) Update

func (s *CustomersService) Update(ctx context.Context, id string, attributes Attributes) (*Response, error)

Update calls PATCH /api/customers/:id.

type EntityService

type EntityService struct {
	// contains filtered or unexported fields
}

EntityService — the current entity (the tenant the API key belongs to).

func (*EntityService) Get

func (s *EntityService) Get(ctx context.Context) (*Response, error)

Get calls GET /api/entity.

type Error

type Error struct {
	Status     int
	Kind       string // authentication, forbidden, not_found, validation, rate_limit, server, api
	Type       string // the API's error.type field
	Message    string
	Param      string
	RequestID  string
	RetryAfter int // seconds; only set for rate_limit
	Body       map[string]any
}

Error is the API error envelope, mirroring the other Zazu SDKs' hierarchy: { "error": { "type": ..., "message": ..., "param": ... } }. Match on Kind (or use errors.As with the sentinel helpers) instead of subclassing.

func (*Error) Error

func (e *Error) Error() string

type InvoiceListParams

type InvoiceListParams struct {
	ListParams
	Status     string
	CustomerID string
}

InvoiceListParams filters GET /api/invoices.

type InvoicesService

type InvoicesService struct {
	// contains filtered or unexported fields
}

InvoicesService — invoices and their lifecycle actions.

func (*InvoicesService) Cancel

func (s *InvoicesService) Cancel(ctx context.Context, id string) (*Response, error)

Cancel calls POST /api/invoices/:id/cancel.

func (*InvoicesService) Create

func (s *InvoicesService) Create(ctx context.Context, attributes Attributes) (*Response, error)

Create calls POST /api/invoices.

func (s *InvoicesService) CreatePaymentLink(ctx context.Context, invoiceID, accountID string) (*Response, error)

CreatePaymentLink calls POST /api/invoices/:invoice_id/payment_link.

func (*InvoicesService) CreditNote

func (s *InvoicesService) CreditNote(ctx context.Context, id string) (*Response, error)

CreditNote calls POST /api/invoices/:id/credit_note.

func (*InvoicesService) Delete

func (s *InvoicesService) Delete(ctx context.Context, id string) (*Response, error)

Delete calls DELETE /api/invoices/:id.

func (*InvoicesService) Get

func (s *InvoicesService) Get(ctx context.Context, id string) (*Response, error)

Get calls GET /api/invoices/:id.

func (*InvoicesService) List

func (s *InvoicesService) List(ctx context.Context, params InvoiceListParams) (*Page, error)

List calls GET /api/invoices.

func (*InvoicesService) MarkAsPaid

func (s *InvoicesService) MarkAsPaid(ctx context.Context, id string) (*Response, error)

MarkAsPaid calls POST /api/invoices/:id/mark_as_paid.

func (*InvoicesService) Send

func (s *InvoicesService) Send(ctx context.Context, id string) (*Response, error)

Send calls POST /api/invoices/:id/send.

func (*InvoicesService) Update

func (s *InvoicesService) Update(ctx context.Context, id string, attributes Attributes) (*Response, error)

Update calls PATCH /api/invoices/:id.

type ListParams

type ListParams struct {
	Limit  int
	Cursor string
}

ListParams are the shared cursor-pagination inputs. Limit 0 means MaxPerPage.

type Option

type Option func(*Client)

Option configures a Client.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the API key (default: the ZAZU_API_KEY env var).

func WithAPIVersion

func WithAPIVersion(v string) Option

WithAPIVersion pins the Zazu-Version request header (default: ZAZU_API_VERSION).

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL sets the API base URL (default: ZAZU_BASE_URL or https://zazu.ma).

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient swaps the underlying *http.Client (default: 30s timeout).

type Page

type Page struct {
	Data       []map[string]any
	HasMore    bool
	NextCursor string
	Response   *Response
	// contains filtered or unexported fields
}

Page is one page of a cursor-paginated list endpoint: { "data": [...], "has_more": bool, "next_cursor": string|null }.

func (*Page) Next

func (p *Page) Next(ctx context.Context) (*Page, error)

Next fetches the following page, or returns nil when this is the last one.

type PaymentLinkListParams

type PaymentLinkListParams struct {
	ListParams
	Status   string
	LinkType string
}

PaymentLinkListParams filters GET /api/payment_links.

type PaymentLinksService

type PaymentLinksService struct {
	// contains filtered or unexported fields
}

PaymentLinksService — standalone payment links (not attached to an invoice).

func (*PaymentLinksService) Cancel

func (s *PaymentLinksService) Cancel(ctx context.Context, id string) (*Response, error)

Cancel calls POST /api/payment_links/:id/cancel.

func (*PaymentLinksService) Create

func (s *PaymentLinksService) Create(ctx context.Context, attributes Attributes) (*Response, error)

Create calls POST /api/payment_links.

func (*PaymentLinksService) Get

Get calls GET /api/payment_links/:id.

func (*PaymentLinksService) List

List calls GET /api/payment_links.

type Response

type Response struct {
	Status    int
	RequestID string
	Body      map[string]any
	Raw       []byte
}

Response is a successful (2xx) API response.

type TransactionListParams

type TransactionListParams struct {
	ListParams
	Operation    string
	PostedAfter  string // ISO-8601
	PostedBefore string // ISO-8601
}

TransactionListParams filters GET /api/accounts/:id/transactions.

type TransferDraftsService

type TransferDraftsService struct {
	// contains filtered or unexported fields
}

TransferDraftsService — API-initiated transfers. Creating a draft routes it into the workspace's in-app approval flow; the API never executes a transfer itself. Poll Get (status: requested → processing → completed / failed) or subscribe to the `transfer.executed` webhook.

func (*TransferDraftsService) Create

func (s *TransferDraftsService) Create(ctx context.Context, attributes Attributes) (*Response, error)

Create calls POST /api/transfer_drafts. Required: account_id, amount, and exactly one of beneficiary_id (external transfer) or destination_account_id (own-account move).

func (*TransferDraftsService) Get

Get calls GET /api/transfer_drafts/:id.

type WebhookEndpointsService

type WebhookEndpointsService struct {
	// contains filtered or unexported fields
}

WebhookEndpointsService — webhook endpoint management.

func (*WebhookEndpointsService) Create

func (s *WebhookEndpointsService) Create(ctx context.Context, attributes Attributes) (*Response, error)

Create calls POST /api/webhook_endpoints.

func (*WebhookEndpointsService) Delete

Delete calls DELETE /api/webhook_endpoints/:id.

func (*WebhookEndpointsService) Disable

func (s *WebhookEndpointsService) Disable(ctx context.Context, id string) (*Response, error)

Disable calls POST /api/webhook_endpoints/:id/disable.

func (*WebhookEndpointsService) Enable

Enable calls POST /api/webhook_endpoints/:id/enable.

func (*WebhookEndpointsService) Get

Get calls GET /api/webhook_endpoints/:id.

func (*WebhookEndpointsService) List

func (s *WebhookEndpointsService) List(ctx context.Context, params ListParams) (*Page, error)

List calls GET /api/webhook_endpoints.

func (*WebhookEndpointsService) RegenerateSecret

func (s *WebhookEndpointsService) RegenerateSecret(ctx context.Context, id string) (*Response, error)

RegenerateSecret calls POST /api/webhook_endpoints/:id/regenerate_secret.

func (*WebhookEndpointsService) Test

Test calls POST /api/webhook_endpoints/:id/test.

func (*WebhookEndpointsService) Update

func (s *WebhookEndpointsService) Update(ctx context.Context, id string, attributes Attributes) (*Response, error)

Update calls PATCH /api/webhook_endpoints/:id.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL