This repository contains a reference implementation of the Commerce Extensibility Framework. It includes sample code for extending the following services:
- Domain Extensions for Cart Calculate API:
- Pricing
- Promotion
- Shipping Calculator
- Tax Calculator
- Tax Service
- Domain Extension for Checkout
- Checkout Create Order
Each set of sample code includes: an Apex class, a test class, and any necessary resource files.
Live Heroku services are used to simulate a connection to a third-party system. You can bypass the Heroku service and use mocked data instead.
Warning: The sample code and Heroku services are provided "as is" for demonstration purposes only. Do not use the source code in a production system without modifying and testing it first. And do not use the Heroku services in a production system under any circumstances.
The sample code for Pricing Service includes an Apex class (in PricingServiceSample.apxc
) that calls an external service to retrieve product prices and then saves that price in the PricingResponseItems
list.
The sample code for Pricing Calculator includes an Apex class (in PricingCalculatorSample.apxc
) that calls an external service to retrieve pricing information and then save those taxes in CartItem
.
The sample code for Promotion Calculator includes an Apex class (in PromotionCalculatorSample.apxc
) that updates price adjustments for each CartItem
based on promotion applied.
The sample code for Shipping Calculator includes an Apex class (in ShippingCalculatorSample.apxc
) that calls an external service to retrieve shipping rates and then save that rate as an additional charge in the CartItems
list.
The sample code for Tax Calculator includes an Apex class (in TaxCalculatorSample.apxc
) that calls an external service to retrieve tax information and then save those taxes in CartTaxes
in CartItems
and CartItemAdjustments
.
The sample code for Tax Service includes the following Apex classes :
- an Apex class (in
TaxServiceSample.apxc
) that calls an external service to retrieve tax calculation data and then saves that in theCalculateTaxesResponseLineItem
list. - an Apex class (in
TaxServiceExtensionResolverSample.apxc
) which selects different resolution states (EXECUTE_DEFAULT, EXECUTE_REGISTERED and OFF) for different locales to execute respective implementations (Extension Providers or the Default Salesforce Internal Tax Api).
In order to propagate an error message to the shopper use CartValidationOutput. Throwing an Exception from any Orchestrator or Calculator would result into CartValidationOutput created on the Cart with generic error message based on Calculator type. Special case CartCalculateRuntimeException can be used to rollback all calculation applied to the Cart withing given request processing boundaries. All error cases are propagated to the admin as CommerceDiagnosticEvents (see CommerceDiagnosticEvent)
All reference implementations include examples of how to propagate an error to the user.
The sample code for Checkout Create Order extension point includes an Apex class (see CreateOrderSample.cls that provides an example of how to work with the OrderGraph.
A unit test (see CreateOrderSampleUnitTest.cls)) that follows this approach for Mocking the Base Apex Class in Tests.
Also, there is an "integration" test (see CreateOrderSampleIntegrationTest.cls) that verifies implementation of the CreateOrder extension that calls real default extension point behavior. This testing approach can be used in addition to unit test, it has wider test coverage, but it is less isolated than unit test presented in the example below.
To deploy this reference implementation, use Workbench:
- Clone this repository.
- From this folder, create a .zip file:
zip -r -X <your-zip-file>.zip *
- Open Workbench and go to Migration > Deploy.
- Select the file you created (
<your-zip-file>.zip
). - Check the Single Package checkbox.
- Click Next.
- Click Deploy.
We are not currently accepting external contributions to this repository.
We are not currently tracking issues through GitHub. If you’re experiencing an issue with the sample code, reach out to your Salesforce representative.
We expect all users of this repository to follow the Salesforce Open Source Community Code of Conduct.
Please report any security issue to security@salesforce.com as soon as it is discovered.
The sample code is licensed under a BSD 3-Clause license. See the license for details.
This repository may contain forward-looking statements that involve risks, uncertainties, and assumptions. For more information, see STATEMENTS.