Docs
STEP 2

Shopify (headless): Integration steps

These are the steps for integrating Checkout+ SDK into a headless Shopify store. You implement a CartConnector using your existing cart logic and pass it to the SDK. CartConnector runs in the browser.

Who this page is for

This page is for Shopify stores that meet both of the following.

  • A headless Shopify store that handles the cart with the Storefront API (for example, one built with Next.js or Hydrogen)
  • Purchases go through Shopify checkout

If you use a cart or checkout other than Shopify's, talk to your Recustomer contact.

Integration flow

The integration has the following five steps. For each step, the table lists how to check that it worked and the kind delivered to onError on failure (for what each kind means, see onError).

StepWhat to doHow to check it workedkind delivered to onError on failure
1Load the SDKIn the browser console, window.rcmr?.checkoutPlus is defined—
2Implement CartConnectorCalling getCart() of the CartConnector you implemented, from your development code, returns every line in the cartinvalid-cart, unavailable
3Initialize the SDKinit() returns a CheckoutPlusSession, and invalid-options is not delivered to onErrorinvalid-options
4Show the bannerWhen you open the cart, the banner appears, and in the Network tab, metafield in the cart response isn't nullnot-published, invalid-benefit-set, acceptance-suspended, currency-not-offered, ui-failure
5Replace the checkout buttonWhen you check the box and proceed to checkout, checkout contains one Checkout+ product lineadd-failed, remove-failed

init() makes no network requests. The only case where init() notifies onError is when the storeId or cart you pass is invalid (invalid-options). Failures for the benefit set (the commitment charge and benefits for each range) or the cart are delivered when the SDK starts fetching (on the first call to mount(), refresh(), or prepareCheckout()). In the step 3 example, fetching starts with the refresh() right after initialization.

  • If the SDK can't be loaded in step 1, window.rcmr.checkoutPlus doesn't exist, so you can't call init(), and onError is not called either.
  • invalid-cart in step 2 arrives when the SDK fetches the cart and the value returned by CartConnector has the wrong shape. This isn't limited to the first fetch.
  • unavailable in step 2 arrives when getCart throws an exception.
  • ui-failure in step 4 arrives when an unexpected failure occurs inside the banner or the details dialog.
  • add-failed in step 5 arrives when adding the Checkout+ product is rejected. remove-failed arrives when removing the Checkout+ product is rejected and the SDK could not confirm that it was removed.
  • callback-failure arrives in any step when one of your callbacks (onCheckoutPlusLinesChange, etc.) throws an exception.

After Steps 1–5, complete the tasks in Shopify store settings and before going live.

The code for each step is an example of how to integrate. What the SDK needs is the method calls described in each step and in the Reference; you don't need to write the code or split the files the same way as the examples. The examples are written in React (19 or later). With other frameworks, you call the same methods and follow the same rules. In the code, cartConnector, reloadCart(), reportError(), and useCart() are placeholder names for your logic. Also replace getCheckoutUrl() in step 5 (Step 5: Replace the checkout button) with your own logic. The full text of the examples is in 4. Sample code.

Preparation

Before you start

TaskWhoDetails
Set up returns and exchanges, and the send back method (Sagawa Express pickup, receiver-pay)Your store's staff"Prerequisites" in What is Checkout+?
Set up the Checkout+ policy (benefits and the conditions for excluded products)Your store's staff and RecustomerCheckout+ policy
Activate Checkout+Your store's staffGetting started
Publish the Checkout+ product to your sales channel (such as the Headless channel)Recustomer—
Make the Checkout+ metafield readable through the Storefront APIRecustomer—
  • Charges begin on activation. If you don't want test orders to be charged, ask support to enable test mode before activation.

Development Shopify store and store ID

Use a development Shopify store to check your integration. Install the Recustomer app on the development Shopify store and set up the Checkout+ benefit set. Recustomer sets the commitment charges according to your contract, and the benefits and exclusion tags are set in the Checkout+ policy in the Recustomer admin dashboard.

The store ID is an ID that Recustomer issues for each store (a UUID, in the form 0193f0c2-7a4e-7c1d-9b2a-5e8f3d6c1a90), and one value identifies one store. It is shown in the Recustomer admin dashboard. You pass it as storeId to init. It isn't a secret, so you can put it in browser code. The development Shopify store and the production Shopify store are separate stores in Recustomer, so their store IDs differ too. Pass it from per-environment configuration (such as environment variables), depending on which store the build targets (Step 3: Initialize the SDK).

Recustomer writes the benefit set to the Checkout+ metafield (Glossary). The SDK user fetches it together with the cart from the Storefront API in CartConnector's getCart, and passes it to the SDK (Step 2: Implement CartConnector). Recustomer will tell you the metafield namespace and key.

Your Recustomer contact will tell you how to prepare the development Shopify store.

Before you start the integration, open the SDK URL (https://script.rcmr.io/checkout-plus/sdk/shopify-headless/v1/checkout-plus.js) in a browser and confirm that its contents are displayed. You check the benefit set in metafield of the cart response in the Network tab of the developer tools after showing the banner in Step 4.

Requirements

ItemDetails
Content Security Policy (CSP)https://script.rcmr.io in script-src. If you show your store's images in the details dialog, the image origin in img-src
Supported currencyCarts in the same currency as the benefit set only (benefit sets are currently in Japanese yen only)
Storefront API permissionsQuery with an access token that has the permission to read product tags (unauthenticated_read_product_tags) and the permission to read products (unauthenticated_read_product_listings, used to fetch the Checkout+ metafield)
Sales channelThe Checkout+ product is published to your sales channel (such as the Headless channel). Recustomer handles publishing
Storefront API versionA version Shopify currently supports
  • CSP: Needed only if you set a CSP. With a CSP that uses 'strict-dynamic', scripts without a nonce aren't loaded, so add a nonce attribute to the SDK script tag (with Next.js Script, pass nonce). For how to configure CSP, see MDN's documentation.
  • Supported currency: When the cart currency differs from the currency of the benefit set (currently, carts not in Japanese yen), the banner isn't shown. Shoppers can still purchase without Checkout+.
  • Storefront API permissions: Besides fetching and updating the cart, your CartConnector implementation reads the handles and tags of products in the cart through the Storefront API. The cart and product permissions (unauthenticated_read_checkouts, unauthenticated_write_checkouts, unauthenticated_read_product_listings) are usually already granted for Shopify stores that implement a cart. The permission to read product tags (unauthenticated_read_product_tags) may not be granted, so check it. Without it, getCart fails and unavailable is delivered to onError. If your store uses the Headless channel, check the Storefront API access scopes in the Headless channel in the Shopify admin. In Shopify, the cart can be read and written without an access token, but product tags require one (Storefront API authentication). Fetching the Checkout+ metafield also requires an access token and the product permission (unauthenticated_read_product_listings) (Shopify's Shop). If you handle the cart without an access token, make the Storefront API calls in your CartConnector implementation with an access token that has these permissions (unauthenticated_read_product_tags and unauthenticated_read_product_listings).
  • Storefront API version: Requests to a version that is no longer supported are processed with the oldest supported version. You can check the version actually used in the X-Shopify-API-Version header of the Storefront API response (Shopify API versioning). In supported versions, the Checkout+ product does not appear in product lists or search results.
© Recustomer, Inc.