stripe

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("stripe: not found")

Functions

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 MakeID added in v0.3.8

func MakeID(parts ...string) string

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 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
}

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
}

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