TaxEngineContext Class
Namespace
Example
At the beginning of a tax adapter, use TaxEngineContext class to pass the value of a request type to an instance of RequestType.
global virtual class MockAdapter implements commercetax.TaxEngineAdapter {
global commercetax.TaxEngineResponse processRequest(commercetax.TaxEngineContext taxEngineContext) {
commercetax.RequestType requestType = taxEngineContext.getRequestType();
commercetax.CalculateTaxRequest request = (commercetax.CalculateTaxRequest)taxEngineContext.getRequest();
Build the rest of your adapter based on the type of request that you got from TaxEngineContext class.
if(requestType == commercetax.RequestType.CalculateTax){
commercetax.calculatetaxtype type = request.taxtype;
String docCode='';
if(request.DocumentCode == 'simulateEmptyDocumentCode')
docCode = '';
else if(request.DocumentCode != null)
docCode =request.DocumentCode;
else if(request.ReferenceEntityId != null) docCode = request.ReferenceEntityId;
else docCode = String.valueOf(getRandomInteger(0,2147483647));
commercetax.CalculateTaxResponse response = new commercetax.CalculateTaxResponse();
if(request.isCommit == true) {
response.setStatus(commercetax.TaxTransactionStatus.Committed);
} else {
response.setStatus(commercetax.TaxTransactionStatus.Uncommitted);
}
}
TaxEngineContext Constructors
The TaxEngineContext class includes these constructors.
TaxEngineContext(request, requestType, namedUri)
Signature
TaxEngineContext(commercetax.TaxEngineRequest request, commercetax.RequestType requestType, String namedUri)
Parameters
- request
- Type: TaxEngineRequest
- Information about the request.
- requestType
- Type: RequestType
- Whether the tax request is to calculate or estimate tax.
- namedUri
- Type: String
- URI that was called as part of the tax calculation request.
TaxEngineContext Methods
The TaxEngineContext class includes these methods.
getRequest()
Signature
global commercetax.TaxEngineRequest getRequest()
Return Value
Type: TaxEngineRequest
An implemented instance of an external tax engine's interface for processing requests. We've provided the TaxEngineRequest interface for you to test within mock adapters with classes that implement it, such as CalculateTaxRequest. However, don’t use it outside of a testing context.
getRequestType()
Signature
global commercetax.RequestType getRequestType()
Return Value
Type: RequestType
Indicates whether the calculation request was for actual or calculated tax.