Foundations Apex API Developer Reference

fferpcore.TaxCalculationService

global with sharing class TaxCalculationService

This class provides the functionality required to connect to an external tax calculation service.

Enums

AddressTextCase

The letter case to use for the validated address.

Value Description
MIXED Return the validated address in the letter case used by the provider.
UPPER Return the validated address in capital letters.

DocumentType

Value Description
SALE Represents a sale that your company made to a customer.
PURCHASE Represents a purchase made by your company from a vendor.

DetailLevel

The level of detail to be returned from the tax service.

Value Description
TAX Header, summary, and line information, including jurisdiction details on lines.
LINE Header, summary, and line information, excluding jurisdiction details on lines.
SUMMARY Header and summary information only.

VoidRequestReason

Value Description
UNSPECIFIED No reason has been provided for the return.
POST_FAILED Tax calculation on the document has failed.
DOCUMENT_DELETED The original document was deleted.
DOCUMENT_VOIDED The original document is now void.
ADJUSTMENT_CANCELLED A previous adjustment to the original document is no longer necessary.

Methods

getSettings

global static fferpcore.TaxCalculationService.Settings getSettings()

Gets the saved tax calculation settings.

Return Value

A Settings DTO that contains the tax calculation settings excluding the password/license key.

saveSettings

global static fferpcore.TaxCalculationService.SaveSettingsResponse saveSettings(fferpcore.TaxCalculationService.Settings settings)

Saves the modified settings. If the password is empty, the existing password/license key is not overwritten.

Input Parameters

Name Type Description
settings fferpcore.TaxCalculationService.Settings The settings DTO to be saved.

isEnabled

global static Boolean isEnabled()

Determines whether external tax calculation is enabled.

Return Value

True if the endpoint service is enabled.

testConnection

global static fferpcore.TaxCalculationService.TestConnectionResponse testConnection(fferpcore.TaxCalculationService.Settings settings)

Calls the external tax calculation service with the saved settings to validate values. This method bypasses the enabled flag.

Return Value

A Response object that contains the state of the connection and errors that occurred.

validateAddress

global static fferpcore.TaxCalculationService.ValidateAddressResponse validateAddress(fferpcore.TaxCalculationService.Address address)

Calls the external tax calculation service with the address to be validated.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A ValidateAddressResponse object that contains the validated address.

calculateTax

global static fferpcore.TaxCalculationService.TaxResponse calculateTax(fferpcore.TaxCalculationService.TaxDocument document)

Calls the external tax calculation service with the document for which tax is to be calculated.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A TaxResponse object that contains the tax values for the document.

commitTax

global static fferpcore.TaxCalculationService.TaxResponse commitTax(fferpcore.TaxCalculationService.TaxDocument document)

Calls the external tax calculation service with a document for which tax is to be calculated and committed.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A TaxResponse object that contains the tax values for the document.

commitTax

global static fferpcore.TaxCalculationService.TaxResponse commitTax(fferpcore.TaxCalculationService.CommitRequest request)

Calls the external tax calculation service with a request to commit a draft document.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A TaxResponse object that contains the tax values for the document.

calculateReversal

global static fferpcore.TaxCalculationService.ReversalResponse calculateReversal(fferpcore.TaxCalculationService.CreditDocument document)

Calls the external tax calculation service with a credit document for which tax is to be calculated. The monetary values in the document are expected to be positive. The returned tax values will also be positive.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A ReversalResponse object that contains the tax values for the credit document.

commitReversal

global static fferpcore.TaxCalculationService.ReversalResponse commitReversal(fferpcore.TaxCalculationService.CreditDocument document)

Calls the external tax calculation service with a credit document for which tax is to be calculated and committed. The monetary values in the document are expected to be positive. The returned tax values will also be positive.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A ReversalResponse object that contains the tax values for the credit document.

commitReversal

global static fferpcore.TaxCalculationService.ReversalResponse commitReversal(fferpcore.TaxCalculationService.CommitRequest request)

Calls the external tax calculation service with a request to commit a draft return document. The returned tax values will be positive.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A ReversalResponse object that contains the tax values for the credit document.

uncommitTax

global static fferpcore.TaxCalculationService.UncommitResponse uncommitTax(fferpcore.TaxCalculationService.UncommitRequest request)

Calls the external tax calculation service with a request to uncommit a document.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

An UncommitResponse object.

uncommitReversal

global static fferpcore.TaxCalculationService.UncommitResponse uncommitReversal(fferpcore.TaxCalculationService.UncommitRequest request)

Calls the external tax calculation service with a request to uncommit a return document.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

An UncommitResponse object.

voidTax

