Class PaymentAppHooks
dw.apps.checkout.hooks
Class PaymentAppHooks
dw.apps.checkout.hooks.PaymentAppHooks
This interface defines Commerce App hook extension points for the payment domain.

These hooks provide integration points for payment Commerce Apps installed via the Commerce App framework. They are called by the platform during SCAPI basket and order operations when a payment Commerce App is registered for the relevant payment method.

IMPORTANT: These hooks should only be implemented and registered by Commerce Apps (applications installed via the Commerce App framework with a CAP file). They are not intended for custom merchant cartridges.

Hook Registration

A function must be defined inside a JavaScript source and must be exported. The script with the exported hook function must be located inside a site cartridge. Inside the site cartridge a package.json file with a 'hooks' entry must exist:

 "hooks": "./hooks.json"
 

The hooks entry links to a JSON file, relative to the package.json file:

 "hooks": [
    {"name": "sfcc.app.payment.getClaimedPaymentMethods", "script": "./paymentHooks.js"},
    {"name": "sfcc.app.payment.afterCreateBasketPaymentInstrument", "script": "./paymentHooks.js"},
    {"name": "sfcc.app.payment.afterUpdateBasketPaymentInstrument", "script": "./paymentHooks.js"},
    {"name": "sfcc.app.payment.afterCreateOrderPaymentInstrument", "script": "./paymentHooks.js"},
    {"name": "sfcc.app.payment.afterUpdateOrderPaymentInstrument", "script": "./paymentHooks.js"},
    {"name": "sfcc.app.payment.onAttemptOrderTransition", "script": "./paymentHooks.js"},
    {"name": "sfcc.app.payment.reversePayment", "script": "./paymentHooks.js"},
    {"name": "sfcc.app.payment.authorizePayment", "script": "./paymentHooks.js"},
    {"name": "sfcc.app.payment.cancelAuthorization", "script": "./paymentHooks.js"},
    {"name": "sfcc.app.payment.capturePayment", "script": "./paymentHooks.js"},
    {"name": "sfcc.app.payment.refundCapture", "script": "./paymentHooks.js"}
 ]
 

A hook entry has a name and a script property:

  • The name contains the extension point name (the hook name).
  • The script contains the script path relative to the hooks file, with the exported hook function.

Function Naming Convention: The exported JavaScript function name must match the last segment of the extension point name: afterCreateBasketPaymentInstrument.

Transaction Semantics

The effect of returning Status.ERROR or throwing an uncaught exception differs for basket hooks and order hooks:

  • Basket payment instrument hooks (afterCreateBasketPaymentInstrument, afterUpdateBasketPaymentInstrument): these execute within the platform's transaction boundary for the current basket operation. No order has been created yet, so Status.ERROR or an uncaught exception rolls back that operation; the basket payment instrument is not created or updated.
  • Order payment instrument hooks (afterCreateOrderPaymentInstrument, afterUpdateOrderPaymentInstrument, onAttemptOrderTransition): the order already exists and its creation has already committed, so there is no operation to roll back. Instead, Status.ERROR or an uncaught exception causes the platform to fail the order and reopen the basket, compensating by reversing any payments and refunding any gift cards already captured for the order.

Hook Precedence

  • When a Commerce App claims the payment method for a payment instrument, these hooks take precedence over dw.order.payment.* hooks.
  • If no Commerce App claims the payment method, the platform falls back to the standard behavior.
