Documentation
¶
Overview ¶
Package payments defines the payment provider interface the credits module uses: a hosted checkout for a server-priced amount, and verified webhook events.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInvalid means a webhook failed signature verification or is malformed. ErrInvalid = errors.New("payments: invalid webhook") // ErrIgnored means a valid webhook is not about a payment this app takes, such as // another product's order or an event type the app does not use. ErrIgnored = errors.New("payments: ignored webhook") )
Functions ¶
This section is empty.
Types ¶
type Checkout ¶
type Checkout struct {
// Reference identifies the purchase in the app; webhook events carry it back.
Reference string
// AmountCents is what the buyer pays, in EUR cents.
AmountCents int64
// Email prefills the buyer's address. It may be empty.
Email string
// SuccessURL is where the provider sends the buyer after paying.
SuccessURL string
}
Checkout is a payment to collect. The server sets the amount; the browser never chooses it.
type Event ¶
type Event struct {
// ID is the provider's event ID.
ID string
Kind EventKind
// Reference is the Checkout.Reference of the payment, when the event carries it.
Reference string
// CheckoutID and OrderID identify the payment at the provider.
CheckoutID string
OrderID string
// AmountCents is the checkout's price for a Paid event, and the reversed amount
// for a refund or dispute.
AmountCents int64
// PaidCents is what the buyer actually paid, which taxes or discounts can change.
PaidCents int64
// Currency is the ISO code, such as "EUR".
Currency string
// CreatedAt is when the provider created the event, if it says.
CreatedAt time.Time
// Review is set when the event is about one of the app's payments but cannot be
// applied as it stands, such as a refund that has not succeeded. It names why.
Review string
}
Event is a verified webhook event about one of the app's payments.
type Provider ¶
type Provider interface {
// Name identifies the provider in stored payments, such as "creem".
Name() string
// CheckoutOrigin is the origin of hosted checkout pages, which pages that start a
// checkout must allow as a form target.
CheckoutOrigin() string
// CreateCheckout creates a hosted checkout for c.
CreateCheckout(ctx context.Context, c Checkout) (Session, error)
// ParseWebhook verifies a webhook and decodes it. It returns ErrInvalid for a bad
// signature or body, and ErrIgnored for events the app does not act on.
ParseWebhook(header http.Header, body []byte) (Event, error)
}
Provider is a payment provider such as Creem.
Click to show internal directories.
Click to hide internal directories.