Manage Orders in the Salesforce B2C Commerce Cartridge
Salesforce B2C Commerce does not natively support order management functions. This cartridge has functions that can be used to process captures and authorization reversals.
Capture
The capture function can be found in the script scripts/http/capture.js. A working example is available in the ServiceFrameworkTest-TestCaptureService controller.
Reference the capture.js object and make this request:
var captureObj = require("~/cartridge/scripts/http/capture.js");var serviceResponse = captureObj.httpCapturePayment(requestID, merchantRefCode, paymentTotal, currency);The resulting serviceResponse object contains the full response object generated by the request. The contents of this object determine your logic in handling errors and successes. These are the Capture request parameters:
Capture Request Parameters:
requestID: the Request ID from the initial authorization.merchantRefCode: the Salesforce Order Number.purchaseTotal: the capture amount.currency: Currency Code.
Function Signature:
httpCapturePayment(requestID, merchantRefCode, purchaseTotal, currency)Authorization Reversal
The authorization reversal function can be found in the script called scripts/http/authReversal.js. A working example is in the ServiceFrameworkTest-TestAuthReversal controller.
Reference the AuthReversal.js object and make this request:
var reversalObj = require("~/cartridge/scripts/http/authReversal.js");var serviceResponse = reversalObj.httpAuthReversal(requestID, merchantRefCode, paymentTotal, currency);The resulting serviceResponse object contains the full response object generated by the request. The contents of this object determine your logic in handling errors and successes. These are the Authorization Reversal request parameters:
Authorization Reversal Request Parameters:
requestID: the Request ID from the initial authorization.merchantRefCode: the Salesforce Order Number.purchaseTotal: the reversal amount.currency: Currency Code.
Refund
The refund function can be found in the script called scripts/http/refund.js. A working example is in the ServiceFrameworkTest-RefundService controller.
Reference the refund.js object and make this request:
var refundObj = require("~/cartridge/scripts/http/refund.js");var serviceResponse = refundObj.httpRefundPayment(transactionId, merchantRefCode, paymentTotal, currency, refundEndpointType);The resulting serviceResponse object contains the full response object generated by the request. The contents of this object determine your logic in handling errors and successes. These are the refund request parameters:
Refund Request Parameters:
requestID: the Request ID from the capture or sale.merchantRefCode: the Salesforce Order Number.paymentTotal: the refund amount.currency: Currency Code.refundEndpointType:paymentsfor ACH/echeck andcapturesfor all other payments.
Function Signature:
httpRefundPayment(transactionId, referenceInformationCode, total, currency, refundEndpointType)Customization
The cartridge for Salesforce B2C Commerce has built-in custom hooks that can be used to customize the request data that is sent to each service. These hooks can send additional custom data, such as Merchant Defined Data for authorization requests.
How Custom Hooks Work
After a request for a particular service is built, there is a check for any code registering to the hook app.payment.modifyrequest. If present, the hook is called for that specific request and the request object is passed into the hook. The return value of the hook is sent to as the final request object. Through this process, you can inject your own data into the request object from the custom code you write in a separate cartridge.
Implementation
To customize request objects, register the hook app.payment.modifyrequest in your cartridge's hooks.json file. An example would look like this, replacing the script path with your own script:
{ "name": "app.payment.modifyrequest", "script": "./cartridge/scripts/hooks/modifyRequestExample"}You can copy the scripts/hooks/modifyRequestExample script from this cartridge into your own to use as a template for extending and modifying service request objects. Every hook must return a valid request object for the given service. Refer to the REST API Field Reference for information about any field you want to customize or add.
Thanks for your feedback!
Last published: November 18, 2026