mirror of
https://github.com/hanzoai/commerce.git
synced 2026-11-23 18:55:39 +00:00
130 lines
5.0 KiB
Go
130 lines
5.0 KiB
Go
package processor
|
|
|
|
import "context"
|
|
|
|
// WalletConfigurer is a processor that keeps a commerce-owned configuration with the
|
|
// chosen wallets off and answers its id.
|
|
type WalletConfigurer interface {
|
|
WalletConfiguration(ctx context.Context, applePay, googlePay bool) (string, error)
|
|
}
|
|
|
|
// LocalIntentMaker is a processor that opens PaymentIntents for the Payment Element.
|
|
type LocalIntentMaker interface {
|
|
CreateLocalIntent(ctx context.Context, in LocalIntent) (*LocalIntentOut, error)
|
|
}
|
|
|
|
// LocalIntent is a PaymentIntent for the Payment Element: no payment method yet,
|
|
// no confirmation here. Stripe offers the buyer each method their country and
|
|
// the intent's currency allow (Pix and boleto in BRL, iDEAL and SEPA in EUR,
|
|
// OXXO in MXN, ...), as the account's payment method configuration enables them.
|
|
type LocalIntent struct {
|
|
Amount int64
|
|
Currency string
|
|
Key string // idempotency key
|
|
Metadata map[string]interface{}
|
|
Desc string
|
|
// Excluded are payment method types the Payment Element must not offer.
|
|
Excluded []string
|
|
// Only, when set, restricts the intent to these payment method types (a checkout for
|
|
// one method: a bank debit). Excluded and Configuration then do not apply.
|
|
Only []string
|
|
// Configuration is a Payment Method Configuration id to offer methods from, or "".
|
|
Configuration string
|
|
// Customer is the payer's customer at the processor; ReceiptEmail their email.
|
|
Customer string
|
|
ReceiptEmail string
|
|
// QuoteID is the processor's locked exchange rate (RateQuote.ID) the intent is
|
|
// bound to, so the processor converts at the rate the buyer was quoted. "" for none.
|
|
QuoteID string
|
|
// Verification, for the bank debits: how the bank account is verified, "automatic" being
|
|
// instant verification through the bank's login (Financial Connections) and microdeposits
|
|
// when the bank is not covered. "" leaves the processor's own default.
|
|
Verification string
|
|
// SaveForOffSession attaches the confirmed PaymentMethod (e.g. us_bank_account) to
|
|
// Customer for future off-session subscription renewals.
|
|
SaveForOffSession bool
|
|
}
|
|
|
|
// Capable is a processor that can say which payment methods its account takes now (not
|
|
// which exist): a method name as the policy writes it ("us_bank_account", "sepa_debit",
|
|
// "pix", "upi", ...) is true when the account's capability for it is active.
|
|
type Capable interface {
|
|
Methods(ctx context.Context) map[string]bool
|
|
}
|
|
|
|
// RateQuoter is a processor that quotes its own exchange rate to USD, the currency it
|
|
// settles in (Stripe's FX Quotes API), optionally locked for the life of one payment.
|
|
type RateQuoter interface {
|
|
QuoteRate(ctx context.Context, cur, lock string) (*RateQuote, error)
|
|
}
|
|
|
|
// Rate locks: how long a quoted rate holds. LockNone is the current rate, no lock and
|
|
// no premium; the others bind a payment and carry the processor's lock premium.
|
|
const (
|
|
LockNone = "none"
|
|
LockHour = "hour"
|
|
LockDay = "day"
|
|
)
|
|
|
|
// RateQuote is a processor's rate for converting Currency to USD. PerDollar is what one
|
|
// dollar costs in Currency at the rate the processor will CONVERT at (its own
|
|
// conversion fee and lock premium included), in major units. BasePerDollar is the same
|
|
// before them. FeeRate and Premium are the fraction taken for each.
|
|
type RateQuote struct {
|
|
ID string
|
|
Currency string
|
|
PerDollar float64
|
|
BasePerDollar float64
|
|
FeeRate float64
|
|
Premium float64
|
|
// ExchangeRate is the same rate as PerDollar the way Stripe states it: USD per one
|
|
// unit of Currency. ReferenceRate is the market reference Stripe measured against,
|
|
// from ReferenceProvider.
|
|
ExchangeRate float64
|
|
ReferenceRate float64
|
|
ReferenceProvider string
|
|
Lock string
|
|
ExpiresAt int64
|
|
}
|
|
|
|
// LocalIntentOut is what the browser needs to mount the Payment Element.
|
|
type LocalIntentOut struct {
|
|
ID string
|
|
ClientSecret string
|
|
}
|
|
|
|
// IntentState is a PaymentIntent's state as the payment state machine names it.
|
|
func IntentState(status string) string {
|
|
switch status {
|
|
case "succeeded":
|
|
return "succeeded"
|
|
case "canceled":
|
|
return "canceled"
|
|
case "processing", "requires_action", "requires_confirmation", "requires_capture":
|
|
return "pending"
|
|
default: // requires_payment_method
|
|
return "created"
|
|
}
|
|
}
|
|
|
|
// SettlementReader is a processor that reports what a payment settled for: the
|
|
// processor's balance transaction, in the currency it settles in.
|
|
type SettlementReader interface {
|
|
Settlement(ctx context.Context, intentID string) (*Settlement, error)
|
|
}
|
|
|
|
// Settlement is what the processor reports once a payment has settled, all in minor
|
|
// units of Currency (the settlement currency, USD). Gross is what the buyer's payment
|
|
// converted to, Fee the processor's fees in total (Tax inside it is the tax on them),
|
|
// Net what is left, and ExchangeRate the rate the processor converted at (settlement
|
|
// currency per unit of the paid currency), 0 when no conversion happened.
|
|
type Settlement struct {
|
|
BalanceTransaction string
|
|
Currency string
|
|
Gross int64
|
|
Fee int64
|
|
Tax int64
|
|
Net int64
|
|
ExchangeRate float64
|
|
}
|