stripe

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnectUnavailable = errors.New("connect unavailable")
)
View Source
var (
	ErrInvalidAPIKey = errors.New("stripe: Invalid API Key")
)
View Source
var ErrNotFound = errors.New("stripe: not found")

Functions

func BaseURL added in v0.5.0

func BaseURL() string

func CleanAccounts added in v0.5.2

func CleanAccounts(ctx context.Context, c *Client, f func(Account) bool) error

func Dedup

func Dedup(ctx context.Context, key string, logf func(string, ...any), f func(f Form) error) (winner bool, err error)

func IsLiveKey added in v0.3.8

func IsLiveKey(key string) bool
func Link(live bool, accountID string, parts ...string) (string, error)

Link creates and returns a link to the Stripe dashboard for the provided accountID followed by parts.

If live is true, a link to the live dashboard is returned, otherwise a test link is returned.

func MakeID added in v0.3.8

func MakeID(parts ...string) string

func MaybeSet added in v0.6.0

func MaybeSet[T comparable](f *Form, key string, val T)

func Slurp

func Slurp[I Identifiable](ctx context.Context, c *Client, method, path string, f Form) ([]I, error)

Slurp returns each I over all pages ln a list, or an error if any.

Types

type Account added in v0.5.0

type Account struct {
	ID      string
	Created time.Time
	Type    string // default is "standard"
	Meta    Meta
}

func CreateAccount added in v0.5.0

func CreateAccount(ctx context.Context, c *Client, p *AccountParams) (Account, error)

CreateAccount creates a new connected standard account.

type AccountParams added in v0.5.2

type AccountParams struct {
	Type         string // default is "standard"
	Meta         Meta   // optional metadata to associate with the account
	BusinessName string // required for switch accounts
}

type Client

type Client struct {
	APIKey     string
	BaseURL    string
	HTTPClient *http.Client
	AccountID  string
	Logf       func(format string, args ...any)

	// KeyPrefix is prepended to all idempotentcy keys. Use a new key prefix
	// after deleting test data. It is not recommended for use with live mode.
	KeyPrefix string

	Version string // default is 2022-11-15
}

func FromEnv

func FromEnv() (*Client, error)

func (*Client) CloneAs

func (c *Client) CloneAs(accountID string) *Client

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, f Form, out any) error

func (*Client) Live

func (c *Client) Live() bool

type Error

type Error struct {
	AccountID string
	Type      string
	Code      string
	Param     string
	Message   string
	DocURL    string
	RequestID string
}

func (*Error) Error

func (e *Error) Error() string

type Form

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

Form maps a string key to a list of values. It is intended for use when building request bodies for Stripe requests.

func (*Form) Add

func (f *Form) Add(args ...any)

Add creates a key and value from args and adds the value to the key. The key is constructed from all values in args up until the final, which will be used as the value.

Values are converted to strings according to fmt.Sprint rules, with the exception of time.Time values, which are converted to unix time (seconds since epoch).

Example mapping:

f.Add("tiers", 0, "up_to", 3) // => "tiers[0][up_to]=3"
f.Add("metadata", "link", "http://example.com") // => "metadata[link]=http://example.com"
f.Add("product[name]", "foo") // => "product[name]=foo"
f.Add("started", time.Unix(10, 0)) // => "started=10"

func (Form) Clone

func (f Form) Clone() Form

Clone returns a clone f.

func (*Form) Encode

func (f *Form) Encode() string

Encode encodes the values into “URL encoded” form ("bar=baz&foo=quux") sorted by key.

func (*Form) Set

func (f *Form) Set(args ...any)

func (*Form) SetIdempotencyKey

func (f *Form) SetIdempotencyKey(key string)

type ID

type ID string

func (ID) ProviderID

func (id ID) ProviderID() string

type Identifiable

type Identifiable interface {
	ProviderID() string
}

type Iterator

type Iterator[I Identifiable] struct {
	// contains filtered or unexported fields
}

func List

func List[I Identifiable](ctx context.Context, c *Client, method, path string, f Form) *Iterator[I]

func (*Iterator[I]) Err

func (i *Iterator[I]) Err() error

func (*Iterator[I]) Find

func (i *Iterator[I]) Find(f func(v I) bool) (I, error)

func (*Iterator[I]) Next

func (i *Iterator[I]) Next() bool

func (*Iterator[I]) Value

func (i *Iterator[I]) Value() I

type JustID

type JustID struct {
	ID
}

type Meta added in v0.5.2

type Meta map[string]string

Meta represents metadata in Stripe.

func (Meta) Get added in v0.5.2

func (m Meta) Get(k string) string

Directories

Path Synopsis
Package stroke provides utilities for testing with Stripe using isolated accounts and clocks.
Package stroke provides utilities for testing with Stripe using isolated accounts and clocks.

Jump to

Keyboard shortcuts

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