Docs
STEP 3-1

init: Initialize the SDK

window.rcmr.checkoutPlus.init(options: CheckoutPlusInitOptions): CheckoutPlusSession

window.rcmr.checkoutPlus.init(options) initializes the SDK and returns a CheckoutPlusSession. It makes no network requests at initialization. On the first call to mount(), refresh(), or prepareCheckout(), the SDK fetches the cart and the Checkout+ metafield through CartConnector's getCart.

Exceptions and failures

  • Exceptions: None.
  • If storeId or cart is invalid: This is when storeId is missing or an empty string, or when cart is missing or its getCart or updateCheckoutPlusLines is not a function. It returns a CheckoutPlusSession in the same state as after destroy(), and notifies onError with invalid-options after returning. The banner is not shown, and prepareCheckout() completes immediately with { attached: false }.
  • Network failures: init() makes no network requests, so none happen here. They happen in the first mount(), refresh(), or prepareCheckout().

Options you can pass

OptionRequiredIf omittedDescription
storeIdRequired—The store ID (Development Shopify store and store ID)
cartRequired—The CartConnector the SDK user implemented (getCart and updateCheckoutPlusLines). One CheckoutPlusSession uses only the one CartConnector passed here
onCheckoutPlusLinesChangeRequired if you show cart lines or a cart totalNot calledA function called after the SDK adds or removes the Checkout+ product. Takes no arguments. Fetch the cart again in it
localeOptionalThe value of <html lang>The amount format. Only ja-JP is supported for now; if you set another value, amounts are shown in the ja-JP format. The default text does not change
displaySettingsOptionalRecustomer's default contentThe banner text and the details dialog content (displaySettings below)
initialSelectionOptionalfalseThe initial state of the checkbox. Set it to true to show the box checked (initialSelection below)
onErrorOptionalNot calledA function that receives why Checkout+ is unavailable, and failures
// Example of init()
// Before the SDK finishes loading, window.rcmr.checkoutPlus doesn't exist and nothing is initialized
// Run this after the SDK finishes loading (the recustomer-checkout-plus:ready event) (Step 1)
const checkoutPlus = window.rcmr?.checkoutPlus?.init({
  storeId: '(store ID)',                                                  // Required: the ID for each store
  cart: cartConnector,                                                       // Required: CartConnector you implemented
  onCheckoutPlusLinesChange: () => { /* Fetch your cart again */ }, // Required if you show cart lines or a cart total
  locale: 'ja-JP',                                                           // Optional: amount format
  displaySettings: { /* Banner text, etc. */ },                              // Optional: display settings
  initialSelection: false,                                                   // Optional: initial state of the checkbox
  onError: (error) => reportError(error),                                    // Optional: send to your existing monitoring system
})

displaySettings: Text and details dialog

Specifies the text and images of the banner and the details dialog. Every field is optional. Omitted fields show Recustomer's default content. The default text and the default accessible names are in Japanese regardless of locale. To show another language, specify the text in that language. Change the look (colors, corner radius, font) with CSS (Change the look with CSS).

FieldTypeDefaultDescription
titlestring「あんしんプラス」 (Anshin Plus)The banner title. Displayed as a string, and HTML is not supported
descriptionstringNone (no description is shown)The banner description. Displayed as a string. It can include the estimated coupon cashback amount (see the placeholder below)
detailsButtonLabelstring「詳しく見る」 (See details)Text of the button that opens the details dialog
shippingBadgeLabelstring「返品送料無料」 (Free return shipping)Text of the 「返品送料無料」 badge. Displayed as a string, and HTML is not supported
cashbackBadgeLabelstring「クーポンバック」 (Coupon cashback)Text of the 「クーポンバック」 badge. Displayed as a string, and HTML is not supported
exclusionNoticestring「※{excludedItem}は対象外商品です。」 (※{excludedItem} is not eligible.)The excluded-item notice. {excludedItem} is replaced with the list of excluded product names
excludedItemFormatstring「{name}」 (the name in Japanese corner brackets)How one product name is written in the excluded-item notice. {name} is replaced with the product name
excludedItemSeparatorstringNone (names are written one after another)The string placed between excluded product names (e.g. , )
detailsModal.heroImageUrlstringNone (no image is shown)URL of the image shown at the top of the details dialog. The details dialog is 480px wide, so a 960px-wide image is recommended for high-resolution screens
detailsModal.logoImageUrlstringNone (no logo is shown)URL of the logo in the details dialog
detailsModal.logoImageAltstringストアロゴ (Store logo)Alternative text of the logo image (for screen readers)
detailsModal.htmlstringRecustomer's default textHTML for the body of the details dialog. Scripts, event attributes, and the like are removed before it is displayed. If it is an empty string, nothing is shown
detailsModal.ariaLabelstring{title}の詳細 ({title} details)Accessible name of the details dialog. {title} is replaced with the value of title
detailsModal.closeButtonAriaLabelstring閉じる (Close)Accessible name of the close button
detailsModal.poweredByLinkAriaLabelstringRecustomer(別タブで開く) (Recustomer, opens in a new tab)Accessible name of the "Powered by Recustomer" link
  • Except for detailsModal.html, every text field is displayed as a string, and HTML is not supported. For these fields, an empty string is treated the same as an omitted field.
  • When the excluded products are A and B, the default shows 「※「A」「B」は対象外商品です。」 (※"A" "B" are not eligible.).
  • For badges, you can change only the text. Whether each badge appears depends on the range's benefits (Parts of the banner in mount).

