Afterpay.js Reference

HTML Dataset Attributes

The <afterpay-placement> web component is configurable via a set of data attributes

For Placements initialized through JavaScript, all attributes should be provided in camel-case.

See Mozillas reference on dataset naming conversion for more information.

EnvironmentURL
Sandboxhttps://portal.sandbox.afterpay.com/afterpay.js
Productionhttps://portal.afterpay.com/afterpay.js

Attribute List

AttributeAccepted Values
amountA Number - see the Definition.
amount-selectorA CSS Selector in the DOM - see the Definition.
amount-mutation-selectorAny CSS Selector in the DOM - see the Definition.
badge-themeBlack-on-white, white-on-black, mint-on-black, and black-on-mint. See the Definition.
cart-is-eligibleTrue or false. See the Definition.
cbt-enabledTrue or false. See the Definition.
currencyAUD, CAD, EUR, GBP, NZD and USD - see the Definition.
data-amount-rangeJSON stringified array of numbers/strings. See the Definition.
decimal-separator. (period) and , (comma) - see the Definition.
intro-textPay, pay, In, in, Or, or, Pay in, pay in. See the Definition.
is-eligibleTrue or false. See the Definition.
localeen_AU, en_CA, en_GB, en_NZ, en_US, fr_CA. See the Definition
logo-typecompact-badge, badge, or lockup. See the Definition.
lockup-themeblack, white, mint - see the Definition.
mobile-view-layouttwo-by-two or four-by-one - see the Definition
modal-idProvided by Afterpay - see the Definition.
modal-link-stylelearn-more-text, more-info-text, circled-info-icon, circled-question-icon, or none. See the Definition.
modal-thememint or white. See the Definition.
payment-amount-is-boldtrue or false. See the Definition.
price-table-themeblack or white - see the Definition.
show-interest-freeTrue or false. See the Definition.
show-lower-limitTrue or false. See the Definition.
show-upper-limitTrue or false. See the Definition.
show-withTrue or false. See the Definition.
sizexs - 12px, sm - 14px, md - 16px, lg - 18px. See the Definition.
thousands-separator. (period) and , (comma) - see the Definition.
typeprice-table, or price-paragraph - see the Definition.

Amount

The value provided to the AfterpayPlacement through the amount attribute reflects the full price displayed to the customer on the page. The library calculates the installments and displays the messaging appropriately.

On a product page, the amount should be the product price. On the cart page, the amount should be the total.

Accepted Values
Any Integer, or Double with at most 2 significant figures after the decimal separator.

The Afterpay Messaging will automatically calculate the new instalment price when the amount attribute changes.

HTML

1<afterpay-placement data-amount="400"></afterpay-placement>

JavaScript

1const AfterpayPlacement = new Afterpay.AfterpayPlacement()
2AfterpayPlacement.amount = 400;

amount-selector

Accepts the CSS selector corresponding to the price element on the page. The AfterpayPlacement element reads the price text from the page and sets the amount attribute on the component.

This attribute takes the second highest precedence after amount, and if neither are specified the default amount is set to zero.

HTML

1<div class="pdp-wrapper">
2 <span id="productPrice">59.99</span>
3 </div>
4
5<afterpay-placement
6 data-amount-selector ="#productPrice">
7</afterpay-placement>

Configuring the placement with data-amount-selector enables the placement to track updates to the price element. When a change is detected, the installment messaging automatically updates with the new calculated installment amount.

amount-mutation-selector

Accepts any CSS selector corresponding to the “target” element on the page to watch for changes.

When amount-mutation-selector is defined, an attribute to retrieve the current amount on the page must also be defined. There are two ways to achieve this:

  1. Setting data-amount .

  2. Retrieving the price text from data-amount-selector.

HTML

1<afterpay-placement
2 data-amount-mutation-selector = "#targetElement"
3 data-amount-selector ="#productPrice">
4</afterpay-placement>

Useful for eCommerce platforms like Shopify and BigCommerce where the product price is available to template pages.

HTML

1<afterpay-placement
2 data-amount-mutation-selector = "#targetElement"
3 data-amount ="{{product.price}}">
4</afterpay-placement>

badge-theme

Themes specific to data-logo-type = "badge" and data-logo-type="compact-badge"
See the logo-type section for details on switching between logos.

badge-themes.png

cart-is-eligible

Accepted values: true, false
When true, the price paragraph displays the normal installment messaging.
When false, the price paragraph renders Afterpay not available messaging.

For more information, see Set Messaging For Unavailable Items.

cbt-enabled

Displays Afterpay cross border trade information in the modal content.

Cross Border Trade

Permitted in the following regions:

  • Australia 🇦🇺

  • New Zealand 🇳🇿

  • United Kingdom 🇬🇧

currency

When provided, formats the currency for a given locale.

HTML

1<afterpay-placement
2 data-amount="300"
3 data-locale="en_CA"
4 data-currency="USD">
5</afterpay-placement>

