LogoLogo
System Status
  • Commerce API
    • Test and use cases
    • Roles and permissions
    • Sending API calls
  • Shopper APIs
    • Shopper basics
      • Common use cases
        • Creating a customer
        • Applying store credit
        • Private store workflow
        • Guest checkout
    • OAuth
      • Authentication
      • OAuth 2.0 APIs
      • Token
      • Access tokens
      • Session-aware access tokens
      • Authorizing a shopper
    • Shoppers
      • Managing shoppers
        • User management
        • Single sign-on (SSO)
        • Data validation
        • Bulk user management
        • Bulk user account export
      • Managing a shopper's account
      • Managing a shopper's address
      • Managing payment options
    • Product discovery
      • Categories
      • Products
      • Product variations
      • Pricing
      • Inventory status
      • Financing
      • Offers
        • Understanding offers
        • How to use point of promotions (POPs)
          • Retrieving all point of promotion offers for a specific product
          • Retrieving all offers for a specific point of promotion
        • How to use offers
      • Private stores
        • Managing private stores
        • Submitting an order for a private store
        • Useful APIs
      • Fulfillment
        • Electronic Fulfillment Service (OFI)
        • Digital rights
        • Digital rights revocation
        • Physical fulfillment
          • EDI X12 832 definition data elements
          • EDI X12 846 definition data elements
          • EDI X12 850 definition data elements
          • EDI X12 855 definition data elements
          • EDI X12 856 definition data elements
          • EDI X12 180-1 definition data elements
          • EDI X12 180-2 definition of data elements
          • EDI X12 180-3 definition of data elements
    • Cart
      • Applying a shopper to a cart
      • Getting the current cart
      • Creating or updating a cart
        • Adding a product to a cart
          • Gifting
        • Capturing the customer's IP address
        • Providing address information
        • Managing the shipping or billing address
        • Providing subscription information
        • Managing payment methods
        • Capturing the Terms of Sale (TOS) acceptance
      • Managing offers in a cart
        • Applying an offer
        • Applying a coupon or promo code
        • Getting all applied offers
        • Removing an applied offer
        • Removing eligible offers
        • Reconciling conflicting offers
        • Dynamic offers/personalization
          • Skipping Global Commerce merchandising offer arbitration
          • Triggering a promotional URL offer
          • Overriding a promotional URL offer discount
      • Pricing
        • Landed cost
          • Mixed cart support
          • Tax-included pretty price
      • Redirecting to a Digital River-hosted cart
      • Configuring taxes
        • Managing tax identifiers
      • Managing shipping options
        • Getting shipping options
        • Providing a shipping discount
      • Managing line items
      • Applying a price override
      • Managing payment sessions
      • Managing web checkout
      • Submitting a cart
        • Initiating a charge
        • Authorization declines
      • Resuming cart submission
      • HGOP2
    • Orders
      • Getting orders
      • Selling entities
      • Retrieving addresses from an order
      • Retrieving line items from an order
      • Order lookup
      • Returns
        • Initiate an authenticated session
        • Setting up returns in Global Commerce
        • Managing returns
    • Subscriptions
      • Retrieve the subscription
        • Getting all orders for a subscription
        • Getting a subscription's pending actions
        • Getting all subscriptions for a shopper
        • Getting a subscription by identifier
      • Update subscription at the next renewal
        • Changing the subscription renewal type
        • Changing the subscription renewal quantity
        • Adding or updating a perpetual unit price
        • Changing the subscription's payment option
        • Changing the subscription's payment source
      • Immediately change the subscription
        • Updating the subscription's shipping address
        • Updating a subscription's billing and shipping email address
        • Cancelling a subscription
      • Immediately apply a midterm subscription change
        • Reducing the subscription renewal quantity
  • Admin APIs
    • Admin basics
      • Available Admin API calls
    • Order management
      • Getting the order's details
      • Downloading the invoice
    • Offer management
    • Refund management
      • Authorization
      • Refund reason codes
      • Creating a satisfaction refund
      • Getting the available refunds for a specific order
      • Getting refunds for a specific order
      • Getting refunds available for a shopper's order
      • Getting the JSON schema for an order refund
      • Managing a refund for a delayed payment method
      • Refund error scenarios
    • Subscription management
      • Retrieve the subscription
        • Getting all orders for a subscription
        • Getting a subscription's pending actions
        • Getting all subscriptions for a shopper
        • Getting a subscription by identifier
      • Update the subscription at the next renewal
        • Changing the subscription renewal type
        • Changing the subscription renewal product
        • Changing the subscription renewal price
        • Changing the subscription renewal quantity
        • Adding or updating a perpetual unit price
        • Changing the subscription's payment option
        • Changing the subscription's payment source
      • Immediately change the subscription
        • Activating a subscription
        • Changing the subscription's external reference identifier
        • Updating a subscription's billing and shipping email address
        • Cancelling a subscription
        • Updating the subscription's expiration date
      • Immediately apply a midterm subscription change
        • Applying a midterm change with price override
        • Reducing the subscription renewal quantity
      • Subscription notifications
        • Updating the subscriber's email address
        • Card Account Updater
        • Sending a payment information change notification
        • Sending an expired credit card notification
        • Sending an invalid payment account notification
        • Sending a payment failure notification
        • Sending a subscription renewal reminder notification
        • Setting up subscription renewal reminders
        • Setting up trial subscription renewal reminders
        • Setting up marketing reminders
      • Using the Expired Card Optimizer
    • Customer management
      • Retrieving customer details
      • Requesting PII removal for a customer
    • Site management
      • Configuring authorized shipping and billing countries
      • Getting a site's authorized billing countries
      • Getting a site's authorized shipping countries
    • Product management
      • Getting started
      • Manage products (asynchronous API)
        • Creating or updating a product
        • Adding or updating a product variation
        • Deploying a product
        • Applying live changes
        • Retiring a product
        • Deleting a product variation
        • Deleting a base or individual product's locale
      • Retrieve products (synchronous API)
        • Getting a product by locale
        • Getting a product variation
        • Getting a product variation by locale
      • Get the task status for a product (synchronous API)
        • Getting the latest information on a product task
        • Retrieving the tasks for a specific product
        • Retrieving the tasks for products
      • Bulk operation
        • Asynchronous bulk operations
          • Creating products in bulk
          • Updating products in bulk
          • Deploying products in bulk
          • Deleting product variations in bulk
        • Bulk product upload (BPU)
        • Bulk Product Export (BPE)
          • Line-item level satisfaction refund
          • Order-level satisfaction refund
          • Auto-created line-item level return product
          • Line-item level return product
    • File management
      • Downloading a file
  • Payments
    • Payments solutions
      • Drop-in payments
        • How Drop-in payments work
        • Drop-in payments integration guide
      • DigitalRiver.js with Elements
        • Elements integration guide
        • Configuring payment methods
          • Configuring Afterpay
          • Configuring Alipay+ (cross-border)
          • Configuring Alipay (domestic)
          • Configuring Amazon Pay
          • Configuring Apple Pay
          • Configuring Bancontact
          • Configuring BLIK
          • Configuring Boleto
          • Configuring CCAvenue
          • Configuring Clearpay
          • Configuring Credit Cards
          • Configuring FPX Online Banking
          • Configuring Google Pay
          • Configuring iDEAL
          • Configuring Klarna
          • Configuring Konbini
          • Configuring Online Banking (IBP)
          • Configuring Online Banking (Korea Bank Transfer)
          • Configuring PayCo
          • Configuring PayPal
          • Configuring SEPA Direct Debit
          • Configuring Trustly
          • Configuring Wire Transfer
          • Common payment sources
          • Common payment objects
    • Supported payment methods
      • Afterpay
      • Alipay (domestic)
      • Alipay+ (cross-border)
      • Amazon Pay
      • Apple Pay
      • Bancontact
      • BLIK
      • Boleto
      • CCAvenue
      • Clearpay
      • Credit Cards
      • FPX Online Banking
      • Google Pay
      • iDEAL
      • Klarna
      • Konbini
      • Korea Bank Transfer (Online Banking)
      • Online Banking (IBP)
      • PayCo
      • PayPal
      • PayPal Billing Agreement
      • PayPal Credit
      • PayPal Pay in 3
      • PayPal Pay in 4
      • PayPal RatenZahlung (Installment Payment)
      • SEPA Direct Debit
      • Trustly
      • Wire Transfer
    • Source basics
      • Managing sources
      • Handling credit card sources
      • Retrieving sources
    • Building payment workflows
      • Flows by payment type
      • Handling redirect payment methods
    • PSD2 and SCA
    • Payment testing scenarios
      • Testing standard payment methods
      • Testing redirect payment methods
      • Testing receiver payment methods
      • Testing the CCAvenue payment method
  • Events
    • Events overview
    • Responding to events
    • Event types
      • Delayed payment event types
        • Delayed payment expired event
          • Boleto
          • Konbini
          • Wire Transfer
        • Delayed payment reminder event
          • Boleto
          • Konbini
          • Wire Transfer
      • Subscription event types
        • Subscription created event
        • Subscription updated event
        • Subscription action processed event
        • Subscription cancelled event
        • Subscription credit card expired event
        • Subscription payment information changed event
        • Subscription renewal reminder event
        • Subscription renewed event
        • Subscription trial converted event
        • Subscription trial renewal reminder event
        • Subscription payment failed event
      • Post-order event types
        • Invoice created event
        • Refund credit memo event
      • Inventory event types
        • Inventory out of stock event
        • Inventory source and management
        • Inventory self-managed updated event
        • Inventory fulfiller-managed updated event
      • Post-order Notification Integration Guide
    • Webhooks
      • Commerce API safelist
      • Searching for a webhook
      • Creating a webhook
      • Using webhooks
      • Editing a webhook
      • Turning webhooks on or off
      • Revealing a webhook's secret
      • Rotating a webhook's secret
      • Viewing the webhook details
      • Deleting a webhook
  • Developer Resources
    • Postman collection
    • Commerce API references
    • Shopper APIs reference
    • Admin APIs reference
    • DigitalRiver.js reference
      • Including DigitalRiver.js
      • Initializing DigitalRiver.js
      • DigitalRiver object
      • Elements
        • Amazon Pay element
        • Apple Pay elements
        • Google Pay elements
        • IBAN element
        • iDEAL element
        • Konbini elements
        • Compliance element
        • Offline refund element
        • Online Banking elements
        • Tax Identifier element
        • Delayed payment instructions element
        • PayPal elements
      • Guidelines for capturing payment details
      • Security
      • Digital River payment objects
      • Error types, codes, and objects
  • General resources
    • Global Commerce
    • Global Commerce
      • Company hierarchy
      • Categories
        • Getting a list of categories
      • Products
        • Product scenarios
        • Individual products
          • Creating an individual product
        • Base product with variants
          • Creating a base product with variants
        • Bundle offers
          • Creating a prorated bundle offer with a subscription
        • Product combination
          • Creating a product combination
        • Gifting
        • Inventory status
      • Customer service
        • Log a shopper's request to remove PII
      • Customers
        • Creating a customer
        • Digital River-maintained customer login
        • Client-maintained customer login
      • Transparent Commerce purchase flow
    • eCompass
    • eCompass documentation
    • Release notes
      • 2024
      • 2024 latest
      • 2023
      • 2022
      • 2021
      • 2020
