You can extend the functionality and features of the Salesforce B2C LINK Cartridge to meet your integration needs. Read the following section to learn how you can do this.
Custom code
Important: Follow the instructions below only when you cannot use the cartridge directly and unmodified, or you need to resolve conflicts with other cartridges on your project. Otherwise, you must compile the client-side scripts and styles, upload the cartridge, and add it to your storefront cartridge path.
Cartridge int_digitalriver_sfra already contains all templates and script changes.
SFRA templates
This section describes changes applied to the most recent templates provided with the cartridge. In addition, the section describes changes that may need to be made to templates to support specific client use cases and integration choices.
The following templates and their changes are described in this section:
Note: All line numbers referred to in the following code samples and example screenshots are relative. For the location of the code changes being discussed, refer to the highlighted areas in the screenshots that are isolated with a green or red border around the code.
Add payment
Use the add payment (addPayment.isml) template to add payment cards to the customer's account. You can use the template to add Drop-in payments functionality (DigitalRiver.js) and Drop-in payments in styles (DigitalRiver.css) and place Drop-in payments on an account page.
Use the dashboard profile cards (dashboardProfileCards.isml) template to add a Digital River Tax Certificates section to your Profile Dashboard page. The following image shows the out-of-the-box (OOTB) Dashboard Profile Dashboard page for the Salesforce B2C Link Cartridge.
When you apply the dashboard profile cards template, it adds Tax Certificates.
Added the Digital River tax certificate section on the page. In this example, tax certificates are displayed in My account only for the US locale. This section is available for US locale only.
As part of Billing, you can use the payment options summary template (paymentOptionsSummary.isml) to extend the payment condition with the DIGITAL_RIVER_DROPIN payment method on the Checkout page.
Important: The DIGITAL_RIVER_DROPIN payment integration represents not one but multiple payment types such as credit card, PayPal, Wire Transfer, and so on. The Drop-in integration provides the selection of payment types, and the client-side/backend scripts handle it. We designed this cartridge mainly to handle the credit card payment type, though it will also successfully process any other payment type provided by the Drop-in integration. You can extend Drop-in data handlers to add any business logic for a specific payment type or provide shoppers with a better customer experience.
Billing
Use the billing (billing.isml) template to add accordion components to the Billing page. The following image shows the out-of-the-box (OOTB) Payment section of the Checkout page for the Salesforce B2C Link Cartridge.
When you apply the dashboard profile cards template, you can now choose whether the purchase is tax-exempt and the payment method.
Use the stored payment instruments (storedPaymentInstruments.isml) template to display the stored payment instruments on the Billing page as a list of saved payment cards in the customer's account.
Wrapped the security-code-input div with the following condition:
<isif condition="${!isDRDropInEnabled}"> <iscomment> Digital River - if enabled no cvv needed thus pictures are always shown instead of input </iscomment>
<div class="security-code-input ${loopState.first ? '' : 'checkout-hidden'}">
<label class="form-control-label" for="saved-payment-security-code">${Resource.msg('label.credit.card-security.code','checkout',null)}</label>
… security-code-unput goes here
</div>
</isif>
Confirmation
Use the standard confirmation (confirmation.isml) template for the B2C LINK Cartridge to include the Digital River compliance statement.
The customer should agree to Digital River's Terms of Sale and Privacy Policy and set the checkbox to complete an order. For more information on the Terms of Sale and the Privacy Policy of Digital River, visit the Digital River Legal Documentation website.
Compliance links are required to be displayed in several different places throughout the storefront. The out-of-the-box (OOTB) cartridge displays the compliance links in all required locations. Consult your Digital River Project Manager before making modifications to your storefront. For more detailed information on the purpose of the compliance links, visit Compliance on the Digital River Legal Documentation website.
Use the checkout (checkout.isml) template to add Digital River styles, the Drop-in styles, and the check box to confirm agreement with the Terms of Sale and the Privacy Policy of Digital River to the Checkout page when the customer is ready to place an order. The customer should agree to Digital River's Terms of Sale and Privacy Policy and set the checkbox to complete the order.
Note: Refer to the Use Customer Credit section of this documentation for more information on how to use the Checkout template when using the Customer Credit feature and theint_digitalriver_customercreditcartridge.
Added a spinner inside the placeOrderstage condition. When the Shopper is in placeOrder stage, they will see a spinner running until the place order stage executes.
$('#checkout-main').spinner().start();
Added the Digital River confirm disclosure checkbox to the checkout page.
In the <isscript>section, added a reference to the drInvoiceCredit.js script.
assets.addJs('/js/drInvoiceCredit.js');
Added remote include for Invoices and Credit memos and Offline Refund functionality.
<iscomment> Include DR invoice & credit memo links </iscomment><isincludeurl="${URLUtils.url('DigitalRiver-InvoiceCredit', 'id', pdict.order.drOrderID)}" /><isinclude url="${URLUtils.url('DigitalRiver-OfflineRefund', 'id', pdict.order.drOrderID, 'sfOrderID', pdict.order.orderNumber)}" />
Menu
Use the Menu (menu.isml) template to display the country/currency selector for the dynamic pricing feature.
Note: This template is not overridden by the cartridge OOTB. The following example includes the country/currency selector on the storefront. You are expected to add the selector to the desired location.
Use the Page Header (pageHeader.isml) template to display the country/currency selector for the dynamic pricing feature.
Note: This template is not overridden by the cartridge OOTB. Use the following example to include the country/currency selector on the storefront. You are expected to add the selector to the desired location.
This section describes the changes applied to the most recent client scripts provided with the cartridge. It also describes changes that you may need to make to the client scripts to support your specific use cases and integration choices.
The following scripts and their changes are described in this section:
Note: All line numbers in the following code samples and example screenshots are relative. For the location of the code changes being discussed, refer to the highlighted areas in the screenshots that are isolated with a green or red border around the code.
Note: Do not forget to compile client-side scripts after implementing changes in the source code.
Checkout script
The checkout (checkout.js) script is loaded on the Checkout page and includes the page frontend event handler. The script loads the base event handler (checkout.js) and additionally loads the Digital River US Tax Certificate handler (drCertificate.js) on the shipping stage of the checkout and the Global Tax ID handler (drTaxId.js) on the billing stage of checkout.
The checkout script (checkout.js) is loaded on the Checkout page and includes a basic page frontend event handler. The changes introduced by this script extend the base functionality to correctly handle Digital River extensions.
Added the following line at the beginning of the file:
var drHelper = require('./drHelper');
Added the retrieve stored card global variable at the beginning of the checkout function.
// --- Digital River Retrieve Stored Card ---
var drStoredPayment = null;
Added the following code to the shipping submit success handler.
if (!data.error &&data.digitalRiverConfiguration) {drHelper.updateComplianceEntity(data.digitalRiverComplianceOptions.compliance.businessEntityCode); $('body').trigger('digitalRiver:dropIn', data.digitalRiverConfiguration); // Digital River integration: call dropIn feature after checkoutCreate
$('body').trigger('digitalRiver:taxIdentifier',data.digitalRiverTaxIdConfig);$('body').trigger('digitalRiver:taxCertificate',data.digitalRiverTaxExemptData);}
Added the following code to the Retrieve stored card section.
drStoredPayment =null; // --- Digital River Retrieve Stored Card --de
Extended the code as follows.
var paymentMethod =$('.payment-information').data('payment-method-id');if (paymentMethod === 'CREDIT_CARD' || paymentMethod === 'DIGITAL_RIVER_DROPIN') { // Extended by Digital River Drop-in integration
if ($('.saved-payment-instrument.selected-payment').length===0) {$('#savedPaymentNotSelectedMessage').show();$('#collapse-payment').collapse('show');defer.reject();return defer;}
Added the following code to the Retrieve stored card section.
// --- Digital River Retrieve Stored Card ---
drStoredPayment = $savedPaymentInstrument.data('uuid')
Extended the billing code as follows:
$('#collapse-billing').collapse('show');
Extended the code as follows:
drHelper.renderDRConfirm();
Wrapped the contents of the placeOrder stage function.
// --- Digital River Retrieve Stored Card ---
var placeOrder = function (defer) { // eslint-disable-line no-shadow
//Digital River - 2.6 - Redirect Flow
if (!$('.DR-place-order').data('dr-order-placed') && !$('.DR-place-order').data('dr-redirect-success'))
{
drHelper.handleDROrderPlacement(defer, placeOrder);
}
//End Digital River - 2.6 - Redirect Flow
else {
$('.DR-place-order').data('dr-order-placed',"false");
… 'placeOrder' stage content goes here
if (data.digitalRiverConfiguration) {
$('body').trigger('digitalRiver:updateDropIn', data.digitalRiverConfiguration);
}
… 'placeOrder' stage content goes here
drHelper.retrieveStoredCard(drStoredPayment, defer, placeOrder);
Added the following code to the shipping submit success handler.
Modified the following and also modified the row (see highlighted area).
$('[name$=' + element + ']', form).val(attrs[attr]).trigger('change');
The default storefront on the Checkout page uses the payment instruments (paymentInstruments.js) script. This JavaScript includes the frontend handler for payment cards. This frontend JavaScript must be completed and compiled before being used on the site. When this JavaScript is loaded on the Checkout page, the script loads the base handler (paymentInstruments.js) and additionally loads the handler for the Digital River payment cards (paymentInstrumentsDropIn.js).
Used proccessInclude to extend the default paymentInstruments.js script. Once compiled, the paymentInstrumentsDropIn.js extends the Checkout page to display the available payment methods. The script contains functions to launch Drop-in, handle errors, and handle submitted payments.
Modify the selectBillingAddressfunction. An example is shown in line 267 of the following screenshot:
$('[name$=' + element + ']', form).val(attrs[attr]).trigger('change');
Add the clearCreditCardFormfunction content and include the following condition:
if ($('#dropInContainer').data('enabled')) return;
Add the handleCreditCardNumber function and include the following condition:
if ($('.cardNumber').length === 0) return;
Add the following condition inside the selectSavedPaymentInstrument function.
if ($('#dropInContainer').data('enabled')) { // Digital River - if enabled no cvv needed thus pictures are always shown instead of input
$('#savedPaymentNotSelectedMessage').hide();
} else {
$('.saved-payment-instrument .card-image').removeClass('checkout-hidden');
$('.saved-payment-instrument .security-code-input').addClass('checkout-hidden');
$('.saved-payment-instrument.selected-payment'
+ ' .card-image').addClass('checkout-hidden');
$('.saved-payment-instrument.selected-payment '
+ '.security-code-input').removeClass('checkout-hidden');
}
Add the following code to the addNewPaymentInstrument function:
// Digital River Drop-in section
if ($('#dropInContainer').data('enabled')) {
$('.drop-in-container').removeClass('checkout-hidden'); // show drop-in form to enter new payment
$('.submit-payment').addClass('digitalriver-hide'); // next step will be launched from drop-in button instead
}
Add the following code to the canceNewPayment function:
// Digital River Drop-in section
if ($('#dropInContainer').data('enabled')) {
$('.submit-payment').removeClass('digitalriver-hide');
$('.drop-in-container').addClass('checkout-hidden');
}
Summary script
Use the summary.js script to extend the checkout script functionality that provides order summary information. For more information on this script and how it is used with Customer Credit, refer to Use Customer Credit and Customize the Customer Credit Cartridge.
'use strict";
var addressHelpers = require('base/checkout/address');
........
var addressHelpers = require('base/checkout/shipping');
Modified the updateMultiShipInformation function with the following condition on line 20:
if (!$drCustomerError.length) {
$submitShippingBtn.prop('disabled', null);
}
The shipping.js script has been updated so that the Ajax call to load shipping methods is not triggered if a shopper successfully submits a payment.
Wrap the Ajax call in an if statement as follows:
if(!$('.DR-place-order').data('dr-redirect-success'))
{
… code to load shipping methods
}
The updateShippingList function has been extended to handle trigger updates to the shipping methods list if the Zip Code is changed in the shipping form. The handler code has been moved to a separate function that triggers both the stateCode and shippingZipCode fields in the shipping form.
var handler = function (e) {
if (baseObj.methods && baseObj.methods.updateShippingMethodList) {
baseObj.methods.updateShippingMethodList($(e.currentTarget.form));
} else {
updateShippingMethodList($(e.currentTarget.form));
}
};
$(document).on('focusout', '.shippingZipCode', handler);
$('select[name$="shippingAddress_addressFields_states_stateCode"]')
.on('change', handler);
SFRA model changes
This section describes changes applied to the most recent models provided with the cartridge. In addition, the section describes changes you may need to make the models support your specific use cases and integration choices. The following scripts were updated, and their changes are described in this section:
Shipping
The Shipping (shipping.js) model was updated to add support for the Digital River Shipping Options feature.
Model path:cartridge/models/shipping.js
The following functions were extended in this model:
getSelectedShippingMethod
ShippingModel
The getSelectedShippingMethod function was extended as follows:
function getSelectedShippingMethod(shipment) {
if (!shipment) return null;
var method = shipment.shippingMethod;
// Digital River Modification - Begin
var model = null;
if (method) {
model = new ShippingMethodModel(method, shipment);
if (method.ID.indexOf('DRDefaultShp') > -1) {
var sqModel = {};
sqModel.default = false;
sqModel.description = shipment.custom.drSQDescription;
sqModel.displayName = shipment.custom.drSQServiceLevel;
sqModel.shippingTerms = shipment.custom.drSQShippingTerms;
sqModel.estimatedArrivalTime = shipment.custom.drSQEstimatedArrivalTime;
sqModel.ID = shipment.custom.drUniqueID;
sqModel.selected = true;
sqModel.shippingCost = shipment.custom.drSQTotalAmount;
model = sqModel;
}
}
// Digital River Modification - End
return model;
}
The ShippingModel function was extended as follows:
function ShippingModel(shipment, address) {
parent.apply(this, arguments);
var shippingHelpers = require('*/cartridge/scripts/checkout/shippingHelpers');
var basketCalculationHelpers = require('*/cartridge/scripts/helpers/basketCalculationHelpers');
var Transaction = require('dw/system/Transaction');
this.applicableShippingMethods = shippingHelpers.getApplicableShippingMethods(shipment, address);
if (!this.applicableShippingMethods || empty(this.applicableShippingMethods)) {
var basket = BasketMgr.getCurrentBasket();
if (basket) {
Transaction.wrap(function () {
shipment.setShippingMethod(null);
basketCalculationHelpers.calculateTotals(basket);
});
}
}
this.selectedShippingMethod = getSelectedShippingMethod(shipment);
}
SFRA script changes
This section describes the changes applied to the most recent cartridge scripts. In addition, you may need to make some of these changes to the scripts to support your specific use cases and integration choices. The following scripts and their changes are described in this section:
function getFirstApplicableShippingMethod(methods, filterPickupInStore) {
var method;
var iterator = methods.iterator();
while (iterator.hasNext()) {
method = iterator.next();
if (!filterPickupInStore) {
if (method.apiShippingMethod) {
if (!method.apiShippingMethod.custom.storePickupEnabled) {
break;
}
} else if (!method.custom.storePickupEnabled) {
break;
}
}
}
return method;
}
ensureShipmentHas method
This method was changed as follows:
output.ensureShipmentHasMethod = function (shipment) {
var shippingMethod = shipment.shippingMethod;
if (!shippingMethod) {
var methods = ShippingMgr.getShipmentShippingModel(shipment).applicableShippingMethods;
var defaultMethod = ShippingMgr.getDefaultShippingMethod();
var isAllDigitalProducts = checkoutHelper.checkDigitalProductsOnly(shipment.productLineItems);
if (isAllDigitalProducts) {
shippingMethod = collections.find(methods, function (method) {
return method.ID.includes('DigitalProductShipment');
});
} else if (!defaultMethod) {
// If no defaultMethod set, just use the first one
shippingMethod = getFirstApplicableShippingMethod(methods, true);
} else {
// Look for defaultMethod in applicableMethods
shippingMethod = collections.find(methods, function (method) {
return method.ID === defaultMethod.ID;
});
}
// If found, use it. Otherwise return the first one
if (!shippingMethod && methods && methods.length > 0) {
shippingMethod = getFirstApplicableShippingMethod(methods, true);
}
if (shippingMethod) {
shipment.setShippingMethod(shippingMethod);
}
}
};
getApplicableShipping method
This method was changed as follows:
function getApplicableShippingMethods(shipment, address) {
if (!shipment) return null;
var shipmentShippingModel = ShippingMgr.getShipmentShippingModel(shipment);
var shippingMethods;
if (address) {
shippingMethods = shipmentShippingModel.getApplicableShippingMethods(address);
} else {
shippingMethods = shipmentShippingModel.getApplicableShippingMethods();
}
// Filter out whatever the method associated with in store pickup
var convertedMethods = checkoutHelper.convertShippingMethodsToModel(shippingMethods, shipment);
var modifiedShippingQuotes = [];
var checkoutPageOnly = checkoutHelper.isAllowedEndpoint();
if (checkoutPageOnly) {
var shippingQuotes = ShippingQuotesHelper.getShippingQuotes(shippingMethods, shipment, convertedMethods.drShippingMethod);
modifiedShippingQuotes = ShippingQuotesHelper.modifyShippingQuotes(shippingQuotes);
}
var isAllDigitalProducts = checkoutHelper.checkDigitalProductsOnly(shipment.productLineItems);
var drEnabled = Site.getCurrent().getCustomPreferenceValue('drUseDropInFeature');
var drShippingMethodAvailability = Site.getCurrent().getCustomPreferenceValue('drShippingMethodAvailability').value;
if (!drEnabled || (isAllDigitalProducts && drShippingMethodAvailability === 'quotes')) {
modifiedShippingQuotes = convertedMethods.filteredMethods;
}
var bothShippingMethods = convertedMethods.filteredMethods;
if (drEnabled) {
bothShippingMethods = convertedMethods.filteredMethods.concat(modifiedShippingQuotes);
}
var shippingMethodAvailability = null;
switch (drShippingMethodAvailability) {
case 'native':
shippingMethodAvailability = convertedMethods.filteredMethods;
break;
case 'quotes':
shippingMethodAvailability = modifiedShippingQuotes;
break;
case 'both':
shippingMethodAvailability = bothShippingMethods;
break;
default:
shippingMethodAvailability = convertedMethods.filteredMethods;
break;
}
return shippingMethodAvailability;
}
output.getApplicableShippingMethods = getApplicableShippingMethods;
selectShippingMethod
This method was changed as follows:
output.selectShippingMethod = function (shipmentArg, shippingMethodID, shippingMethods, address) {
var shipment = shipmentArg;
var applicableShippingMethods;
var defaultShippingMethod = ShippingMgr.getDefaultShippingMethod();
var shippingAddress;
if (address && shipment) {
shippingAddress = shipment.shippingAddress;
if (shippingAddress) {
if (address.stateCode && shippingAddress.stateCode !== address.stateCode) {
shippingAddress.stateCode = address.stateCode;
}
if (address.postalCode && shippingAddress.postalCode !== address.postalCode) {
shippingAddress.postalCode = address.postalCode;
}
}
}
var isShipmentSet = false;
if (shippingMethods) {
applicableShippingMethods = checkoutHelper.convertShippingMethodsToModel(shippingMethods, shipment).filteredMethods;
} else {
applicableShippingMethods = getApplicableShippingMethods(shipment, address);
}
applicableShippingMethods = new ArrayList(applicableShippingMethods);
if (shippingMethodID) {
// loop through the shipping methods to get shipping method
var iterator = applicableShippingMethods.iterator();
while (iterator.hasNext()) {
var shippingMethod = iterator.next();
if (shippingMethod.ID === shippingMethodID) {
shipment.setShippingMethod(shippingMethod.apiShippingMethod);
isShipmentSet = true;
checkoutHelper.populateShipmentCustomPref(shipment, shippingMethod);
break;
}
}
}
if (!isShipmentSet) {
var isAllDigitalProducts = checkoutHelper.checkDigitalProductsOnly(shipment.productLineItems);
if (isAllDigitalProducts) {
var digitalShippingMethod = collections.find(applicableShippingMethods, function (method) {
return method.ID.includes('DigitalProductShipment');
});
shipment.setShippingMethod(digitalShippingMethod.apiShippingMethod);
} else if (collections.find(applicableShippingMethods, function (sMethod) {
return sMethod.ID === defaultShippingMethod.ID;
})) {
shipment.setShippingMethod(defaultShippingMethod);
} else if (applicableShippingMethods.length > 0) {
var firstMethod = getFirstApplicableShippingMethod(applicableShippingMethods, true);
shipment.setShippingMethod(firstMethod.apiShippingMethod);
checkoutHelper.populateShipmentCustomPref(shipment, firstMethod);
} else {
shipment.setShippingMethod(null);
}
}
};
Calculate hook
The Calculate hook (calculate.js) script was updated to add support for the Dynamic Shipping and Digital River taxation features.
output.calculateShipping = function (basket) {
var status = new Status(Status.OK);
try {
Transaction.wrap(function () {
for (let i = 0; i < basket.shipments.length; i++) {
var shipment = basket.shipments[i];
if (shipment && shipment.shippingMethodID && shipment.shippingMethodID.indexOf('DRDefaultShp') > -1) {
ShippingMgr.applyShippingCost(basket);
var priceStringified = shipment.custom.drSQTotalAmount;
var shippingPrice;
if (priceStringified) {
if (shipment.shippingMethodID === 'DRDefaultShpJPY') {
shippingPrice = parseFloat(priceStringified.replace(/[^\d.]/g, ''));
} else {
shippingPrice = Number(priceStringified.replace(/[^0-9,.-]+/g, '').replace(',', '.'));
}
var shippingLineItem = shipment.shippingLineItems[0];
shippingLineItem.setPriceValue(shippingPrice);
var taxRate = shippingLineItem.getTaxRate();
var updatedTax = shippingPrice * taxRate;
shippingLineItem.updateTaxAmount(new dw.value.Money(updatedTax, basket.currencyCode));
}
} else {
ShippingMgr.applyShippingCost(basket);
}
}
basket.updateTotals();
});
} catch (e) {
status = new Status(Status.ERROR);
}
return status;
};
calculateTax
This function has changed as follows:
output.calculateTax = function (basket) {
var DigitalRiverEnabled = require('dw/system/Site').getCurrent().getCustomPreferenceValue('drUseDropInFeature');
var checkoutData = taxHelper.parseCheckoutData(basket.custom.drCheckoutData);
if (!DigitalRiverEnabled || !checkoutData) { // use default tax calculation if Digital River is disabled or checkout hasn't been created yet
return parent.calculateTax.apply(null, arguments);
}
var logger = require('*/cartridge/scripts/digitalRiver/drLogger').getLogger('digitalriver.checkout');
if (!taxHelper.checkoutDataIsValid(checkoutData, basket)) {
return parent.calculateTax.apply(null, arguments);
}
// taxHelper.updateTaxPromotion(basket, checkoutData);
var currency = basket.getCurrencyCode();
var shippingTaxAmount = checkoutData.shippingTax;
var itemNavigation = checkoutData.items.map(function (item) { return item.digitalRiverID; });
var lineItems = basket.getAllLineItems();
collections.forEach(lineItems, function (lineItem) {
if (lineItem instanceof dw.order.ProductLineItem) { // updating taxes for product line items
var taxAmount = 0;
var taxRate = 0;
if (!lineItem.optionProductLineItem) { // option products line items will have 0 taxes while parent item taxes will include options cost
var sourceItem = checkoutData.items[itemNavigation.indexOf(lineItem.custom.digitalRiverID)];
if (sourceItem) {
taxAmount = sourceItem.tax.amount;
taxRate = sourceItem.tax.rate;
}
}
if (!empty(taxRate)) {
lineItem.updateTax(taxRate);
}
lineItem.updateTaxAmount(new Money(taxAmount, currency));
} else if (lineItem instanceof dw.order.ShippingLineItem
&& lineItem.ID !== 'digitalRiver_duty'
&& lineItem.ID !== 'digitalRiver_importerTax'
) {
lineItem.updateTaxAmount(new Money(shippingTaxAmount, currency));
} else if (lineItem instanceof dw.order.PriceAdjustment) { // price adjustments except Fees will have 0 taxes
if (!taxHelper.isDrAdjustment(lineItem.promotionID)) {
lineItem.updateTax(0);
}
} else {
lineItem.updateTax(0);
logger.warn('Taxes for {0} set to zero. Digital River tax calculation is not supported by this implementation', lineItem.constructor.name);
}
});
return new Status(Status.OK);
};
SFRA JSON files changes
This section describes the changes made to the most recent cartridge JSON and the changes that you may need to make to the scripts to support your specific use cases and integration choices.
The following scripts and their changes are described in this section:
The cartridge's Digital River API endpoints and Digital River Drop-in payments external script handles client payments. The DigitalRiver.http.service shares one profile and one credential.
dropinHelper.js
Use the dropinHelper.js to configure specific payment data used by Drop-in payments.
You can use use the following elements in dropinHelper.js to configure the payment data.
switch(source.type)—Saves payment data (for example, creditCard) from Drop-in payments to the customer's wallet, which the customer can use it the next time they go to the Checkout page.
switch(paymentType)—returns object with specific fields from the SFCC paymentInstrument object.
switch(source.type)—returns object with specific fields from the Drop-In response object.
payment.js
Use the payments.js script to add specific attributes to the core payment object. Templates and client-side scripts (JSON) use this object.
extendDigitalRiverInfo—extract data (such as paymentType, maskedCreditCardNumber, and so on) and makes it available in templates or the client-side as JSON.
Example of endpoint URL: https://zzrk-032.sandbox.us01.dx.commercecloud.salesforce.com/on/demandware.store/Sites-DR-SFRA-Net-Site/en_US/HooksObserver-Debug
You only need to configure a single endpoint per site regardless of the number of locales supported.
Controller
Use the following steps to use the controller portion of the handler:
// get the hook data
var drSignature = request.getHttpHeaders().get('digitalriver-signature') || '';
var requestBodyAsString = request.httpParameterMap.getRequestBodyAsString() || '{}';
var hook = JSON.parse(requestBodyAsString);
var hookType = hook.type ? hook.type : 'error';
var hookHandlerResponse;
var checkSignature = drHooksHelper.checkSignature(drSignature, requestBodyAsString);
Step 2: Use helper script to log request data
// log info
var DRLogger = logger.getLogger("drWebhooks", hookType); // hook type, e.g. refund.pending
DRLogger.info(requestBodyAsString);
Send an email (sendTechnicalMail(title, content)).
Set the email address in the Business Manager site preferences
Check the received request (checkSignature(signature, requestBodyAsString)).
Set webhook signature token in Business Manager site preferences. Otherwise, the handler returns an error and 500 response code. You can find the webhook signature token under Signing secret under Webhooks in the Dashboard.
Use the handler script where custom handling is needed. The handler script contains simple examples of handlers, which can be modified and extended for custom handling. Examples are provided for the following event types:
refund.pending
refund.complete
If the hookType (webhook's event type) is set in the request body (see Step 1: Catch request data in Controller), the handler script handles events by the event type and returns a 200 OK response.
If a handler with a selected hookType does not exist, or if the hookType is not set, the “default” handler is used and processes all other types and returns 200 response code.
If an error occurs, the handler returns a 500 response code.
To add a handler for a specific event type, create a function with a data attribute that returns a response code (for example, 200) and add a function name to the module.exports object.