currency.png

data-amount-range

When you specify a range of possible prices for a product using the data-amount-range attribute and the data-amount attribute is set to 0, a new messaging variant appears. This new messaging variant is based on the lowest price within the range that fits the minimum and maximum price thresholds set by the merchant.

HTML

1<afterpay-placement
2 data-amount="0"
3 data-locale="en_US"
4 data-min="100"
5 data-max="1000"
6 data-amount-range="[95, 111.11, 222, 333.33, 444, 555.55, 666, 777.777, 888, 999.99, 1111]"
7 data-currency="USD">
8</afterpay-placement>

In the HTML code example above, the message displayed is:

data-amount-range.png

When the above attributes are set and the data-amount is a valid amount, the messaging with the exact instalment amount is displayed.

decimal-separator

Accepts: ".", ","
Sets how the component should parse the provided amount.

intro-text

The first word(s) of the Afterpay Messaging Paragraph.

Accepted Values (Sentence Case)Accepted Values (Lowercase)
Oror
Inin
Paypay
Pay inpay in

HTML

1<afterpay-placement
2 data-amount="300"
3 data-intro-text="Pay in"
4 data-currency="USD">
5</afterpay-placement>

is-eligible

Accepted values: true, false
When true, the price paragraph displays the normal installment messaging.
When false, the price paragraph renders “Afterpay not available” messaging

For more information see Set Messaging For Unavailable Items

locale

Accepted values: en_US, en_AU, en_NZ, en_CA, en_GB, fr_CA

CountryLocaleBrand - Language
United Statesen_USAfterpay - English
Australiaen_AUAfterpay - English
New Zealanden_NZAfterpay - English
Canadaen_CAAfterpay - English
Canadafr_CAAfterpay - French
United Kingdomen_GBAfterpay - English
Note

fr_CA is not currently available using the <square-placement> tag.

logo-type

Accepted values: badge, lockup, compact-badge

BadgeLockupCompact Badge
green-badge.png See badge themes for all variants![black badge.png](../../assets/images/black badge.png>) See lockup themes for all variants.![compact badge.png](../../assets/images/compact badge.png>) See badge themes for all variants.

Badge HTML

Badge:

1<afterpay-placement
2 data-amount="55.95"
3 data-locale="en_AU"
4 data-logo-type="badge">
5</afterpay-placement>

Lockup:

1<afterpay-placement
2 data-amount="55.95"
3 data-locale="en_AU"
4 data-logo-type="lockup">
5</afterpay-placement>

Compact Badge:

1<afterpay-placement
2 data-amount="55.95"
3 data-locale="en_AU"
4 data-logo-type="compact-badge">
5</afterpay-placement>

lockup-theme

Accepted values are: mint, black, and white Mint lockup-mint.png

Black lockup-black.png

White lockup-white.png

mobile-view-layout

Changes the price table layout for mobile devices and on smaller screen sizes.

Accepted values: two-by-two, four-by-one

mobile-view-layout.png Above - two-by-two layout.

An attribute provided by Afterpay to display custom modal content.

1<afterpay-placement
2 data-modal-id="en_US-theme-white-lockup"
3 data-amount="400">
4</afterpay-placement>
ValueColumn Title
circled-info-icon
learn-more-textLearn More
more-info-textMore Info
circled-question-iconquestion-mark.png
noneNo icon or text displayed

HTML

1<afterpay-placement
2 data-locale="en_AU"
3 data-currency="AUD"
4 data-amount="120.00"
5 data-modal-link-style="circled-question-icon">
6</afterpay-placement>

Fully Customize “learn more link” using Slots

Provide a child element to AfterpayPlacement with the attribute/value pair slot="learn-more-link" to render a custom element which opens the Afterpay information modal when clicked.

For example:

1<afterpay-placement>
2 <img slot="learn-more-link" src="./custom-info-icon.png" >
3</afterpay-placement>

Configures the modal theme using one of two predefined colors: mint and white.

1<afterpay-placement
2 data-locale="en_AU"
3 data-currency="AUD"
4 data-amount="120.00"
5 data-modal-theme="white">
6</afterpay-placement>

White and Mint Modal Themes

white-modal.png

payment-amount-is-bold

Accepts a boolean, true , or false. True = payment amount is in bold.

You can also apply this attribute to the afterpay-price-table component:

afterpay-price-table.png

In the example above, the $50 prices are all in bold.

price-table-theme

Configures the modal theme using one of two predefined colors: mint (default), and white.

Mint Theme

price-table-theme-mint.png

Mint Theme HTML

1<afterpay-placement
2 data-type="price-table"
3 data-price-table-theme="mint"
4 data-amount="200">
5</afterpay-placement>

White Theme

price-table-theme-white.png

White Theme HTML