Powered by GitBook
On this page
  • element.mount();
  • element.on();
  • Blur
  • Cancel
  • Change
  • Click
  • Focus
  • Ready
  • Return
  • Shipping address change
  • Shipping option change
  • Source
  • Element functions
  • element.blur();
  • element.clear();
  • element.focus();
  • element.destroy();
  • element.unmount();
  • element.update(options);
  • Styling an element container
  • Custom classes
  • Custom styles
  • Pseudo-classes
  • Other customizable attributes

Was this helpful?

  1. Developer Resources
  2. DigitalRiver.js reference

Elements

Learn how to customize and stylize elements to seamlessly integrate them into your user experience or purchase flow.‌

PreviousDigitalRiver objectNextAmazon Pay element

Last updated 11 months ago

Was this helpful?

An Element is a UI component that creates to collect sensitive customer information without having the data touch your servers. You can customize and stylize these components to seamlessly integrate into your user experience or purchase flow. The library collects and tokenizes the data contained in these elements without exposing you to PCI-compliance liability.‌

element.mount();

Use this function to place the created elements on your page. The function accepts an identifier of a container div. The library will load the created element within the specified container.

<form id="payment-form">
    <div id="card-number"></div>
    <div id="card-expiration"></div>
    <div id="card-cvv"></div>
    <button type="submit">Submit</button>
