Step 3: Register external services
Learn how to register external services.
Register external services for Tax Calculation and Payment Services.
If you have not registered the external service for tax integration:
- 1.The script below can be used to insert the Tax Calculation Apex class that comes with the package into
RegisteredExternalService
. To use the script, simply modify the <<storeName>> variable before running.// WebStore query valuesString webstoreName = <<storeName>>; // Enter your webstore name// ApexClass query valuesString apexClassname = 'DRB2B_CartTaxCalculations';String status = 'Active';Double ApiVersion = 51.0;// RegisteredExternalService insert valuesString registeredProviderType = 'Tax';String registeredDevName = 'COMPUTE_TAXES';String registeredLabel = registeredDevName;// StoreIntegratedService insert valuesString devname = registeredDevName;String prefix = registeredProviderType;String prefixedName = prefix + '__' + devname;// locate webstoreWebStore webStore = Database.query('SELECT Id FROM WebStoreWHERE Name = :webstoreName LIMIT 1');String webStoreId = webStore.Id;System.debug('webStoreId:' + webStoreId);// locate apex class IdApexClass apexClass = Database.query('SELECT Id FROM ApexClassWHERE Status=:status AND ApiVersion=:apiVersion ANDName=:apexClassname LIMIT 1');String apexClassId = apexClass.Id;System.debug('apexClassId:' + apexClassId);// locate apex in RegisteredExternalServiceString registeredIntegrationId = null;try {RegisteredExternalService registeredExternalService =Database.query('SELECT Id FROM RegisteredExternalServiceWHERE ExternalServiceProviderId=:apexClassId ANDDeveloperName=:registeredDevName ANDExternalServiceProviderType=:registeredProviderType LIMIT 1');registeredIntegrationId = registeredExternalService.Id;System.debug('apex class registration: FOUND '+ registeredIntegrationId);//delete registeredExternalService; // optionally removeif needed}catch (QueryException q) {System.debug('apex class registration: MISSING ' + apexClassId);insert new RegisteredExternalService(DeveloperName =registeredDevName, MasterLabel = registeredLabel,ExternalServiceProviderId = apexClassId,ExternalServiceProviderType = registeredProviderType);RegisteredExternalService registeredExternalService =Database.query('SELECT Id FROM RegisteredExternalService WHEREExternalServiceProviderId = :apexClassId LIMIT 1');registeredIntegrationId = registeredExternalService.Id;System.debug('apex class registration: INSERTED ' +registeredIntegrationId);} - 2.Verify that the
Tax Calculation Apex class ID
is registered with thesoql
query below. TheExternalServiceProviderId
should match the Tax Calculation Apex ClassDRB2B_CartTaxCalculations
ID in the org.
Select Id, ExternalServiceProviderId, ExternalServiceProviderType,
DeveloperName From RegisteredExternalService Where
ExternalServiceProviderType = 'Tax'
If you have already registered the external service for tax integration:
- 1.Execute the below script to update the Tax Integration service to point to the Tax Calculation integration class from the Salesforce Lightning app.// Configure Tax Calculation ServiceRegisteredExternalService taxServiceRegistration = [SELECT IdFROM RegisteredExternalServiceWHERE ExternalServiceProviderType = 'Tax'LIMIT 1];ApexClass taxCalculationService = [SELECT IdFROM ApexClassWHERE Name = 'DRB2B_CartTaxCalculations'LIMIT 1];taxServiceRegistration.ExternalServiceProviderId =taxCalculationService.Id;update taxServiceRegistration;
- 2.Verify that the
Tax Calculation Apex class ID
is registered by making the belowsoql
query. TheExternalServiceProviderId
should match the Tax Calculation Apex ClassDRB2B_CartTaxCalculations
ID in the org.
Select Id, ExternalServiceProviderId, ExternalServiceProviderType,
DeveloperName From RegisteredExternalService Where
ExternalServiceProviderType = 'Tax'
Register Payment Service by the following steps:
- 1.Capture the
WebStore Id
. This will be used in the script in step 4. - 2.Create a Named Credential for Digital River with the following details:
- Label: Digital River API
- Name: Digital_River_API
- URL: https://api.digitalriver.com
- Identity Type: Named Principal
- Authentication Protocol: No Authentication
- Generate Authorization Header: false
- 3.Create a Payment Gateway Provider:
- Log in to Workbench from your commerce org.
- Go to the Data tab and select Insert.
- Go to the Object Type and select PaymentGatewayProvider.
- Select Single Record and click Next.
- Fill in the fields using your Payment Gateway Adapter information.Field nameExampleApexAdapterIdID of Payment Gateway Adapter Apex class
DRB2B_PaymentGatewayAdapter
DeveloperNameDR_PaymentGatewayIdempotencySupportedYesMasterLabelDR Payment GatewayCommentsDigital River Payment Gateway Provider - Click Confirm Insert.
- 4.Set up Payment Gateway and insert a
StoreIntegratedService
record for payment by executing the below script:
PaymentGatewayProvider paymentGatewayProvider =
[SELECT Id FROM PaymentGatewayProvider Where DeveloperName =
'DR_PaymentGateway' LIMIT 1];
NamedCredential namedCredential = [SELECT Id FROM NamedCredential
WHERE DeveloperName = 'Digital_River_API' LIMIT 1];
PaymentGateway paymentGateway = new PaymentGateway(
PaymentGatewayName = 'Digital River Payment Gateway',
MerchantCredentialId = namedCredential.Id,
PaymentGatewayProviderId = paymentGatewayProvider.Id,
Status = 'Active'
);
insert paymentGateway;
List<StoreIntegratedService> storeIntegratedServiceList =
[SELECT Id FROM StoreIntegratedService WHERE ServiceProviderType =
'Payment' Limit 1];
if(null != storeIntegratedServiceList &&
storeIntegratedServiceList.size() > 0) {
StoreIntegratedService storeIntegratedService =
storeIntegratedServiceList.get(0);
storeIntegratedService.Integration = paymentGateway.Id;
update storeIntegratedServiceList;
}
else {
StoreIntegratedService storeIntegratedService = new
StoreIntegratedService(
StoreId = 'WebStoreId',
Integration = paymentGateway.Id,
ServiceProviderType = 'Payment'
);
insert storeIntegratedService;
}
Last modified 1yr ago