global static fferpcore.TaxCalculationService.VoidResponse voidTax(fferpcore.TaxCalculationService.VoidRequest request)

Calls the external tax calculation service with a request to void a previously committed tax document.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A VoidResponse object.

voidReversal

global static fferpcore.TaxCalculationService.VoidResponse voidReversal(fferpcore.TaxCalculationService.VoidRequest request)

Calls the external tax calculation service with a request to void a previously committed credit document.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A VoidResponse object.

unvoidTax

global static fferpcore.TaxCalculationService.UnvoidResponse unvoidTax(fferpcore.TaxCalculationService.UnvoidRequest request)

Calls the external tax calculation service with a request to unvoid a previously voided document.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

An UnvoidResponse object.

unvoidReversal

global static fferpcore.TaxCalculationService.UnvoidResponse unvoidReversal(fferpcore.TaxCalculationService.UnvoidRequest request)

Calls the external tax calculation service with a request to unvoid a previously voided credit document.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

An UnvoidResponse object.

verifyTax

global static fferpcore.TaxCalculationService.VerifyResponse verifyTax(fferpcore.TaxCalculationService.VerifyRequest request)

Calls the external tax calculation service with a request to verify a previously created uncommitted document.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A VerifyResponse object.

verifyReversal

global static fferpcore.TaxCalculationService.VerifyResponse verifyReversal(fferpcore.TaxCalculationService.VerifyRequest request)

Calls the external tax calculation service with a request to verify a previously created uncommitted return document. The monetary values in the request are expected to be positive.
This method might result in DML if logging is enabled and prevent further callouts. To defer DML until all callouts have been performed, see the createWorkScope() method.

Return Value

A VerifyResponse object.

createWorkScope

global static fferpcore.Disposable createWorkScope()

Creates a scope to facilitate grouping tax operations together. Scopes can be nested.
This causes the logging system to defer its database writes until the end of the outermost work scope. It is necessary when performing multiple callouts to prevent a Salesforce exception.

Return Value

A Disposable object.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

public void calculateTax(List<Document> documents)
{
    fferpcore.Disposable workScope = fferpcore.TaxCalculationService.createWorkScope();
    try
    {
        for(Document document : documents)
        {
            // The calculateTax method marshals the Document, calculates tax and unmarshals
            // the result.
            calculateTax(document);
        }
    }
    finally
    {
        // Use of try-finally ensures that the work scope is always disposed,
        // even if calculateTax results in an exception.
        workScope.dispose();
    }
}

fferpcore.TaxCalculationService.Settings

global inherited sharing class Settings

This class wraps the tax calculation settings in a Salesforce org.

Properties

Name Type Description
Enabled Boolean Indicates whether tax is calculated using the external service.
DisableCommit Boolean Indicates whether committing data to the external tax calculation service should be prevented.
Provider String The name of the class that interfaces with the external tax calculation service.
General String A JSON blob that contains the general settings which can be displayed on the user interface.
Secret String A JSON blob that contains the secret settings which cannot be displayed on the user interface. This value is masked when returned from the getSettings() call in the TaxCalculationService.
SecretSpecified Boolean Indicates whether secret data was provided. The value is true if secret data was provided and is false otherwise.

Methods

Settings

global Settings()

Constructs a new Settings object that is disabled by default.

fferpcore.TaxCalculationService.AdvancedMessage

global inherited sharing class AdvancedMessage

fferpcore.Message data with enhanced information.

Properties

Name Type Description
Code String The identifier for the message.
Description String Detailed message information.
HelpLink String The URL that links to the specified message name.
Level fferpcore.Message.MessageLevel The severity of the message.
Name String The type of message.
Origin String The entity from where the message was originally generated.
TargetEntity String The element for which the message was generated.
Text String The message summary.

fferpcore.TaxCalculationService.Response

global inherited sharing virtual class Response

Data returned from the external tax provider.

Properties

Name Type Description
Success Boolean True if the request was successful, false otherwise.
Messages List<fferpcore.Message> A list of any associated messages.
AdvancedMessages List<fferpcore.TaxCalculationService.AdvancedMessage> A list of any associated detailed messages.

fferpcore.TaxCalculationService.SaveSettingsResponse

global inherited sharing class SaveSettingsResponse extends Response

Data concerning an attempt to save settings.

This class extends fferpcore.TaxCalculationService.Response

Properties

Name Type Description
Validated Boolean True if the settings have been validated, false otherwise.

Methods

SaveSettingsResponse

global SaveSettingsResponse()

SaveSettingsResponse

global SaveSettingsResponse(fferpcore.TaxCalculationService.TestConnectionResponse response)