</form>
 
 
cardNumber.mount('card-number');
cardExpiration.mount('card-expiration');
cardCVV.mount('card-cvv');

element.on();

Use this function to listen to events that you can use to build and enhance your purchase flow.

Event
Trigger When
Applies To

The element has lost focus.

cardnumber, cardexpiration, cardcvv, onlinebanking

The customer has canceled the experience.

applepay, googlepay

The element's state has changed.

cardnumber, cardexpiration, cardcvv, onlinebanking

A shopper clicked the element's button.

applepay, googlepay

The element has gained focus.

cardnumber, cardexpiration, cardcvv, onlinebanking

The created element is loaded and ready to accept an update request.

cardnumber, cardexpiration, cardcvv, applepay, googlepay, onlinebanking

The shopper has pressed the Return key while focused in the input field.

cardnumber, cardexpiration, cardcvv

The customer has chosen a different address than was previously selected. You should use this data to re-price your order totals (if applicable).

applepay, googlepay

The customer has chosen a different shipping option than was previously selected. You should use this data to re-price your order totals (if applicable).

applepay, googlepay

The customer has authorized the payment and a source, and DigitalRiver.js returned associated data.

applepay, googlepay

Blur

A Blur event triggers when an element loses focus.

cardNumber.on('blur', function(event) {
    console.log('card number blur', event);
});
{
    elementType: "cardnumber"
}
{
    elementType: "cardnumber"
}