Constants
extensionPointAfterCreateBasketPaymentInstrument  :  String = "sfcc.app.payment.afterCreateBasketPaymentInstrument"
The extension point name sfcc.app.payment.afterCreateBasketPaymentInstrument.
extensionPointAfterCreateOrderPaymentInstrument  :  String = "sfcc.app.payment.afterCreateOrderPaymentInstrument"
The extension point name sfcc.app.payment.afterCreateOrderPaymentInstrument.
extensionPointAfterUpdateBasketPaymentInstrument  :  String = "sfcc.app.payment.afterUpdateBasketPaymentInstrument"
The extension point name sfcc.app.payment.afterUpdateBasketPaymentInstrument.
extensionPointAfterUpdateOrderPaymentInstrument  :  String = "sfcc.app.payment.afterUpdateOrderPaymentInstrument"
The extension point name sfcc.app.payment.afterUpdateOrderPaymentInstrument.
extensionPointAuthorizePayment  :  String = "sfcc.app.payment.authorizePayment"
The extension point name sfcc.app.payment.authorizePayment.
extensionPointCancelAuthorization  :  String = "sfcc.app.payment.cancelAuthorization"
The extension point name sfcc.app.payment.cancelAuthorization.
extensionPointCapturePayment  :  String = "sfcc.app.payment.capturePayment"
The extension point name sfcc.app.payment.capturePayment.
extensionPointGetClaimedPaymentMethods  :  String = "sfcc.app.payment.getClaimedPaymentMethods"
The extension point name sfcc.app.payment.getClaimedPaymentMethods.
extensionPointOnAttemptOrderTransition  :  String = "sfcc.app.payment.onAttemptOrderTransition"
The extension point name sfcc.app.payment.onAttemptOrderTransition.
extensionPointRefundCapture  :  String = "sfcc.app.payment.refundCapture"
The extension point name sfcc.app.payment.refundCapture.
extensionPointReversePayment  :  String = "sfcc.app.payment.reversePayment"
The extension point name sfcc.app.payment.reversePayment.
Properties
claimedPaymentMethods  :  String[]  (Read Only)
Called to retrieve the list of payment method IDs that this payment Commerce App claims. The hook implementation must return an array of payment method IDs (e.g. ["CREDIT_CARD", "BANK_TRANSFER"]). When a payment instrument has a payment method that appears in the returned array, its payment lifecycle will be handled by the payment Commerce App.
Constructor Summary
This class does not have a constructor, so you cannot create it directly.
Method Summary
afterCreateBasketPaymentInstrument(basket : Basket, paymentInstrument : OrderPaymentInstrument, request : BasketPaymentInstrumentRequest) : Status
Called after a new claimed payment instrument is created on a basket.
afterCreateOrderPaymentInstrument(order : Order, paymentInstrument : OrderPaymentInstrument, request : OrderPaymentInstrumentRequest) : Status
Called after an order payment instrument is created for a claimed payment method directly on an existing order via the SCAPI POST order-payment-instruments endpoint.
afterUpdateBasketPaymentInstrument(basket : Basket, paymentInstrument : OrderPaymentInstrument, request : BasketPaymentInstrumentRequest) : Status
Called after a claimed payment instrument is updated on a basket.
afterUpdateOrderPaymentInstrument(order : Order, paymentInstrument : OrderPaymentInstrument, request : OrderPaymentInstrumentRequest) : Status
Called when a claimed payment instrument is updated on an order.
authorizePayment(order : Order, paymentInstrument : OrderPaymentInstrument) : Status

Called to authorize payment for a payment instrument.

cancelAuthorization(order : Order, paymentInstrument : OrderPaymentInstrument) : Status

Called to void or cancel the authorization for a payment instrument.

capturePayment(order : Order, paymentInstrument : OrderPaymentInstrument) : Status

Called to capture a previous payment authorization.

getClaimedPaymentMethods() : String[]
Called to retrieve the list of payment method IDs that this payment Commerce App claims.
onAttemptOrderTransition(order : Order, paymentInstrument : OrderPaymentInstrument) : Status
Called for each claimed order payment instrument during an order-transition attempt.
refundCapture(order : Order, paymentInstrument : OrderPaymentInstrument) : Status

Called to refund a previously captured payment.

reversePayment(order : Order, paymentInstrument : OrderPaymentInstrument) : Status
Called to void or refund the payment for a claimed payment instrument.
Method Detail
afterCreateBasketPaymentInstrument
afterCreateBasketPaymentInstrument(basket : Basket, paymentInstrument : OrderPaymentInstrument, request : BasketPaymentInstrumentRequest) : Status
Called after a new claimed payment instrument is created on a basket.
Parameters:
basket - the basket containing the new payment instrument
paymentInstrument - the created payment instrument
request - body of the SCAPI request that triggered the creation
Returns:
Status.OK to proceed or Status.ERROR to roll back

afterCreateOrderPaymentInstrument
afterCreateOrderPaymentInstrument(order : Order, paymentInstrument : OrderPaymentInstrument, request : OrderPaymentInstrumentRequest) : Status
Called after an order payment instrument is created for a claimed payment method directly on an existing order via the SCAPI POST order-payment-instruments endpoint.
Parameters:
order - the order that owns the payment instrument
paymentInstrument - the order payment instrument just created
request - body of the SCAPI request that triggered the creation
Returns:
Status.OK to proceed or Status.ERROR to fail the order and reopen the basket