fferpcore.TaxCalculationService.TestConnectionResponse

global inherited sharing class TestConnectionResponse extends Response

Data returned from the external tax provider following a connection test.

This class extends fferpcore.TaxCalculationService.Response

fferpcore.TaxCalculationService.ValidateAddressResponse

global inherited sharing class ValidateAddressResponse extends Response

Data returned from the external tax provider after validating an address.

This class extends fferpcore.TaxCalculationService.Response

Properties

Name Type Description
Address fferpcore.TaxCalculationService.ValidatedAddress The validated address as determined by the external tax provider.

fferpcore.TaxCalculationService.TaxResponse

global inherited sharing virtual class TaxResponse extends Response

Data returned from the external tax provider after calculating tax.

This class extends fferpcore.TaxCalculationService.Response

Properties

Name Type Description
TaxLines List<fferpcore.TaxCalculationService.TaxResponseLine> A list of tax response lines providing tax information respective to each line provided.
Committed Boolean True if the document was committed, false otherwise.
TaxSummary List<fferpcore.TaxCalculationService.TaxDetail> Tax details by jurisdiction.
TotalTax Decimal The total tax value for all lines of the document.
DocumentCode String The identifier for the tax document. This value matches the DocumentCode in the request, if provided. If the value in the request is null or blank, the DocumentCode is determined by the external tax provider.
DocumentId String The unique identifier for the tax document provided by the external tax provider.

Methods

TaxResponse

global TaxResponse()

fferpcore.TaxCalculationService.TaxResponseLine

global inherited sharing class TaxResponseLine

Data concerning the calculated tax for a provided request line.

Properties

Name Type Description
LineNo String A line identifier matching the provided request line.
Rate Decimal The calculated rate of tax as a fractional value, ranging from 0.0 for no tax to 1.0 for 100% tax. This value is not provided if the DetailsToInclude property in the request is LINE. An effective rate can be calculated by dividing the Tax value by the Taxable value.
Tax Decimal The calculated tax value for the given amount.
Taxable Decimal The amount that is taxable.
Exemption Decimal The amount that is exempt from tax.
Discount Decimal The amount of discount applied if the document level Discount is used.
TaxDetails List<fferpcore.TaxCalculationService.TaxDetail> Tax details by jurisdiction.
Amount Decimal The total amount of the line, including both taxable and exempt values.

fferpcore.TaxCalculationService.Address

global inherited sharing virtual class Address

Data concerning an address.

Properties

Name Type Description
Line1 String Street Address / P.O Box / Company Name
Line2 String Apartment Suite / Unit / Building / Floor
Line3 String Third line of the address.
City String Town / City
Region String County / State
PostalCode String Post code for the area.
Country String Country
TextCase fferpcore.TaxCalculationService.AddressTextCase Letter case for the validated address returned in the validation response.
Latitude Decimal Geocoded latitude value of the address.
Longitude Decimal Geocoded longitude value of the address.

fferpcore.TaxCalculationService.ValidatedAddress

global inherited sharing class ValidatedAddress extends Address

Data concerning a validated address.

This class extends fferpcore.TaxCalculationService.Address

Properties

Name Type Description
AddressType String Type of address such as residential or company.
County String County of the address.
FipsCode String Unique 10-digit code representing each geographic combination of state, county, and city.
CarrierRoute String Four-character string representing a US postal carrier route.
TaxRegionId String Identifier for the region.
PostNet String 12-digit barcode containing the ZIP Code, ZIP+4 Code, and the delivery point code. Used by the USPS to direct mail.

Methods

ValidatedAddress

global ValidatedAddress()

fferpcore.TaxCalculationService.DocumentIdentity

global inherited sharing virtual class DocumentIdentity

Data that identifies a document.

Properties

Name Type Description
CompanyCode String Code corresponding to a company.
DocumentCode String Identifier for the document.
Type fferpcore.TaxCalculationService.DocumentType Type of document to create, such as SALE or PURCHASE. This can be used for the calculateTax, commitTax, and voidTax methods. Type is not supported for reversal methods and is expected to be null, if provided.

Methods

DocumentIdentity

global DocumentIdentity()

Default constructor.

DocumentIdentity

global DocumentIdentity(String companyCode, String documentCode)

Construct a document identity with the given company code and document code.

Input Parameters

Name Type Description
companyCode String Code corresponding to a company
documentCode String Identifier for the document.

fferpcore.TaxCalculationService.TaxDocument

global inherited sharing virtual class TaxDocument extends DocumentIdentity

Document data provided to the external tax calculation service to calculate tax.

This class extends fferpcore.TaxCalculationService.DocumentIdentity

