dw.extensions.payments
Class SalesforcePaymentRequest
Object
dw.extensions.payments.SalesforcePaymentRequest

Commerce Cloud Payments request for a shopper to make payment. See Commerce Cloud Payments documentation for how to gain access and configure it for use on your sites.

A request is required to render payment methods and/or express checkout buttons using <ispayment> or <isbuynow>. You can call methods on the payment request to configure which payment methods and/or express checkout buttons may be presented, and customize their visual presentation.

When used with <isbuynow> you must provide the necessary data to prepare the shopper basket to buy the product, and the necessary payment request options for the browser payment app.

Constants
ELEMENT_CARD_CVC  :  String = "cardCvc"
Element for the Stripe credit card CVC field "cardCvc".
ELEMENT_CARD_EXPIRY  :  String = "cardExpiry"
Element for the Stripe credit card expiration date field "cardExpiry".
ELEMENT_CARD_NUMBER  :  String = "cardNumber"
Element for the Stripe credit card number field "cardNumber".
ELEMENT_IBAN  :  String = "iban"
Element for the Stripe IBAN field "iban".
ELEMENT_IDEAL_BANK  :  String = "idealBank"
Element for the Stripe iDEAL bank selection field "idealBank".
ELEMENT_PAYMENT_REQUEST_BUTTON  :  String = "paymentRequestButton"
Element for the Stripe payment request button "paymentRequestButton".
ELEMENT_TYPE_APPLEPAY  :  String = "applepay"
Element type name for Apple Pay payment request buttons.
ELEMENT_TYPE_BANCONTACT  :  String = "bancontact"
Element type name for Bancontact.
ELEMENT_TYPE_CARD  :  String = "card"
Element type name for credit cards.
ELEMENT_TYPE_IDEAL  :  String = "ideal"
Element type name for iDEAL.
ELEMENT_TYPE_PAYMENTREQUEST  :  String = "paymentrequest"
Element type name for other payment request buttons besides Apple Pay, like Google Pay.
ELEMENT_TYPE_SEPA_DEBIT  :  String = "sepa_debit"
Element type name for SEPA debit.
Properties
basketData  :  Object
A JS object containing the data used to prepare the shopper basket when a Buy Now button is tapped.
static ELEMENT_CARD_CVC  :  String
Element for the Stripe credit card CVC field "cardCvc".
static ELEMENT_CARD_EXPIRY  :  String
Element for the Stripe credit card expiration date field "cardExpiry".
static ELEMENT_CARD_NUMBER  :  String
Element for the Stripe credit card number field "cardNumber".
static ELEMENT_IBAN  :  String
Element for the Stripe IBAN field "iban".
static ELEMENT_IDEAL_BANK  :  String
Element for the Stripe iDEAL bank selection field "idealBank".
static ELEMENT_PAYMENT_REQUEST_BUTTON  :  String
Element for the Stripe payment request button "paymentRequestButton".
static ELEMENT_TYPE_APPLEPAY  :  String
Element type name for Apple Pay payment request buttons.
static ELEMENT_TYPE_BANCONTACT  :  String
Element type name for Bancontact.
static ELEMENT_TYPE_CARD  :  String
Element type name for credit cards.
static ELEMENT_TYPE_IDEAL  :  String
Element type name for iDEAL.
static ELEMENT_TYPE_PAYMENTREQUEST  :  String
Element type name for other payment request buttons besides Apple Pay, like Google Pay.
static ELEMENT_TYPE_SEPA_DEBIT  :  String
Element type name for SEPA debit.
exclude  :  Set  (Read Only)

Returns a set containing the element types to be explicitly excluded from mounted components. See the element type constants in this class for the full list of supported element types.

Note: if an element type is both explicitly included and excluded, it will not be presented.

ID  :  String  (Read Only)
The identifier of this payment request.
include  :  Set  (Read Only)

Returns a set containing the specific element types to include in mounted components. If the set is empty then all applicable and enabled element types will be included by default. See the element type constants in this class for the full list of supported element types.

Note: if an element type is both explicitly included and excluded, it will not be presented.

selector  :  String  (Read Only)
The DOM element selector where to mount payment methods and/or express checkout buttons.
Constructor Summary
SalesforcePaymentRequest(id : String, selector : String)
Constructs a payment request using the given identifiers.
Method Summary
addExclude(elementType : String) : void

Adds the given element type to explicitly exclude from mounted components.

addInclude(elementType : String) : void

Adds the given element type to include in mounted components.

static calculatePaymentRequestOptions(basket : Basket, options : Object) : Object

Returns a JS object containing the payment request options to use when a Pay Now button is tapped, in the appropriate format for use in client side JavaScript, with data calculated from the given basket.

static format(options : Object) : Object

Returns a JS object containing the payment request options to use when a Buy Now button is tapped, in the appropriate format for use in client side JavaScript.