afterUpdateBasketPaymentInstrument
afterUpdateBasketPaymentInstrument(basket : Basket, paymentInstrument : OrderPaymentInstrument, request : BasketPaymentInstrumentRequest) : Status
Called after a claimed payment instrument is updated on a basket.
Parameters:
basket - the basket containing the updated payment instrument
paymentInstrument - the updated payment instrument
request - body of the SCAPI request that triggered the update
Returns:
Status.OK to proceed or Status.ERROR to roll back

afterUpdateOrderPaymentInstrument
afterUpdateOrderPaymentInstrument(order : Order, paymentInstrument : OrderPaymentInstrument, request : OrderPaymentInstrumentRequest) : Status
Called when a claimed payment instrument is updated on an order.
Parameters:
order - the order containing the payment instrument
paymentInstrument - the updated payment instrument
request - body of the SCAPI request that triggered the update
Returns:
Status.OK to proceed or Status.ERROR to fail the order and reopen the basket

authorizePayment
authorizePayment(order : Order, paymentInstrument : OrderPaymentInstrument) : Status

Called to authorize payment for a payment instrument.

Note: The platform does not call this hook directly, so there is no guarantee the given payment instrument is claimed by this payment Commerce App. Call this hook in your custom hook implementations to perform authorization. Implement this hook to support payment authorization outside of the defined platform extension points.

Parameters:
order - the order whose payment to authorize
paymentInstrument - the payment instrument to authorize
Returns:
Status.OK on successful authorization or Status.ERROR if authorization fails

cancelAuthorization
cancelAuthorization(order : Order, paymentInstrument : OrderPaymentInstrument) : Status

Called to void or cancel the authorization for a payment instrument.

Note: The platform does not call this hook directly, so there is no guarantee the given payment instrument is claimed by this payment Commerce App. Call this hook in your custom hook implementations to perform authorization reversal. Implement this hook to support authorization reversal outside of the defined platform extension points.

Parameters:
order - the order whose authorization to void or cancel
paymentInstrument - the payment instrument whose authorization to void or cancel
Returns:
Status.OK on successful reversal or Status.ERROR if reversal fails

capturePayment
capturePayment(order : Order, paymentInstrument : OrderPaymentInstrument) : Status

Called to capture a previous payment authorization.

Note: The platform does not call this hook directly, so there is no guarantee the given payment instrument is claimed by this payment Commerce App. Call this hook in your custom hook implementations to capture payment. Implement this hook to support capture outside of the defined platform extension points.

Parameters:
order - the order whose payment to capture
paymentInstrument - the payment instrument whose payment to capture
Returns:
Status.OK on successful capture or Status.ERROR if capture fails

getClaimedPaymentMethods
getClaimedPaymentMethods() : String[]
Called to retrieve the list of payment method IDs that this payment Commerce App claims. The hook implementation must return an array of payment method IDs (e.g. ["CREDIT_CARD", "BANK_TRANSFER"]). When a payment instrument has a payment method that appears in the returned array, its payment lifecycle will be handled by the payment Commerce App.
Returns:
an array of payment method IDs, or an empty array if no methods are claimed

onAttemptOrderTransition
onAttemptOrderTransition(order : Order, paymentInstrument : OrderPaymentInstrument) : Status
Called for each claimed order payment instrument during an order-transition attempt.

When the app authorizes the payment synchronously within this hook, set the payment transaction status on paymentInstrument to PaymentTransaction.STATUS_AUTHORIZED or PaymentTransaction.STATUS_CAPTURED before returning Status.OK. When the app initiates asynchronous payment authorization or capture, set the payment transaction status to PaymentTransaction.STATUS_PENDING.

Parameters:
order - the order that owns the payment instrument
paymentInstrument - the order payment instrument being processed
Returns:
Status.OK to proceed or Status.ERROR to fail the order and reopen the basket

refundCapture
refundCapture(order : Order, paymentInstrument : OrderPaymentInstrument) : Status

Called to refund a previously captured payment.

Note: The platform does not call this hook directly, so there is no guarantee the given payment instrument is claimed by this payment Commerce App. Call this hook in your custom hook implementations to refund payment. Implement this hook to support refund outside of the defined platform extension points.

Parameters:
order - the order containing the payment to refund
paymentInstrument - the payment instrument whose payment to refund
Returns:
Status.OK on successful refund or Status.ERROR if refund fails

reversePayment
reversePayment(order : Order, paymentInstrument : OrderPaymentInstrument) : Status
Called to void or refund the payment for a claimed payment instrument.
Parameters:
order - the order containing the payment instrument
paymentInstrument - the payment instrument to reverse
Returns:
Status.OK on successful reversal or Status.ERROR if reversal fails