mirror of
https://github.com/hanzoai/commerce.git
synced 2026-11-23 05:38:11 +00:00
* billing: processors are told who is paying, so their card checks stop declining a stranger
A live Stripe account was declining first-period charges (card_velocity_exceeded,
do_not_honor, insufficient_funds on a normal-risk buyer). The customer Stripe held
was named for the org slug ("github"), with no email, phone or address; the card
carried only a postal code; the PaymentIntent had no receipt email, no statement
suffix and metadata of only hanzo_subject.
vaultCustomer no longer passes the billing subject as the customer name. A Payer
(name, email, phone, billing address, org, user) is carried from the host to the
processors: Stripe and Square create ONE customer per payer with everything known
and bring an existing customer up to date at its next checkout (processor.PayerProfiles:
CreateCustomerFor, ProfileCustomer; writes nothing when it already agrees). The name
and email are the host's verified identity and no request body can set them
(CreateMethodIn.BillingName is json:"-"); phone and address are the buyer's.
After a SetupIntent saves a card, its billing_details are completed from the customer.
Every Stripe card PaymentIntent now carries receipt_email, statement_descriptor_suffix
"HANZO AI", a description naming plan, seats and date, and metadata org/user/subject;
saved cards remember their payer's email/name/org/user so renewals and reloads carry
them too. The Payment Element intent is made for the payer's customer with the same.
BackfillPayers reads (dry run by default) the customers commerce made whose name is a
billing key and proposes the person's name and email from the host's identity lookup;
writing is a separate explicit argument, and a repeat writes nothing. It was not run.
There is no automatic re-attempt with a new amount: a first-period charge is made only
by the buyer's own request, and a renewal charges the invoice's amount; nothing here
adds a retry.
Testing: Stripe test mode, TestLiveStripe_TheCustomerAndTheCardNameThePayer (customer name/
email/phone/address/metadata, card billing_details, PaymentIntent receipt_email/suffix/
description/metadata) and TestLiveStripe_ACustomerMadeNamelessIsNamedAtItsNextCheckout fail
with the old behaviour (customer "hanzo", no phone, no address) and pass; TestTheBackfill...;
Square TestAPayerIsSplit...; full api/billing, payment/..., thirdparty/square, api/checkout pass.
Risk: medium (billing). Customers already at Stripe are updated in place at their next
checkout; a profile that cannot be written is logged and does not stop the checkout.
How to revert: git revert this commit; customers are named for the billing subject again.
Co-authored-by: Hanzo Dev <[email protected]>
* square: a payer the host could not name is still a customer, under its org's company name
Square refuses a customer with no name, email, phone or company. Before, the billing
subject stood in as the given name; with the subject gone from the name, a sale whose
host passed no name and no email failed at the customer ("Card declined"). The org the
payer buys for is now the customer's company_name, which is what it is.
Testing: cloud apps/commerce TestASquareSaleOfEveryRungIsTheLimitersPlan (Square sandbox)
failed without this ("Card declined — invalid card number") and passes with it.
Risk: low; one more field on a new Square customer.
How to revert: git revert this commit.
Co-authored-by: Hanzo Dev <[email protected]>
---------
Co-authored-by: Hanzo Dev <[email protected]>
55 lines
2.2 KiB
Go
55 lines
2.2 KiB
Go
package processor
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
)
|
|
|
|
// Payer is who is paying, as a processor needs to know them: the person, never the
|
|
// billing key they are charged under. Name and Email come from the host's verified
|
|
// identity; Phone and Address are what the buyer typed in the payment form. Org and
|
|
// User say whose books the payment is in, for the processor's own records.
|
|
type Payer struct {
|
|
Name string
|
|
Email string
|
|
Phone string
|
|
Locale string // BCP 47, e.g. "en-US"; "" when unknown
|
|
// Address is the billing address, nil when the buyer gave none.
|
|
Address *PayerAddress
|
|
Org string
|
|
User string
|
|
}
|
|
|
|
// PayerAddress is a billing address in a processor's terms.
|
|
type PayerAddress struct {
|
|
Line1, Line2, City, State, Postal, Country string
|
|
}
|
|
|
|
// Empty reports whether the address names nothing.
|
|
func (a *PayerAddress) Empty() bool {
|
|
return a == nil || (a.Line1 == "" && a.Line2 == "" && a.City == "" && a.State == "" && a.Postal == "" && a.Country == "")
|
|
}
|
|
|
|
// Known reports whether the payer carries anything a processor can record.
|
|
func (p Payer) Known() bool {
|
|
return strings.TrimSpace(p.Name) != "" || strings.TrimSpace(p.Email) != "" || strings.TrimSpace(p.Phone) != "" || !p.Address.Empty()
|
|
}
|
|
|
|
// PayerProfiles is a processor that keeps a customer profile of its payers: made
|
|
// once with everything known, and brought up to date at a later checkout when the
|
|
// profile is missing a field or holds a different one. The issuer and the
|
|
// processor's risk checks read the profile, so a payer the processor knows nothing
|
|
// about is declined more often.
|
|
type PayerProfiles interface {
|
|
// CreateCustomerFor makes the payer's customer under reference (found again by
|
|
// it) and returns its id.
|
|
CreateCustomerFor(ctx context.Context, p Payer, reference string, metadata map[string]interface{}) (string, error)
|
|
// ProfileCustomer sets the fields of p that the customer lacks or holds
|
|
// differently. It writes nothing when the profile already matches.
|
|
ProfileCustomer(ctx context.Context, customerID string, p Payer) error
|
|
}
|
|
|
|
// StatementSuffix is what follows the account's statement descriptor on a
|
|
// cardholder's statement, so the charge is recognized as Hanzo's.
|
|
const StatementSuffix = "HANZO AI"
|