Class PaymentApiHooks
dw.extensions.paymentapi
Class PaymentApiHooks
dw.extensions.paymentapi.PaymentApiHooks
PaymentApiHooks interface containing extension points for customizing Payment API requests for authorization, and their responses.

These hooks are executed in a transaction.

The extension points (hook names), and the functions that are called by each extension point. 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. This file lists all registered hooks inside the hooks property:

 "hooks": [
      {"name": "dw.extensions.paymentapi.beforeAuthorization", "script": "./payment.ds"}
      {"name": "dw.extensions.paymentapi.afterAuthorization", "script": "./payment.ds"}
 ]
 

A hook entry has a 'name' and a 'script' property.

  • The 'name' contains the extension point, the hook name.
  • The 'script' contains the script relative to the hooks file, with the exported hook function.
Constants
extensionPointAfterAuthorization  :  String = "dw.extensions.paymentapi.afterAuthorization"
The extension point name dw.extensions.paymentapi.afterAuthorization.
extensionPointBeforeAuthorization  :  String = "dw.extensions.paymentapi.beforeAuthorization"
The extension point name .
Properties
Constructor Summary
This class does not have a constructor, so you cannot create it directly.
Method Summary
afterAuthorization(order : Order, payment : OrderPaymentInstrument, custom : Object, status : Status) : Status

Called after the response has been handled for a request to authorize payment for the given order.

beforeAuthorization(order : Order, payment : OrderPaymentInstrument, custom : Object) : Status

Called when a request is to be made to authorize payment for the given order.

Method Detail
afterAuthorization
afterAuthorization(order : Order, payment : OrderPaymentInstrument, custom : Object, status : Status) : Status

Called after the response has been handled for a request to authorize payment for the given order.

The given status is the result of handling the response without customization. That status will be used unless an implementation of this hook returns an alternative status.

Parameters:
order - the order whose payment to authorize
payment - the payment instrument to authorize
custom - container of custom properties included in the PSP response
status - the result of handling the response without customization
Returns:
a non-null result ends the hook execution

beforeAuthorization
beforeAuthorization(order : Order, payment : OrderPaymentInstrument, custom : Object) : Status

Called when a request is to be made to authorize payment for the given order.

Return an error status to indicate a problem. The request will not be made to the payment provider.

Parameters:
order - the order whose payment to authorize
payment - the payment instrument to authorize
custom - container for custom properties to include in request
Returns:
a non-null result ends the hook execution