At-cost services (IRP/IFTA/intrastate) only collected our service fee at
checkout; the variable state fee was never billed, so orders stalled at
authorization_signed and the filing card would have had to front large IRP fees.
New end-to-end, hands-off flow (you only approve the final filing):
1. After authorization is signed, state_trucking auto-estimates the gov fee
from intake (base/op states, power units, weight) via gov_fee.estimate_gov_fee.
2. Creates a CHILD compliance order (CG-..., service_fee=0, gov_fee=estimate,
parent_order_number set, migration 099) that flows through the EXISTING
checkout/payment/webhook machinery.
3. Emails the customer a payment link to /order/pay (new self-contained page)
showing every method with correct surcharges — ACH 0% (Stripe 0.8%/ cap
absorbed, no GoCardless needed), card/PayPal 3%, Klarna 6%, crypto 0%.
4. Order holds at awaiting_government_fee_approval until paid.
5. On payment, handlePaymentComplete detects the child (parent_order_number)
and re-dispatches the PARENT with gov_fee_paid=true, which proceeds to
prepare + queue the filing and stops at ready_to_file for your approval.
IRP fees are estimates billed at cost (refund overage / rebill shortfall); IFTA
decals + most intrastate fees are near-exact. Tunable via env.
20 lines
986 B
SQL
20 lines
986 B
SQL
-- 099: Government-fee child orders for at-cost compliance services.
|
|
--
|
|
-- At-cost services (IRP, IFTA, intrastate authority, etc.) collect only our
|
|
-- SERVICE fee at checkout; the actual government/state fee is variable and
|
|
-- "billed at cost" afterward. To collect it we create a CHILD compliance_orders
|
|
-- row (service_fee_cents = 0, gov_fee_cents = the quoted state fee) that flows
|
|
-- through the EXISTING checkout/payment-picker/webhook machinery unchanged, and
|
|
-- email the customer a payment link with every payment method + correct
|
|
-- surcharges. parent_order_number links that child back to the original order so
|
|
-- the worker can resume filing once the fee is paid.
|
|
--
|
|
-- Idempotent.
|
|
|
|
ALTER TABLE compliance_orders
|
|
ADD COLUMN IF NOT EXISTS parent_order_number text;
|
|
|
|
-- Look up a parent's gov-fee children quickly (and vice-versa).
|
|
CREATE INDEX IF NOT EXISTS idx_compliance_orders_parent
|
|
ON compliance_orders (parent_order_number)
|
|
WHERE parent_order_number IS NOT NULL;
|