Documentation
¶
Overview ¶
Package starlingbank is a complete, production-grade Go client for the Starling Bank Public API, structured around Domain-Driven Design (DDD) principles.
Architecture ¶
The package is organized into bounded contexts, each as a self-contained sub-package:
- account — accounts, identifiers, confirmation of funds
- accountholder — identity, name, address, type, email
- balance — cleared/effective/available balances
- transaction — feed items, spending category, attachments, statements
- payment — local, international, and standing order payments
- payee — saved recipients and their images
- directdebit — Direct Debit mandates
- savingsgoal — savings goals, top-ups, withdrawals, recurring transfers
- card — card controls (freeze, spend limits, channel toggles)
- webhook — event subscriptions and HMAC signature verification
- oauth — authorization URL, code exchange, token refresh
- receipt — itemized receipts and binary attachments
- merchant — merchant and merchant-location enrichment
- onboarding — TPP customer onboarding
Each bounded context exposes a typed Service with methods named after domain operations (not HTTP verbs). Services depend on the transport.Doer interface, enabling full unit-test isolation without a real HTTP server.
Quick start ¶
client := starlingbank.NewClient(
starlingbank.WithAccessToken("your-token"),
starlingbank.WithEnvironment(starlingbank.Production),
)
accounts, err := client.Account.List(ctx)
Error handling ¶
All methods return nil or a typed error — either transport.APIError (HTTP failures) or transport.NetworkError (transport failures). Use errors.As to inspect them, or compare against the sentinel values transport.ErrUnauthorized, transport.ErrNotFound, etc.
Hooks ¶
Register transport.HookFunc callbacks via WithHook for logging, Prometheus metrics, or OpenTelemetry spans — with no build-time dependency on those libraries.
Index ¶
- type Client
- type ClientOption
- func WithAccessToken(token string) ClientOption
- func WithBaseURL(url string) ClientOption
- func WithEnvironment(env Environment) ClientOption
- func WithHTTPClient(hc *http.Client) ClientOption
- func WithHook(fn transport.HookFunc) ClientOption
- func WithNoRetry() ClientOption
- func WithRetry(r transport.RetryConfig) ClientOption
- func WithTimeout(d time.Duration) ClientOption
- func WithTransport(t http.RoundTripper) ClientOption
- func WithUserAgent(ua string) ClientOption
- type Environment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// Account manages bank accounts and their identifiers.
Account *account.Service
// AccountHolder manages the identity and address of the account holder.
AccountHolder *accountholder.Service
// Balance provides balance enquiries for an account.
Balance *balance.Service
// Transaction provides the transaction feed, spending categories, and statements.
Transaction *transaction.Service
// Payment initiates local and international payments and manages standing orders.
Payment *payment.Service
// Payee manages saved payment recipients.
Payee *payee.Service
// DirectDebit manages Direct Debit mandates.
DirectDebit *directdebit.Service
// SavingsGoal manages savings pots and their top-up/withdrawal transfers.
SavingsGoal *savingsgoal.Service
// Card manages card controls (freeze, spend limits, channel toggles).
Card *card.Service
// Webhook provides webhook subscription listing and signature verification.
Webhook *webhook.Service
// OAuth implements the OAuth 2.0 authorization code flow.
OAuth *oauth.Service
// Receipt manages itemized receipts and binary receipt attachments.
Receipt *receipt.Service
// Merchant provides merchant and merchant-location enrichment data.
Merchant *merchant.Service
// Onboarding handles TPP customer onboarding applications.
Onboarding *onboarding.Service
}
Client is the entry point for all Starling Bank API calls. Obtain one with NewClient; it is safe for concurrent use by multiple goroutines.
Each field is the application service for its bounded context. All services share a single underlying HTTP transport and configuration.
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
NewClient creates a new Client with the given options. Supply at least WithAccessToken for authenticated calls.
Example:
c := starlingbank.NewClient(
starlingbank.WithAccessToken(os.Getenv("STARLING_TOKEN")),
starlingbank.WithEnvironment(starlingbank.Production),
starlingbank.WithHook(myLoggingHook),
)
type ClientOption ¶
type ClientOption func(*clientConfig)
ClientOption is a functional option for NewClient.
func WithAccessToken ¶
func WithAccessToken(token string) ClientOption
WithAccessToken sets the Bearer token used for API authentication.
func WithBaseURL ¶
func WithBaseURL(url string) ClientOption
WithBaseURL overrides the API base URL (useful for tests and proxies).
func WithEnvironment ¶
func WithEnvironment(env Environment) ClientOption
WithEnvironment selects Sandbox or Production.
func WithHTTPClient ¶
func WithHTTPClient(hc *http.Client) ClientOption
WithHTTPClient replaces the underlying *http.Client entirely.
func WithHook ¶
func WithHook(fn transport.HookFunc) ClientOption
WithHook registers a transport.HookFunc called before and after every request. Multiple hooks are called in registration order.
func WithRetry ¶
func WithRetry(r transport.RetryConfig) ClientOption
WithRetry configures retry behavior.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout sets the per-request HTTP timeout.
func WithTransport ¶
func WithTransport(t http.RoundTripper) ClientOption
WithTransport replaces only the http.Transport, keeping the configured timeout.
func WithUserAgent ¶
func WithUserAgent(ua string) ClientOption
WithUserAgent overrides the User-Agent header.
type Environment ¶
type Environment int
Environment selects which Starling API environment to target.
const ( // Sandbox targets https://api-sandbox.starlingbank.com (default). Sandbox Environment = iota // Production targets https://api.starlingbank.com. Production )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package account defines the Account bounded context: entities, value objects, and the application service for managing Starling bank accounts.
|
Package account defines the Account bounded context: entities, value objects, and the application service for managing Starling bank accounts. |
|
Package accountholder defines the Account Holder bounded context: the identity, address, and personal/business details of a Starling account owner.
|
Package accountholder defines the Account Holder bounded context: the identity, address, and personal/business details of a Starling account owner. |
|
Package balance defines the Balance bounded context.
|
Package balance defines the Balance bounded context. |
|
Package card defines the Card bounded context: payment card entities and card control value objects.
|
Package card defines the Card bounded context: payment card entities and card control value objects. |
|
Package directdebit defines the Direct Debit bounded context: mandates authorising third parties to collect payments from a Starling account.
|
Package directdebit defines the Direct Debit bounded context: mandates authorising third parties to collect payments from a Starling account. |
|
internal
|
|
|
transport
Package transport provides the HTTP infrastructure layer for the Starling Bank client.
|
Package transport provides the HTTP infrastructure layer for the Starling Bank client. |
|
Package merchant defines the Merchant bounded context: enriched merchant and merchant-location data linked to card transactions.
|
Package merchant defines the Merchant bounded context: enriched merchant and merchant-location data linked to card transactions. |
|
Package oauth implements the Starling Bank OAuth 2.0 authorization code flow.
|
Package oauth implements the Starling Bank OAuth 2.0 authorization code flow. |
|
Package onboarding defines the Customer Onboarding bounded context, used by registered Third-Party Providers to onboard new customers onto Starling.
|
Package onboarding defines the Customer Onboarding bounded context, used by registered Third-Party Providers to onboard new customers onto Starling. |
|
Package payee defines the Payee bounded context: saved payment recipients.
|
Package payee defines the Payee bounded context: saved payment recipients. |
|
Package payment defines the Payment bounded context: local (FPS) payments, international payments, and standing orders.
|
Package payment defines the Payment bounded context: local (FPS) payments, international payments, and standing orders. |
|
Package receipt defines the Receipt bounded context: itemized receipts and binary receipt attachments linked to transaction feed items.
|
Package receipt defines the Receipt bounded context: itemized receipts and binary receipt attachments linked to transaction feed items. |
|
Package savingsgoal defines the Savings Goal bounded context: savings pots, top-up transfers, withdrawals, and recurring transfer schedules.
|
Package savingsgoal defines the Savings Goal bounded context: savings pots, top-up transfers, withdrawals, and recurring transfer schedules. |
|
Package shared defines value objects and primitive types that form the shared kernel across all bounded contexts in the Starling Bank domain.
|
Package shared defines value objects and primitive types that form the shared kernel across all bounded contexts in the Starling Bank domain. |
|
Package transaction defines the Transaction Feed bounded context: feed items, spending categories, attachments, and statement downloads.
|
Package transaction defines the Transaction Feed bounded context: feed items, spending categories, attachments, and statement downloads. |
|
Package webhook defines the Webhook bounded context: event subscriptions and the domain event envelope delivered by Starling's push notification system.
|
Package webhook defines the Webhook bounded context: event subscriptions and the domain event envelope delivered by Starling's push notification system. |