Developer notes
Stripe API calls
Section titled “Stripe API calls”All calls follow the Stripe API reference (API version pinned with the Stripe-Version header, HTTP Basic authentication with the key, form-encoded bodies, an Idempotency-Key on every POST, User-Agent CS-Cart KavioStripeTax/<version> (https://cs-cart.kaviolabs.com)).
| Call | When | Reference |
|---|---|---|
POST /v1/tax/calculations (expand[]=line_items) |
checkout, admin order editing, test calculation | https://docs.stripe.com/api/tax/calculations/create |
POST /v1/tax/transactions/create_from_calculation |
order reaches a record status, Retry, cron | https://docs.stripe.com/api/tax/transactions/create_from_calculation |
POST /v1/tax/transactions/create_reversal (mode=full, mode=partial + flat_amount) |
reverse status, order card | https://docs.stripe.com/api/tax/transactions/create_reversal |
GET /v1/tax/settings |
connection test | https://docs.stripe.com/api/tax/settings/retrieve |
Guides followed: https://docs.stripe.com/tax/custom (shipping cost, tax-inclusive pricing, tax IDs, taxability override, ship-from address, retail delivery fee) and https://docs.stripe.com/tax/off-stripe (address precision, transactions, full / partial / flat-amount reversals, undoing partial reversals).
Request mapping: currency = store primary currency (lower case); line_items[].amount = line total after discounts in the smallest currency unit (lines with 0 are not sent), quantity, reference (product code when unique in the cart, else p<product id>-<n>), tax_behavior (setting), tax_code; shipping_cost (amount > 0, tax_code, tax_behavior); customer_details.address (line1, line2, city, state, postal_code, country) + address_source; customer_details.taxability_override (customer_exempt | reverse_charge); customer_details.tax_ids[]; ship_from_details.address.
How the tax gets into the cart
Section titled “How the tax gets into the cart”CS-Cart computes taxes per product group in fn_calculate_taxes() (identical from 4.17.2 to 4.21.2). The add-on uses existing hooks only:
calculate_cart_taxes_pre: remembers the product groups (vendor orders).calculate_taxes_pre: builds the request, reads the cache or calls Stripe (checkout / order editing / REST API only), and when Stripe decides, empties the group’s coretax_idsso core computes nothing.get_shipping_taxes_post: no core shipping taxes for that group.calculate_taxes_post: writes the Stripe amounts as add-on tax lines, one per distinct rate (rate_type P with the true percentage; a flat retail delivery fee as a flat line on shipping), keyed above the core tax id range (20000000 + rate x 1000, no ?:taxes row), in the shape of the configured method (Unit price:P_<cart id>/S_<group>_<shipping>entries and producttax_summary; Subtotal: one entry per line withappliesP / S / items), and restores thetax_ids. Core’s recalculation of stored taxes (order editing without the add-on) therefore keeps the amounts.- Order editing: orders with add-on tax lines are recalculated by Stripe; when Stripe gives no result,
stored_taxesis set back to Y for the group (previous lines kept) and the row gets the noteedit_not_recalculated. pre_place_order: “do not accept the order” mode.place_order/change_order_status_post: order record, transaction, reversal.
Payment surcharge taxes stay with the core settings.
Tables
Section titled “Tables”?:kv_stx_calcs (calculation cache by request hash: amounts, country / state / postal code, no names or street lines), ?:kv_stx_orders (order to calculation / transaction), ?:kv_stx_reversals, ?:kv_stx_codes (product / category tax codes), ?:kv_stx_log. Orders, reversals and codes survive uninstall unless the purge setting is on.
Idempotency
Section titled “Idempotency”The order row is claimed (UPDATE ... WHERE status IN (...), one winner) before the transaction POST. The Idempotency-Key is derived from the calculation id and the reference, so a retry returns Stripe’s first answer within 24 hours; after that the unique reference stops a second transaction. Reversal rows (unique reference) are written before their POST and retried with the same key.
php admin.php --dispatch=kv_stripe_tax.cron or index.php?dispatch=kv_stripe_tax.cron&key=<key> (the URL and key are shown in the settings). Retries failed recordings (5 min, 15 min, 1 h, 3 h, 12 h), records calculated orders already in a record status, prunes the log and the cache.
Testing against a mock
Section titled “Testing against a mock”$config['kv_stripe_tax_base_url'] = 'http://127.0.0.1:<port>'; in config.local.php sends every call to a local stand-in. Only loopback addresses are accepted.
Full page cache (4.21)
Section titled “Full page cache (4.21)”The add-on prints nothing on cacheable storefront pages and calls Stripe only in checkout requests, which are never cached.