External tax calculators
The external tax calculator object and the allowed CRUD operations on the related resource endpoint
External tax calculators let you delegate tax calculation logic to an external service — whether a different provider from the ones supported out-of-the-box, or a completely custom solution. This way, you can use the order payload to compute your own logic and return the tax rate to be applied to the order.
To create an external tax calculator, choose a meaningful name that helps you identify it within your organization and set the tax_calculator_url attribute to the endpoint you have configured externally. Whenever the tax calculation is fired, Commerce Layer triggers a POST request to that endpoint, sending the order payload in the request body — by default, the payload includes the order's line items, though you can customize which related resources are included via the external_includes attribute. The external service response (or error) must match the format described in this example.
External tax calculators are subject to a circuit breaker check: if the call to your external endpoint fails consecutively more than 30 times, the circuit breaker opens and any further request to the resource will be skipped. You can check the circuit breaker's current status by fetching the circuit_state and circuit_failure_count attributes, or manually reset it by passing the _reset_circuit trigger (the circuit is automatically reset anytime a call to your external endpoint succeeds before reaching the counter's threshold).
Last updated