Extension Point: Tax Calculator
Basics
Parameter | Value |
---|---|
Extension Point Key | TAX_CALCULATOR |
Extension Point Name | Tax Calculator |
Extension Interface | TaxCalculator |
Supports Multiple Extensions? | No |
Selector Type | Store |
Available Since | 1.1.0 |
note
This extension point only supports a single extension, so if multiple are defined, the highest priority extension will be invoked.
Use Cases
Extensions implementing this Extension Point should return the tax details for all items in the shopping cart. Extensions will also be notified when taxes should be committed to a data store for remittance, or deleted from the data store due to cancellation.
There is an embedded extension named ElasticPathTaxCalculator
with priority 1010 that uses the tax configuration from the Elastic Path database to determine taxes.
note
This Extension Point supports extensions that may not use tax regions and tax values that are configured within the Commerce Manager.
Methods
calculate
The calculate
method is invoked whenever Cortex needs to determine taxes for a shopping cart, such as when the cart total or tax resources are retrieved. The following information is passed to the method:
taxableItems
: All items in the shopping cart.store
: The current store.currency
: The session currency.originAddress
: The address where the item will originate; usually this is the store’s configured warehouse address.destinationAddress
: The address where the item will be shipped. For non-physical products this will be set to the billing address.customer
: Information about the shopper.journalType
: Indicates whether taxes are being calculated for a purchase or a reversal.documentId
: The shopping cart GUID or shipment identifier.taxInclusive
: Indicates whether the session region requires taxes to be inclusive in the final price.taxExemptionId
: An identifier indicating that the shopper is tax exempt.taxOverride
: Used for reversals, to indicate information about the original purchase tax calculation.
The extension is responsible for returning a list of XPFTaxedItem
objects that contain the original taxable item and a list of XPFTaxRecord
objects with the breakdown of applicable taxes.
commit
The commit
method is invoked when a shopping cart is converted to a purchase. This method should be used to notify the tax service that taxes are being collected from a shopper, and therefore must be remitted to the appropriate tax agency.
delete
The delete
method is invoked when a purchase is cancelled. This method should be used to notify the tax service that tax information that was previously committed should be deleted and no longer needs to be remitted.
Extension Sample
@Extension
@XPFAssignment(extensionPoint = XPFExtensionPointEnum.TAX_CALCULATOR, priority = 10)
public class SampleTaxCalculator extends XPFExtensionPointImpl implements TaxCalculator {
private static final String PROVIDER_NAME = "Sample Tax Calculator";
@Override
public XPFTaxedItems calculate(final XPFTaxCalculationContext context) {
final List<XPFTaxedItem> taxedItems = new ArrayList<>(context.getTaxableItems().size());
for (XPFTaxableShoppingItem taxableItem : context.getTaxableItems()) {
final List<XPFTaxRecord> taxRecords = new ArrayList<>();
final XPFTaxRecord xpfTaxRecord = new XPFTaxRecord(
taxableItem.getTaxabilityCode(),
taxName, // i.e. "GST" or "CA State Tax"
taxRate, // i.e. 0.02 for 2%
taxJurisdiction, // i.e. "CA" for Canada or "US" for United States
taxRegion, // i.e. "BC" or "WA"
taxAmount, // i.e. 0.20 if the tax amount applied to this line item is 20 cents
PROVIDER_NAME);
taxRecords.add(xpfTaxRecord);
taxedItems.add(new XPFTaxedItem(taxableItem, taxRecords));
}
return new XPFTaxedItems(taxedItems);
}
@Override
public void commit(final XPFTaxDocumentContext xpfTaxDocumentContext) {
//not implemented
}
@Override
public void delete(final XPFDeleteTaxDocumentContext xpfTaxDocumentContext) {
//not implemented
}
}