1<afterpay-placement
2 data-type="price-table"
3 data-price-table-theme="white"
4 data-amount="200">
5</afterpay-placement>

show-interest-free

Accepts a boolean, true , or false. If neither are provided, defaults to true

True example

*Or 4 interest-free payments of $10.25 with *

False example

*Or 4 payments of $10.25 with *

show-lower-limit

Determines whether to show the lower amount e.g) **1.001.00** – 1,000 for products outside of the provided minimum/maximum threshold. See setting a price range

Accepts a boolean, true , or false. If neither are provided, defaults to true

True example

available for orders between 11 - 2,000.

False example

available for orders over $1.

show-upper-limit

Accepts a boolean, true , or false. If neither are provided, defaults to true.

True example

available for orders between 11 - 2,000.

False example available for orders over $1.

show-with

Accepts a boolean, true , or false. If neither are provided, defaults to true

True example

or 4 interest-free payments of $75.00 with

False example

or 4 interest-free payments of $75.00

size

Accepted values: xs, sm, md, lg
The default size for an AfterpayPlacement is md (medium).

Placement SizeSize in Pixels
xs12px
sm14px
md16px
lg18px

thousands-separator

Accepts: ".", ","
Sets how the component should parse the provided amount.

By default, US, CA, AU, and NZ use a comma to parse the amount in thousands.

However, in Europe, the thousands separator is automatically configured to accept amounts formatted with a decimal in the thousands place.

type

Refer to constants for a list of possible values.

NameValueReference
PRICE_PARAGRAPH”price-paragraph”Afterpay.placementTypes.PRICE_PARAGRAPH
PRICE_TABLE”price-table”Afterpay.placementTypes.PRICE_TABLE

Price Table

1<afterpay-placement
2 data-type="price-table"
3 data-amount="400"
4<Info>
5</afterpay-placement
6</Info>
1const priceTable = new Afterpay.AfterpayPlacement()
2priceTable.type = Afterpay.placementTypes.PRICE_TABLE
3priceTable.amount = 400;
4document.body.appendChild(priceTable);

Price Paragraph

Note

If no the data-type attribute is not provided, the AfterpayPlacement will default to PRICE_PARAGRAPH

HTML
1<afterpay-placement
2 data-type="price-paragraph"
3 data-amount="400"
4<Info>
5</afterpay-placement
6</Info>
1const placement = new Afterpay.AfterpayPlacement()
2placement.type = Afterpay.placementTypes.PRICE_PARAGRAPH
3placement.amount = 400;
4document.body.appendChild(placement);

Constants

<CONSTANT_NAME>Values
currencyAUD, CAD ,GBP, NZD, USD
localeEN_AU, EN_CA, EN_GB, EN_NZ, EN_US, ES_ES, FR_FR, IT_IT, FR_CA
logoTypeBADGE, LOCKUP
modalLinkStyleCIRCLED_INFO_ICON, LEARN_MORE_TEXT, MORE_INFO_TEXT, CIRCLED_QUESTION_ICON,
NONE
placementTypesPRICE_TABLE, PRICE_PARAGRAPH
sizeXS, SM, MD, LG
mobileViewLayoutFOUR_BY_ONE, TWO_BY_TWO
theme.badgeBLACK_ON_MINT, BLACK_ON_WHITE, MINT_ON_BLACK, WHITE_ON_BLACK
theme.lockupBLACK, WHITE, MINT
theme.modalWHITE
theme.priceTableBLACK, WHITE
📘 Using Afterpay Constants

Constants are exposed to the window via the Afterpay object Afterpay.<constant_name>.

See some examples below

1console.log(Afterpay.locale.EN_US) // "en_US"
2console.log(Afterpay.theme.lockup) // "{"BLACK":"black","WHITE":"white","MINT":"mint"}"
3console.log(Afterpay.theme.lockup.BLACK) // "black"

Constants are available once the Afterpay.ready event has been dispatched.

Functions

NameDescription
createPlacementsAdd one or more placements to the page using the targetSelector attribute. More Info
launchModalDynamically open the Afterpay Modal
generatePaymentAmountGiven a price, returns the payment amount as a float

Window Events

NameDescription
readyCustom Window Event dispatched when Afterpay.js is successfully initialized.
modalRenderCompleteCustom Window Event dispatched when the <afterpay-modal> finishes rendering

Constructors

NameDescription
AfterpayPlacementCreates and returns a new AfterpayPlacement class reference.

Constructors must be instantiated with “new”.

const Placement = new Afterpay.AfterpayPlacement();

Full example:

1// setup event listener for the Afterpay.js initialization function.
2
3window.addEventListener("Afterpay.ready", function(){
4 const Placement = new Afterpay.AfterpayPlacement();
5 Placement.locale = "en_AU";
6 Placement.amount = 40.00;
7
8 const parentElement = document.getElementById("#product-price-wrapper")
9 parentElement.appendChild(Placement);
10
11});