swile

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package swile is a read-only client for the endpoints the Swile web app uses.

Read-only is a hard rule, not a default: this package must never gain a method that writes. No orders, no card operations, no banking mutations. A bug in a tool people run from a shell should never be able to spend money.

Index

Constants

View Source
const (

	// MaxRadius caps how wide a single search may reach. cantine answers "where
	// do I eat around here"; it is deliberately unable to sweep a region.
	MaxRadius = 10000 // metres

)

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Address1  string `json:"address1"`
	Address2  string `json:"address2"`
	City      string `json:"city"`
	Country   string `json:"country"`
	Postcode  string `json:"postal_code"`
	Formatted string `json:"formatted_address"`
}

Address is a merchant's postal address, already normalised by Swile.

type Cents

type Cents struct {
	Value    float64  `json:"value"`
	Currency Currency `json:"currency"`
}

Cents is an amount in minor units. neobank-api reports operations this way — -2150 means -21,50 €.

Money and Cents are separate types on purpose: the two services really do disagree about scale, and a shared type would let one be printed as the other without the compiler noticing.

func (Cents) String

func (c Cents) String() string

func (Cents) Units

func (c Cents) Units() float64

Units converts to major units.

type Client

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

Client talks to Swile on behalf of one session.

func New

func New(sess *auth.Session) *Client

New builds a client around an existing session.

func (*Client) Filters

func (c *Client) Filters(ctx context.Context) (*FilterSet, error)

Filters returns the caller's default wallet filters and the category catalogue.

func (*Client) Merchants

func (c *Client) Merchants(ctx context.Context, origin geo.Point, box geo.BBox, filters []Filter) (*MerchantResult, error)

Merchants finds places around origin within the given box.

func (*Client) Operations

func (c *Client) Operations(ctx context.Context, n int, since time.Time) ([]Operation, error)

Operations walks the account history from newest to oldest, stopping once it has n entries or reaches an entry older than since (zero time means no floor).

func (*Client) Session

func (c *Client) Session() *auth.Session

Session exposes the underlying session, so callers can report who is signed in.

func (*Client) Wallets

func (c *Client) Wallets(ctx context.Context) ([]Wallet, error)

Wallets lists the caller's balances.

The BFF requires the x-api-version header; without it it answers 404 rather than anything resembling a helpful error.

type Currency

type Currency struct {
	ISO3    string `json:"iso3"`
	ISO3Alt string `json:"iso_3"`
	Symbol  string `json:"symbol"`
	Title   string `json:"title"`
}

Currency is Swile's currency object — a nested object, not a plain ISO string. The two services disagree on how to spell the ISO field: the BFF sends iso3, neobank sends iso_3. Both are accepted here.

func (Currency) Code

func (c Currency) Code() string

Code returns the ISO 4217 code, whichever spelling the service used.

type Filter

type Filter struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Operator string `json:"operator"`
	Property string `json:"property"`
	Value    string `json:"value"`
}

Filter is one criterion accepted by the merchants endpoint. Only payment_networks and merchant_category_aggregated_code are valid properties; there is no name or text property, which is why searching by name can only happen locally.

type FilterSet

type FilterSet struct {
	DefaultFilters []Filter `json:"default_filters"`
	Sections       []struct {
		ID      string   `json:"id"`
		Name    string   `json:"name"`
		Filters []Filter `json:"filters"`
	} `json:"sections"`
}

FilterSet is what /user/filters returns: the caller's default wallet filters plus the catalogue of merchant categories.

func (*FilterSet) Categories

func (fs *FilterSet) Categories() []Filter

Categories flattens every category filter across sections.

type Merchant

type Merchant struct {
	UUID     string    `json:"uuid"`
	Name     string    `json:"name"`
	Position geo.Point `json:"position"`
	Address  Address   `json:"address"`

	PaymentNetworks  []string `json:"payment_networks"`
	MerchantCategory struct {
		AggregatedCode string `json:"aggregated_code"`
		Code           string `json:"code"`
		Description    string `json:"description"`
	} `json:"merchant_category"`

	IsFavorite    bool `json:"is_favorite"`
	IsClosed      bool `json:"is_closed"`
	IsBlacklisted bool `json:"is_blacklisted"`

	// DistanceM is computed locally from the search origin, not returned by the API.
	DistanceM float64 `json:"distance_m"`
}

Merchant is a place that accepts the caller's wallets.

type MerchantResult

type MerchantResult struct {
	Merchants  []Merchant
	TotalInBox int
	Origin     geo.Point
}

MerchantResult carries the merchants found plus how complete that answer is.

TotalInBox is what Swile says exists in the box; len(Merchants) is what it actually handed over. The two diverge badly in dense areas — 178 of 4304 in central Paris — so callers must surface the gap rather than present a partial answer as exhaustive.

func (*MerchantResult) Complete

func (r *MerchantResult) Complete() bool

Complete reports whether every merchant in the box was returned.

type Money

type Money struct {
	Value    float64  `json:"value"`
	Currency Currency `json:"currency"`
}

Money is an amount in major units. employee-bff-api reports wallet balances this way.

func (Money) String

func (m Money) String() string

type Operation

type Operation struct {
	ID          string    `json:"id"`
	Type        string    `json:"type"`
	DisplayType string    `json:"display_type"`
	Name        string    `json:"name"`
	Amount      Cents     `json:"amount"`
	Date        time.Time `json:"date"`
}

Operation is one line of account history.

type Wallet

type Wallet struct {
	ID                    string `json:"id"`
	Type                  string `json:"type"`
	Label                 string `json:"label"`
	Balance               Money  `json:"balance"`
	DailyAvailableBalance Money  `json:"dailyAvailableBalance"`
	IsActivated           bool   `json:"isActivated"`
}

Wallet is one balance on the card.

Jump to

Keyboard shortcuts

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