stripe_transactions gets a nullable `tax` column: the VAT inside the
row's amount, in signed cents like amount, NULL = unknown.
- Charges/payments: the charge's invoice tax (tax, else total_tax_amounts
/ total_taxes) pro-rated by captured amount over invoice total, so a
partly credit-paid invoice counts only the cash part; without an invoice,
the Checkout Session of the payment intent (total_details.amount_tax).
- refund, payment_refund, payment_failure_refund, refund_failure carry the
same share of the charge's VAT as their amount, signed like it.
- Fees, payouts, transfers, disputes and PayPal rows stay NULL.
- syncLedgerForCharge expands charge.invoice (falls back without it on API
versions that lack Charge.invoice). A charge and its refunds share one
lookup; refunds reuse the charge's ledger row; a re-import keeps a known
value without a Stripe call. Stripe holding no VAT data is marked
meta.tax_source=none and not asked again. A failed lookup leaves NULL and
never breaks the import.
- shop:import-stripe-ledger --backfill-tax [--dry-run] [--since] [--recheck]
and Shop::backfillLedgerTax() fill missing VAT read-only, idempotently.
- ledgerTotals, revenueLedgerByDay, ledgerTotalsByAccount and
customerLedgerTotals gain a `tax` key (SUM(COALESCE(tax,0))); existing
keys unchanged. Before the migration runs, rows save without tax and
tax reads 0.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Without credentials the PayPal import was a silent no-op, so an app could
lose its PayPal fees from revenue without anyone noticing. With
shop.paypal.required on, a missing account, missing migration or a failed
account import throws (after every account was tried), which the host's
scheduler failure handling can alert on. Default off.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
payment_failure_refund (a SEPA/ACH payment that bounced, with its failure
fee) and Stripe's account-level fees (stripe_fee, stripe_fx_fee, tax_fee)
were not revenue types, so a bounced payment still counted as income and
Billing/Tax fees never lowered net. Both are revenue types now. Account
fees arrive from Stripe as a negative amount; the ledger stores them as
fee with amount 0 so they do not show up as refunds. The daily full
import rewrites existing rows.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
PayPal checkouts that run through Stripe settle into our PayPal account.
Stripe's ledger row books the gross and Stripe's fee, but PayPal takes its
own fee inside the PayPal account, so net revenue was overstated.
- Ledger rows carry `provider` (stripe, paypal) and `account`; existing
rows default to stripe.
- shop:import-paypal-ledger reads every account in shop.paypal.accounts
through the Transaction Search API (read-only) and upserts one row per
PayPal transaction. Stripe-originated payments and refunds add a
`paypal_fee` row (amount 0, net -fee); payments PayPal swept on to
Stripe are booked as `paypal_fee_passthrough`, because Stripe's fee
already holds PayPal's. Direct PayPal sales count in full; holds,
sweeps and withdrawals are non-revenue.
- `paypal_fee` joins the default revenue types.
- Stripe rows keep their payment intent in meta so PayPal rows find the
buyer.
- Shop::ledgerTotalsByAccount() splits the totals per account.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>