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).
| Step | What to do | How to check it worked | kind delivered to onError on failure |
|---|---|---|---|
| 1 | Load the SDK | In the browser console, window.rcmr?.checkoutPlus is defined | — |
| 2 | Implement CartConnector | Calling getCart() of the CartConnector you implemented, from your development code, returns every line in the cart | invalid-cart, unavailable |
| 3 | Initialize the SDK | init() returns a CheckoutPlusSession, and invalid-options is not delivered to onError | invalid-options |
| 4 | Show the banner | When you open the cart, the banner appears, and in the Network tab, metafield in the cart response isn't null | not-published, invalid-benefit-set, acceptance-suspended, currency-not-offered, ui-failure |
| 5 | Replace the checkout button | When you check the box and proceed to checkout, checkout contains one Checkout+ product line | add-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.checkoutPlusdoesn't exist, so you can't callinit(), andonErroris not called either. invalid-cartin step 2 arrives when the SDK fetches the cart and the value returned byCartConnectorhas the wrong shape. This isn't limited to the first fetch.unavailablein step 2 arrives whengetCartthrows an exception.ui-failurein step 4 arrives when an unexpected failure occurs inside the banner or the details dialog.add-failedin step 5 arrives when adding the Checkout+ product is rejected.remove-failedarrives when removing the Checkout+ product is rejected and the SDK could not confirm that it was removed.callback-failurearrives 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
| Task | Who | Details |
|---|---|---|
| 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 Recustomer | Checkout+ policy |
| Activate Checkout+ | Your store's staff | Getting started |
| Publish the Checkout+ product to your sales channel (such as the Headless channel) | Recustomer | — |
| Make the Checkout+ metafield readable through the Storefront API | Recustomer | — |
- 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
| Item | Details |
|---|---|
| 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 currency | Carts in the same currency as the benefit set only (benefit sets are currently in Japanese yen only) |
| Storefront API permissions | Query 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 channel | The Checkout+ product is published to your sales channel (such as the Headless channel). Recustomer handles publishing |
| Storefront API version | A 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.jsScript, passnonce). 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
CartConnectorimplementation 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,getCartfails andunavailableis delivered toonError. 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 yourCartConnectorimplementation with an access token that has these permissions (unauthenticated_read_product_tagsandunauthenticated_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-Versionheader of the Storefront API response (Shopify API versioning). In supported versions, the Checkout+ product does not appear in product lists or search results.