Cancel

A Cancel event occurs when the customer closes the Apple Pay Element Payment Request interface.

applepay.on('cancel', function(event) {
    //do stuff
}
{
    elementType: "applepay"
}

Change

A Change event triggers when an element changes state.‌

cardNumber.on('change', function(event) {
    console.log('card number change', event);
});
{
    brand: "unknown",
    complete: false,
    empty: true,
    elementType: "cardnumber",
    error: null
}

Invalid element change event example

{
    brand: "unknown",
    complete: true,
    empty: false,
    elementType: "cardnumber",
    "error": {
        "type": "validation_error",
        "code": "invalid_card_number",
        "message": "Your card number is invalid."
    }
}

Incomplete element change event example

{
    brand: "unknown",
    complete: false,
    empty: false,
    elementType: "cardnumber",
    error: {
        "type": "validation_error",
        "code": "incomplete_card_number",
        "message": "Your card number is incomplete."
    }
}

Error types, codes, messages

Error Scenario
Error Type
Error Code
Error Message

Credit Card Number field is incomplete.

validation-error

invalid_card_number

Your card number is invalid.

Credit Card Number field is complete but invalid.

validation-error

incomplete_card_number

Your card number is incomplete.

Card Security Code is incomplete

validation-error

invalid_expiration_month

Your card's expiration month is invalid.

Card Security Code is complete but invalid.

validation-error

invalid_expiration_year

Your card's expiration year is in the past.

Card Expiration field is incomplete.

validation-error

invalid_expiration_date

Your card's expiration date is invalid.

Card Expiration Date is complete but the date is invalid.

validation-error

incomplete_expiration_date

Your card's expiration date is incomplete.

Card Expiration Date is complete but has an invalid year.

validation-error

invalid_security_code

Your card's security code is invalid.

Card Expiration Date is complete but has an invalid month.

validation-error

incomplete_security_code

Your card's security code is incomplete.

Card brands‌

The following table lists the supported credit card brands.

Brand
Key

Visa

visa

MasterCard

mastercard

American Express

amex

Diners Club

dinersclub

Discover

discover

UnionPay

unionpay

JCB

jcb

Maestro

maestro

Forbrugsforeningen

forbrugsforeningen

Dankort

dankort

Click

A Click event occurs when the customer clicks an Apple Pay Element.

applepay.on('click', function(event) {
    //do stuff
}
{
    elementType: "applepay"
}

Focus

A Focus event triggers when an element gains focus.

cardNumber.on('ready', function(event) {
    console.log('card number ready', event);
});
{    
    elementType: "cardnumber"
}

Ready

A Ready event triggers when an element is ready and able to receive blur(), focus(), or update() calls.

cardNumber.on('focus', function(event) {
    console.log('card number focus', event);
});
{
    elementType: "cardnumber"
}

Return

A Return event triggers when a customer presses the Return key while the input field has focus.

cardNumber.on('return', function(event) {
    console.log('card number return', event);
});
{
    elementType: "cardnumber"
}

Shipping address change

A Shipping Address Change event occurs when the Customer has selected a different Shipping Address within the Payment Request interface. The event will create the following object structure.

Key
Type
Description

updateWith

Function

shippingAddress

​

applepay.on('shippingaddresschange', function(event) {
    var shippingAddress = event.shippingAddress;
  
  
    //create a Payment Request Details Update Object
    var newDetails = createPaymentRequestDetailsUpdateObject();
      
    event.updateWith(newDetails);
});

Apple Pay shipping address change object

{
    shippingAddress: {
        "name": "John Smith",
        "firstName": "John",
        "lastName": "Smith",
        "phone": "952-111-1111",
        "email": "jsmith@digitalriver.com",
        "address": {
            "line1": "10380 Bren Rd W",
            "line2": "string",
            "city": "Minnetonka",
            "postalCode": "55129",
            "state": "MN",
            "country": "US"
        }
    },
    "updateWith": function(data) {
        callback(data);
    }
}

Shipping option change

A Shipping Option Change event occurs when the Customer has selected a different Shipping Option within the Payment Request interface. The event will emit the following object structure.

Key
Type
Description

updateWith

Function

shippingOption

​

​

applepay.on('shippingaddresschange', function(event) {
    var shippingAddress = event.shippingAddress;
  
  
    //create a Payment Request Details Update Object
    var newDetails = createPaymentRequestDetailsUpdateObject();
      
    event.updateWith(newDetails);
});

Apple Pay shipping option change object

{
    "shippingOption": {
        "id": "overnight-shipping",
        "label": "Overnight Shipping",
        "amount": 100,
        "detail": "Get this in 1 business day."
    },
    "updateWith": function(data) {
        callback(data);
    }
}

Source

googlepay.on('source', function(result) {
    var source = result.source;
     
    //pass the source to your back end for further processing
}

Element functions

Use these functions to trigger functionality within the specified Element to further enhance your purchase flow experience.‌

element.blur();

This function triggers the blur() event. This will remove the focus from the element.

cardNumber.blur();

element.clear();

This function clears the contents of the element.

cardNumber.clear();

element.focus();

This function triggers the focus() event and places the focus on the element.

cardNumber.destroy();

element.destroy();

This function destroys the element. Removes the element and all of its associated data so you cannot use it again. You must create a new element if you want to restore the associated data.

cardNumber.destroy();

element.unmount();

This function removes the element from the Document Object Module (DOM). The element and its associated data still exists. You can place it on the page again by calling its mount() function.

cardNumber.unmount();

element.update(options);

This function updates the element with any included options. This can include custom styles and classes.

var options = {
    classes: {
        base: "DRElement",
        complete: "complete",
        empty: "empty",
        focus: "focus",
        invalid: "invalid",
        webkitAutofill: "autofill"
    },
    style: {
        base: {
            color: "#fff",
            fontFamily: "Arial, Helvetica, sans-serif",
            fontSize: "20px",
            fontSmoothing: "auto",
            fontStyle: "italic",
            fontVariant: "normal",
            letterSpacing: "3px"
        },
        empty: {
            color: "#fff"
        },
        complete: {
            color: "green"
        },
        invalid: {
            color: "red"
        }
    }
};
 
cardNumber.update(options);

Styling an element container

Custom classes

You can specify custom classes as part of a Class object included within the Options object when you create or update an element. If you do not provide custom classes, the system uses the default options.

var options = {
    classes: {
        base: "DRElement",
        complete: "complete",
        empty: "empty",
        focus: "focus",
        invalid: "invalid",
        webkitAutofill: "autofill"
    }
}
 
var cardNumber = elements.create("cardnumber", options);

Available custom classes

Class Type
ID
Applies When
Default Class Name

Base

base

The Element is in its base state. The user either has not entered anything into the input field or is currently typing.

DRElement

Complete

complete

The Element is in its complete state. The user has input value, and it meets the basic validation requirements of that field.

DRElement--complete

Empty

empty

The Element is empty. The Element once had value but is now empty.

DRElement--empty

Focus

focus

The Element has focus.

DRElement--focus

Invalid

invalid

The Element has value, but it does not meet the basic validation requirements of the field.

DRElement--invalid

WebKit Autofill

webkitAutofill

A saved card stored in a browser automatically fills this element.

DRElement-webkit-autofill

Custom styles

You can specify custom styles as part of a Style object included within the Options object when creating or updating an Element. If you don't provide custom styles, the system uses the browser defaults.

var options = {
    style: {
        base: {
            color: "#fff",
            fontFamily: "Arial, Helvetica, sans-serif",
            fontSize: "20px",
            fontSmoothing: "auto",
            fontStyle: "italic",
            fontVariant: "normal",
            letterSpacing: "3px"
        },
        empty: {
            color: "#fff"
        },
        complete: {
            color: "green"
        },
        invalid: {
            color: "red",
        }
    }
}
 
 
var cardNumber = elements.create('cardnumber', options);

Available custom style classes

ID
Class Name
Description

base

Base

All other variants inherit from this style.

complete

Complete

Applied when the Element has valid input.

empty

Empty

Applied when the Element has no customer input.

focus

Focus

Applied when the Element has focus.

invalid

Invalid

Applied when the Element has invalid input.

webKitAutofill

Webkit Autofill

Applied when the Element has been filled automatically by a browser.

Available custom styles

Style
ID
Type
Example

Box Shadow

boxShadow

string

inset 0 0 0px 1000px #fff

Text Color

color

string

"#fff"

Font Family

fontFamily

string

"Arial, Helvetica, sans-serif",

Font Size

fontSize

string

"20px"

Font Smoothing

fontSmoothing

string

"antialiased"

Font Style

fontStyle

string

"bold"

Font Variant

fontVariant

string

"normal"

Letter Spacing

letterSpacing

string

"2px"

Text Align

textAlign

string

"center"

Text Decoration

textDecoration

string

"underline"

Text Shadow

textShadow

string

"2px 2px #ff0000"

Font Weight

fontWeight

string

"400"

Padding

padding

string

"2px"

Padding Top

paddingTop

string

"2px"

Padding Right

paddingRight

string

"2px"

Padding Bottom

paddingBottom

string

"2px"

Padding Left

paddingLeft

string

"2px"

Pseudo-classes

Class
ID
Type

:hover

:hover

string

:focus

:focus

string

::placeholder

::placeholder

string

::selection

::selection

string

:-webkit-autofill

:-webkit-autofill

string

:disabled

:disabled

string

Other customizable attributes

Attribute
ID
Type
Example
Description
Example

Placeholder Text

placeholderText

string

"Card Number"

You may override the placeholder text that appears in cardnumber, cardexpiration, cardcvv, and onlinebanking element types. If you specify a placeholderText attribute, localization will not be applied.

Mask

mask

boolean

true/false

You may choose to mask the contents of the DigitalRiver.js Element after a proper number and card security code has been implemented. If enabled, only the last 4 digits of the card number will be exposed in the view.

​

​

If an error is detected, Digital River will return a with the event payload.

Calling this function with a merges your updates into the current Payment Request object.

A

A that contains the customer's Shipping Address.

Calling this function with a merges your updates into the current .

A

A that contains the customer's chosen Shipping Option.

A Source event occurs when the Customer completes their interaction with the Payment Request interface and creates a Payment Source. The emitted object will be a .

DigitalRiver.js
​blur​
​cancel​
​change​
click​
focus​
​ready​
return
​shippingaddresschange
​shippingoptionchange​
source​
Change Event Error object
Payment Request Response object
Payment Request Details Update object
Payment Request Details Update object​
Shipping Address object
Payment Request Details Update object
Payment Request object
Payment Request Details Update object​
Payment Request Shipping Option object