{cashback} in description is replaced with the estimated coupon cashback amount. The estimate is calculated according to the Shopify store's tax setting (prices including or excluding tax).

For ranges with no estimated amount, the {cashback} part becomes empty. Write text that still reads naturally when it is empty. Recustomer calculates the final amount after the order.

In ranges where the coupon cashback is a fixed amount, {cashback} becomes that amount.

// Add to the options of init(). This is an example for a Japanese store
displaySettings: {
  title: 'あんしんプラス',
  description: 'ご購入後の返品・交換の送料が無料になります。さらに {cashback} 分のクーポンをお返しします。',
  detailsButtonLabel: '詳しく見る',
  shippingBadgeLabel: '返品送料無料',
  cashbackBadgeLabel: 'クーポンバック',
  exclusionNotice: '※{excludedItem}は対象外商品です。',
  excludedItemFormat: '「{name}」',
  excludedItemSeparator: '',
  detailsModal: {
    heroImageUrl: 'https://cdn.example.com/checkout-plus/hero.png',
    logoImageUrl: 'https://cdn.example.com/logo.png',
    logoImageAlt: 'ストアのロゴ',
    html: '<h2>安心して、もっと自由にショッピングを。</h2><p>…</p>',
    ariaLabel: '{title}の詳細',
    closeButtonAriaLabel: '閉じる',
    poweredByLinkAriaLabel: 'Recustomer(別のタブで開きます)',
  },
},

displaySettings uses the values passed when init() is called. If you load them from a CMS or similar, call init() after loading finishes. To change them, call destroy() and then call init() again.

initialSelection: Initial state of the checkbox

Shows the banner checkbox in the specified initial state.

initialSelectionInitial state
false (default)Shown unchecked
trueShown checked. Only takes effect for stores Recustomer has allowed. For stores that are not allowed, it is shown unchecked

For stores that set initialSelection to true, the SDK behaves as follows.

  • It adds the Checkout+ product by default only after the banner has been rendered. It does not add it if the shopper proceeds to checkout from a screen that does not show the banner, or before the banner is rendered. If the range changes after the banner is rendered and the new price has not been rendered yet, it still adds the product for the range at the moment the checkout button is pressed.
  • If the shopper unchecks the box, the SDK remembers this until the tab is closed and does not check it again. It does not remember that the shopper checked the box.
  • When the cart changes and the price changes, the selection follows Selection when the displayed price changes.
  • When the shopper comes back from checkout, the checkbox returns to its initial state, both when the previous screen is shown as is and when the page reloads. If the SDK has recorded that the shopper unchecked it, it stays unchecked.

Selection when the displayed price changes

When the displayed price changes (for example, because the cart changed and the range changed), the state of the checkbox does not change. If the shopper had checked the box, it stays checked. If the shopper had unchecked it, it stays unchecked.

If the checkout button is pressed before the new price is shown in the banner (for example, after the cart was changed in another tab), the SDK adds or removes the Checkout+ product as currently selected, for the range at the moment the button is pressed (prepareCheckout behavior).

One running CheckoutPlusSession per page

When you recreate it, first call destroy() on the current CheckoutPlusSession. If you call init() without doing so, both run at the same time and the following happens.

What both CheckoutPlusSession objects haveWhat happens
Monitoring whether the previous screen is shown as isWhen the previous screen is shown as is, both fetch the cart and try to remove the Checkout+ product, duplicating cart updates
CallbacksThe same callback is called twice. Functions of components that were already discarded may also be called
Updates in progressResults of the old CheckoutPlusSession's updates get mixed into the new screen's processing
Shopper's selection (whether to add the Checkout+ product)The two CheckoutPlusSession objects hold separate selections, and it becomes unclear which one is correct

For when to call destroy(), see Deciding whether to call destroy().

© Recustomer, Inc.