getBasketData() : Object
Returns a JS object containing the data used to prepare the shopper basket when a Buy Now button is tapped.
getExclude() : Set

Returns a set containing the element types to be explicitly excluded from mounted components.

getID() : String
Returns the identifier of this payment request.
getInclude() : Set

Returns a set containing the specific element types to include in mounted components.

getSelector() : String
Returns the DOM element selector where to mount payment methods and/or express checkout buttons.
setBasketData(basketData : Object) : void

Sets the data used to prepare the shopper basket when a Buy Now button is tapped.

setOptions(options : Object) : void

Sets the payment request options to use when a Buy Now button is tapped.

setReturnController(returnController : String) : void
Sets the controller to which to redirect when the shopper returns from a 3rd party payment website.
setSavePaymentMethodEnabled(savePaymentMethodEnabled : boolean) : void
Sets if mounted components may provide a control for the shopper to save their payment method for later use.
setStripeCreateElementOptions(element : String, options : Object) : void
Sets the the options to pass into the Stripe elements.create call for the given element type.
setStripeElementsOptions(options : Object) : void
Sets the the options to pass into the stripe.elements call.
Methods inherited from class Object
Constructor Detail
SalesforcePaymentRequest
public SalesforcePaymentRequest(id : String, selector : String)
Constructs a payment request using the given identifiers.
Parameters:
id - identifier for payment request
selector - DOM element selector where to mount payment methods and/or express checkout buttons
Throws:
Exception - if id or selector is null

Method Detail
addExclude
addExclude(elementType : String) : void

Adds the given element type to explicitly exclude from mounted components. It is not necessary to explicitly exclude element types that are not enabled for the site, or are not applicable for the current shopper and/or their basket. See the element type constants in this class for the full list of supported element types.

Note: if an element type is both explicitly included and excluded, it will not be presented.

Parameters:
elementType - element type
See Also:

addInclude
addInclude(elementType : String) : void

Adds the given element type to include in mounted components. Call this method to include only a specific list of element types to be presented when applicable and enabled for the site. See the element type constants in this class for the full list of supported element types.

Note: if an element type is both explicitly included and excluded, it will not be presented.

Parameters:
elementType - element type
See Also:

calculatePaymentRequestOptions
static calculatePaymentRequestOptions(basket : Basket, options : Object) : Object

Returns a JS object containing the payment request options to use when a Pay Now button is tapped, in the appropriate format for use in client side JavaScript, with data calculated from the given basket. This method is provided as a convenience to calculate updated payment request options when the shopper basket has changed. Data in the given options object like total, displayItems, and shippingOptions will be replaced in the returned object by values recalculated from the given basket and applicable shipping methods.

The following example shows the resulting output for a basket and sample options.


SalesforcePaymentRequest.calculatePaymentRequestOptions(basket, {
    requestPayerName: true,
    requestPayerEmail: true,
    requestPayerPhone: false,
    requestShipping: true
});
 

returns


{
    currency: 'gbp',
    total: {
        label: 'Total',
        amount: '2644'
    },
    displayItems: [{
        label: 'Subtotal',
        amount: '1919'
    }, {
        label: 'Tax',
        amount: '126'
    }, {
        label: 'Ground',
        amount: '599'
    }],
    requestPayerName: true,
    requestPayerEmail: true,
    requestPayerPhone: false,
    requestShipping: true,
    shippingOptions: [{
        id: 'GBP001',
        label: 'Ground',
        detail: 'Order received within 7-10 business days',
        amount: '599'
    },{
        id: 'GBP002',
        label: 'Express',
        detail: 'Order received within 2-4 business days',
        amount: '999'
    }]
}
 
Parameters:
basket - No Comment In JavaDoc
options - JS object containing payment request options in B2C Commerce API standard format
Returns:
JS object containing equivalent payment request options in Stripe JS API format

format
static format(options : Object) : Object

Returns a JS object containing the payment request options to use when a Buy Now button is tapped, in the appropriate format for use in client side JavaScript. This method is provided as a convenience to adjust values in B2C Commerce API standard formats to their equivalents as expected by Stripe JS APIs. The following example shows options set in B2C Commerce API format, and the resulting output.


SalesforcePaymentRequest.format({
    currency: 'GBP',
    total: {
        label: 'Total',
        amount: '26.44'
    },
    displayItems: [{
        label: 'Subtotal',
        amount: '19.19'
    }, {
        label: 'Tax',
        amount: '1.26'
    }, {
        label: 'Ground',
        amount: '5.99'
    }],
    requestPayerPhone: false,
    shippingOptions: [{
        id: 'GBP001',
        label: 'Ground',
        detail: 'Order received within 7-10 business days',
        amount: '5.99'
    }]
});
 

returns


