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>