mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
This PR moves the client-side "Charge Today" calculation to the backend - relying on the `preview` endpoint data to show the `Charge Today`, `Prorated Credits` and `Customer Balance` in the Subscription Upgrade Preview. It also includes fields for displaying Tax information in the preview, only for enabled orgs. Do note that at the moment the Tax Preview will not change if the address in the Subscription Preview changes, that will be tackled in a follow-up PR. ## Changes - Replace client-side charge calculation with backend data: The upgrade dialog previously computed the prorated credit and total charge locally (using subscription period timestamps and plan prices). This PR uses the `upfront_charge` object returned by the subscription preview API instead. - Display itemized tax breakdown: When the backend returns tax data, the dialog now shows a line-by-line breakdown: plan cost → subtotal (if different) → tax (with rate %) → total charged today. - Use `tax_status` from the subscription preview to conditionally show tax details, and display a warning when tax calculation fails. ## Testing ### No taxes - Upgrade from Free to Paid Plan - With a Free Org with a billing address in Canada or any other non-enabled jurisdiction, start the upgrade to the Pro Plan - Assert that only the Charge Today field is shown in the summary <img width="410" height="298" alt="image" src="https://github.com/user-attachments/assets/e8c7e12e-833d-41d5-aec3-00092b12782f" /> ### Taxes - Upgrade Plan - Update an Org's Orb Customer on the Free or Pro Plan with the `automatic_tax_enabled: true` flag. ``` curl --location --request PUT 'https://api.withorb.com/v1/customers/external_customer_id/{ORG_SLUG}' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'Authorization: ••••••' \ --data '{ "tax_configuration": { "tax_exempt": false, "tax_provider": "numeral", "automatic_tax_enabled": true } }' ``` - Update the Org address to a valid taxable address, like: ``` "address": { "country": "US", "line1": "100 Congress Ave", "city": "Austin", "state": "TX", "postal_code": "78701" } ``` - Assert that the tax information is shown in the preview, including Tax Rate, Prorated credits (if applicable), Customer balance (if applicable) and the price of the intended plan. <img width="465" height="470" alt="image" src="https://github.com/user-attachments/assets/dd6a7e27-1708-48a8-bbf3-5435e6d582c2" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added itemized breakdown of subscription charges, including plan cost, unused time credits, subtotal, and applicable taxes. * Enhanced billing estimates with detailed tax information display. * **Improvements** * Updated "Charge today" calculations to reflect real-time preview data for greater accuracy. * Improved billing estimate UI layout and clarity with better organization of charge details. <!-- end of auto-generated comment: release notes by coderabbit.ai -->