Properties

Name Type Description
ClientName String Name of the client requesting calculation.
ClientVersion Version Version of the client requesting calculation.
CustomerCode String Code identifying the customer.
DocumentDate Date Date associated with the document.
CustomerUsageType String Type of usage. Determines the exemption status of the transaction.
Discount Decimal Discount amount to apply to the document.
ExemptionNumber String Number corresponding to the associated exemption certificate.
PurchaseOrderNumber String Associated customer purchase order number.
LocationCode String Value assigned by some State jurisdictions that identifies a particular store location.
TaxDate Date Date for which tax is to be calculated.
TaxOverrideReason String Reason for overriding tax. This value is set only when TaxDate is provided.
CurrencyISOCode String ISO code of the associated currency.
ShipFromAddress fferpcore.TaxCalculationService.Address Address the item is being sent from.
ShipToAddress fferpcore.TaxCalculationService.Address Address the item is being sent to.
Lines List<fferpcore.TaxCalculationService.TaxRequestLine> List of lines detailing the associated items and their quantities.
BusinessIdentifier String The buyer’s VAT ID. If a value is set, VAT rules are used for the transaction.
DetailsToInclude fferpcore.TaxCalculationService.DetailLevel The level of detail to include in the tax response. If null, all details are returned.
CreateTransaction Boolean Indicates whether to create a transaction in the external service when calculating tax. This option does not commit tax.

fferpcore.TaxCalculationService.CommitRequest

global inherited sharing class CommitRequest

Data provided to the external tax calculation service to commit an existing document.

Properties

Name Type Description
Document fferpcore.TaxCalculationService.DocumentIdentity The existing document to commit.
DetailsToInclude fferpcore.TaxCalculationService.DetailLevel The level of detail to include in the tax response. If null, all details are returned.

Methods

CommitRequest

global CommitRequest()

CommitRequest

global CommitRequest(fferpcore.TaxCalculationService.DocumentIdentity document, fferpcore.TaxCalculationService.DetailLevel detailsToInclude)

Construct a commit request for an existing document, specifying the level of detail to include in the tax response.

Input Parameters

Name Type Description
document fferpcore.TaxCalculationService.DocumentIdentity The existing document to commit.
detailsToInclude fferpcore.TaxCalculationService.DetailLevel The level of detail to include in the tax response.

fferpcore.TaxCalculationService.TaxRequestLine

global inherited sharing class TaxRequestLine

Data concerning a tax line for calculation.

Properties

Name Type Description
LineNo String Identifying number for the line.
ItemCode String Code corresponding to an item.
TaxCode String Product taxability code of the line item.
CustomerUsageType String Type of usage. Determines the exemption status of the transaction.
Description String Description of the item.
Qty Decimal Quantity of the item.
Amount Decimal Total amount for the tax line including all quantities of the item.
BusinessIdentifier String The buyer's VAT ID for this line item. If null, the business identifier provided at the transaction level is used.
Discounted Boolean Indicates whether the document discount is to be applied to this line item.
ShipFromAddress fferpcore.TaxCalculationService.Address Address the item is being sent from. If null, the ShipFromAddress on the tax document is used.
ShipToAddress fferpcore.TaxCalculationService.Address Address the item is being sent to. If null, the ShipToAddress on the tax document is used.
TaxIncluded Boolean Indicates whether the amount for this line item includes tax.

fferpcore.TaxCalculationService.CreditDocument

global inherited sharing class CreditDocument extends TaxDocument

Credit document data provided to the external tax calculation service to calculate tax.

This class extends fferpcore.TaxCalculationService.TaxDocument

Properties

Name Type Description
ReferenceCode String Document code of the original tax document.

fferpcore.TaxCalculationService.ReversalResponse

global inherited sharing class ReversalResponse extends TaxResponse

Data returned from the external tax provider following the tax calculation of a credit document.

This class extends fferpcore.TaxCalculationService.TaxResponse

Methods

ReversalResponse

global ReversalResponse()

fferpcore.TaxCalculationService.UncommitRequest

global inherited sharing class UncommitRequest

Data provided to the external tax calculation service to uncommit an existing document.

Properties

Name Type Description
Document fferpcore.TaxCalculationService.DocumentIdentity The existing document to uncommit.

Methods

UncommitRequest

global UncommitRequest()

UncommitRequest

global UncommitRequest(fferpcore.TaxCalculationService.DocumentIdentity document)

Construct an uncommit request for an existing document.

Input Parameters

Name Type Description
document fferpcore.TaxCalculationService.DocumentIdentity The existing document to uncommit.

fferpcore.TaxCalculationService.UncommitResponse