{
    currency: 'gbp',
    total: {
        label: 'Total',
        amount: '2644'
    },
    displayItems: [{
        label: 'Subtotal',
        amount: '1919'
    }, {
        label: 'Tax',
        amount: '126'
    }, {
        label: 'Ground',
        amount: '599'
    }],
    requestPayerPhone: false,
    shippingOptions: [{
        id: 'GBP001',
        label: 'Ground',
        detail: 'Order received within 7-10 business days',
        amount: '599'
    }]
}
 
Parameters:
options - JS object containing payment request options in B2C Commerce API standard format
Returns:
JS object containing equivalent payment request options in Stripe JS API format

getBasketData
getBasketData() : Object
Returns a JS object containing the data used to prepare the shopper basket when a Buy Now button is tapped.
Returns:
JS object containing the basket data

getExclude
getExclude() : Set

Returns a set containing the element types to be explicitly excluded from mounted components. See the element type constants in this class for the full list of supported element types.

Note: if an element type is both explicitly included and excluded, it will not be presented.

Returns:
set of element types
See Also:

getID
getID() : String
Returns the identifier of this payment request.
Returns:
payment request identifier

getInclude
getInclude() : Set

Returns a set containing the specific element types to include in mounted components. If the set is empty then all applicable and enabled element types will be included by default. See the element type constants in this class for the full list of supported element types.

Note: if an element type is both explicitly included and excluded, it will not be presented.

Returns:
set of element types
See Also:

getSelector
getSelector() : String
Returns the DOM element selector where to mount payment methods and/or express checkout buttons.
Returns:
DOM element selector

setBasketData
setBasketData(basketData : Object) : void

Sets the data used to prepare the shopper basket when a Buy Now button is tapped. For convenience this method accepts a JS object to set all of the following properties at once:

  • sku - SKU of the product to add exclusively to the basket (required)
  • quantity - integer quantity of the product, default is 1
  • shippingMethod - ID of the shipping method to set on the shipment, default is the site default shipping method for the basket currency
  • options - JS array containing one JS object per selected product option, default is no selected options
    • id - product option ID
    • valueId - product option value ID

The following example shows how to set all of the supported basket data.


request.setBasketData({
    sku: 'tv-pdp-6010fdM',
    quantity: 1,
    shippingMethod: '001',
    options: [{
        id: 'tvWarranty',
        valueId: '000'
    }]
});
 
Parameters:
basketData - JS object containing the basket data
See Also:

setOptions
setOptions(options : Object) : void

Sets the payment request options to use when a Buy Now button is tapped. For convenience this method accepts a JS object to set all options at once. The following example shows how to set options including currency, labels, and amounts, in B2C Commerce API format.


request.setOptions({
    currency: 'GBP',
    total: {
        label: 'Total',
        amount: '26.44'
    },
    displayItems: [{
        label: 'Subtotal',
        amount: '19.19'
    }, {
        label: 'Tax',
        amount: '1.26'
    }, {
        label: 'Ground',
        amount: '5.99'
    }],
    requestPayerPhone: false,
    shippingOptions: [{
        id: 'GBP001',
        label: 'Ground',
        detail: 'Order received within 7-10 business days',
        amount: '5.99'
    }]
});
 

The total option must match the total that will result from preparing the shopper basket using the data provided to setBasketData(Object) in this request. The id of each JS object in the shippingOptions array must equal the ID of the corresponding site shipping method that the shopper may select in the browser payment app.

For more information on the available payment request options see the Stripe Payment Request object API documentation.

Note: The Stripe Payment Request country option will be set automatically to the country of the Salesforce Payments account associated with the Commerce Cloud instance and is not included here.

Parameters:
options - JS object containing the payment request options

setReturnController
setReturnController(returnController : String) : void
Sets the controller to which to redirect when the shopper returns from a 3rd party payment website. Default is the controller for the current page.
Parameters:
returnController - return controller, such as "Cart-Show"

setSavePaymentMethodEnabled
setSavePaymentMethodEnabled(savePaymentMethodEnabled : boolean) : void
Sets if mounted components may provide a control for the shopper to save their payment method for later use. When set to false no control will be provided. When set to true a control may be provided, if applicable for the shopper and presented payment method, but is not guaranteed.
Parameters:
savePaymentMethodEnabled - if mounted components may provide a control for the shopper to save their payment method

setStripeCreateElementOptions
setStripeCreateElementOptions(element : String, options : Object) : void
Sets the the options to pass into the Stripe elements.create call for the given element type. For more information see the Stripe Elements API documentation.
Parameters:
element - name of the Stripe element whose creation to configure
options - JS object containing the options

setStripeElementsOptions
setStripeElementsOptions(options : Object) : void
Sets the the options to pass into the stripe.elements call. For more information see the Stripe Elements API documentation.
Parameters:
options - JS object containing the options

X Privacy Update: We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used. By continuing to use this site you are giving us your consent to do this. Privacy Policy.