mirror of
https://github.com/hanzoai/commerce.git
synced 2026-11-23 18:55:39 +00:00
* Bank payments: ACH with Financial Connections, wires reconciled once, local bank methods by capability - ACH (us_bank_account) on the Stripe Payment Element top-up: bank verification automatic (instant through the bank login, microdeposits otherwise); a per-attempt limit (USD 5,000) and dollars only; the attempt is bound as delayed so it outlives a card's 48 hours; credit posts only on payment_intent.succeeded, once; a payment that fails after its credit posted takes the credit back through the refund path, once. - A checkout for one method (method=ach) opens an intent restricted to it. - Every bank method (ACH, SEPA debit, Pix, UPI, iDEAL, Bancontact, BLIK, P24, EPS, FPX, Multibanco, ACSS, BACS, BECS) is offered only where the Stripe account's capability is active (read from /v1/account, cached 5 minutes) and the policy has it on; the route answer lists ach, wire and the bank methods per country. - Wire: GET /v1/billing/wire carries a reference unique to the transfer; POST /v1/billing/wire/reconcile (platform) credits it once, audited, for the amount first credited. - The seed finds secrets at Hanzo's org root; the Kraken and MPC processors' availability follows the credentials the deposit rail reads. Testing: go test ./api/... ./payment/... (non-live); live Stripe test mode creates an ACH intent with automatic verification and an ACH-only intent; tests: ACH succeeded credits once, failed/returned leaves no credit, replays add nothing, wire reconcile idempotent, a local bank method settles once. Risk: dollar checkouts offer ACH where the account's capability is active. How to revert: git revert this commit. * Test: Kraken availability follows the deposit rail's credentials Testing: go test ./api/billing -run KrakenAvailability (fails without the fix). Risk: none (test). How to revert: git revert this commit.
127 lines
4.9 KiB
Go
127 lines
4.9 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
|
|
}
|
|
|
|
// 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
|
|
}
|