global inherited sharing class UncommitResponse extends Response

Data returned from the external tax provider following the uncommit of a document.

This class extends fferpcore.TaxCalculationService.Response

Properties

Name Type Description
DocumentId String The unique identifier for the tax document provided by the external tax provider. When uncommitting a document, a new transaction is created and the original transaction is set to Adjusted.

Methods

UncommitResponse

global UncommitResponse()

fferpcore.TaxCalculationService.VoidRequest

global inherited sharing class VoidRequest

Data provided to the external tax calculation service to void a document.

Properties

Name Type Description
Document fferpcore.TaxCalculationService.DocumentIdentity The document to return.
Reason fferpcore.TaxCalculationService.VoidRequestReason Reason for the return.

Methods

VoidRequest

global VoidRequest(fferpcore.TaxCalculationService.DocumentIdentity document, fferpcore.TaxCalculationService.VoidRequestReason reason)

Construct a Void Request for the given Document with the given Reason.

Input Parameters

Name Type Description
document fferpcore.TaxCalculationService.DocumentIdentity The document to void.
reason fferpcore.TaxCalculationService.VoidRequestReason The reason for the void.

VoidRequest

global VoidRequest(String companyCode, String documentCode, fferpcore.TaxCalculationService.VoidRequestReason reason)

Construct a Void Request for the given Document with the given Reason.

Input Parameters

Name Type Description
companyCode String The tax provider company code of the document
documentCode String The document code to void.
reason fferpcore.TaxCalculationService.VoidRequestReason The reason for the void.

fferpcore.TaxCalculationService.VoidResponse

global inherited sharing class VoidResponse extends Response

Data returned from the external tax provider following the voiding of a document.

This class extends fferpcore.TaxCalculationService.Response

Methods

VoidResponse

global VoidResponse()

fferpcore.TaxCalculationService.TaxDetail

global inherited sharing class TaxDetail

Tax details by jurisdiction.

This class contains deprecated items.

Properties

Name Type Description
Country String Country of the tax jurisdiction.
JurisdictionName String Name of the tax jurisdiction.
JurisdictionType String Type of the tax jurisdiction.
JurisdictionCode2 String Code of the tax jurisdiction.
Rate Decimal Effective tax rate of the tax jurisdiction.
Region String Region of the tax jurisdiction.
Tax Decimal The calculated tax value.
TaxName String Name of the tax.
Taxable Decimal The amount that is taxable.

Deprecated

The following items are deprecated and not supported for use. We recommend that you stop using these items to avoid exceptions.

Properties

Name Type Description Deprecation Details
JurisdictionCode Integer Use JurisdictionCode2 instead.

fferpcore.TaxCalculationService.UnvoidRequest

global inherited sharing class UnvoidRequest

Data provided to the external tax calculation service to unvoid a void document.

Properties

Name Type Description
Document fferpcore.TaxCalculationService.DocumentIdentity The existing void document to unvoid.

Methods

UnvoidRequest

global UnvoidRequest()

UnvoidRequest

global UnvoidRequest(fferpcore.TaxCalculationService.DocumentIdentity document)

Construct an unvoid request for an existing void document.

Input Parameters

Name Type Description
document fferpcore.TaxCalculationService.DocumentIdentity The existing void document to unvoid.

fferpcore.TaxCalculationService.UnvoidResponse

global inherited sharing class UnvoidResponse extends Response

Data returned from the external tax provider following the unvoiding of a document.

This class extends fferpcore.TaxCalculationService.Response

Properties

Name Type Description
DocumentId String The unique identifier for the tax document provided by the external tax provider. When unvoiding a document, a new transaction is created and the original transaction is set to Adjusted.

Methods

UnvoidResponse

global UnvoidResponse()

fferpcore.TaxCalculationService.VerifyRequest

global inherited sharing class VerifyRequest

Data provided to the external tax calculation service to verify a document.

Properties

Name Type Description
DoCommit Boolean True if the document needs to be committed.
Document fferpcore.TaxCalculationService.DocumentIdentity The document to verify.
DocumentDate Date The document date to verify.
TotalAmount Decimal The total amount to verify.
TotalTax Decimal The total tax to verify.

Methods

VerifyRequest

global VerifyRequest()

fferpcore.TaxCalculationService.VerifyResponse

global inherited sharing class VerifyResponse extends Response

Data returned from the external tax provider following the verifying of a document.

This class extends fferpcore.TaxCalculationService.Response

Properties

Name Type Description
Committed Boolean True if the document is committed, false otherwise.

Methods

VerifyResponse

global VerifyResponse()

© Copyright 2009–2023 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.