# How Checkout+ SDK works

> STEP 1

Checkout+ SDK is an SDK for adding Checkout+ to your Shopify store's pages. It shows the Checkout+ banner on the cart page and, if the shopper checks the box, adds the Checkout+ product to the cart right before they proceed to checkout. This guide is for the developers who handle the integration, and explains the integration steps and the SDK specification.

Start by reviewing how it works on this page, then go to the page for the integration that matches how your Shopify store is built. For headless Shopify stores, see STEP 2 and STEP 3 (integration steps and reference). Terms are collected in the [Glossary](#glossary) on this page.

## The shared core and the integration-specific part

Checkout+ consists of a "shared core" that is the same for every Shopify store and an "integration-specific part" that changes with how the Shopify store is built.

![Diagram with Japanese labels. At the bottom is the shared core (fetching the benefit set and calculating the price, showing the banner, the choice of whether to add the Checkout+ product, and the check before proceeding to checkout). Above it are the integration-specific parts (for Shopify themes, for headless Shopify, and for other cart systems)](images/checkout-plus-sdk_layers.svg)

| Part | What it does | Varies by Shopify store |
| --- | --- | --- |
| Shared core | Fetches the benefit set (the commitment charge and benefits for each range) and calculates the price. Shows the banner. Receives the shopper's selection (whether to add the Checkout+ product). Before the shopper proceeds to checkout, adds the Checkout+ product as selected and verifies it | No |
| Integration-specific part | Reads and writes your Shopify store's cart. Inserts the banner into your Shopify store's pages. Connects the checkout button to the shared core | Yes, it changes with how the Shopify store is built |

The integration-specific part connects the shared core to your Shopify store's cart and pages in a way that matches how your Shopify store is built. In a headless Shopify store, the SDK user's code handles this connection. Reading and writing the cart goes through a [`CartConnector`](./shopify-headless-cart-connector.html) implemented by the SDK user. Available settings may differ by integration. For settings, see the page for each integration.

## Choosing an integration

The integration depends on how your Shopify store is built.

- If your Shopify store is built with a Shopify theme, use the app embed. Just enable it in the theme editor; you don't need to write any code ([Adding Checkout+ to the cart page](../checkout-plus/cart-embed.html)).
- If you build your own pages and handle the cart with the Storefront API (headless), follow [Shopify (headless): Integration steps](./shopify-headless.html).

If neither applies, talk to your Recustomer contact.

## Flow and responsibilities

In every integration, Checkout+ works in the following order. The only difference is who handles reading and writing the cart and connecting to the pages.

| Stage | What happens | Runs it in Shopify theme stores | Runs it in headless Shopify stores | What the SDK user's code does in headless stores |
| --- | --- | --- | --- | --- |
| 1. Load the benefit set | Load the benefit set configured by Recustomer | App embed | SDK | Passes the Checkout+ metafield through `CartConnector` |
| 2. Calculate the price | Determine the range from the cart amount (or the quantity, depending on the benefit set) and calculate the price | App embed | SDK | Lets the SDK read the cart through `CartConnector` |
| 3. Show it in the banner | Show the banner in the cart | App embed | SDK | Passes where to place the banner |
| 4. The shopper chooses | The shopper chooses whether to add the Checkout+ product (checks or unchecks the box in the banner) | App embed | SDK | — |
| 5. Check before proceeding to checkout | Add the Checkout+ product to the cart according to the shopper's selection and verify it | App embed | SDK | Calls the SDK from the checkout button. Lets the SDK write to the cart through `CartConnector` |
| 6. Recorded in the order | The order includes the Checkout+ product | Shopify checkout | Shopify checkout | — |

What the SDK does in each situation is in [1-1. SDK states and transitions](./shopify-headless-behavior.html).

Even in a headless Shopify store, the SDK does not receive a Storefront API token. All it receives about the cart is what your `CartConnector` returns (the cart's currency, its lines, and so on), which excludes the cart's secret part (everything from `?key=` in the cart ID). How to check that each step worked, and the notifications you receive on failure, are covered in [Shopify (headless): Integration steps](./shopify-headless.html#integration-flow).

## Checkout+ at checkout

Neither the SDK user's code nor the app embed or SDK can be inserted into Shopify checkout. That's why Checkout+ adds the Checkout+ product to the cart before the shopper proceeds to checkout (stage 5 in the table above). At checkout, it appears as a line like any other product and stays in the order as is. What happens when the shopper comes back from checkout with Back is in [1-1. SDK states and transitions](./shopify-headless-behavior.html#what-the-sdk-does-for-each-trigger).

Shopify Plus stores can also place the Checkout+ block (Checkout UI Extensions) in checkout. Its settings are in [Adding Checkout+ to the checkout page](../checkout-plus/checkout-block.html), and how it works inside checkout is in [How it works on the checkout page](../checkout-plus/checkout-block.html#how-it-works-on-the-checkout-page).

The SDK cannot offer Checkout+ to shoppers who go to checkout without the cart, such as with "Buy it now" on a product page. In Shopify Plus stores, the Checkout+ block can offer it to these shoppers as well. To find out whether the Checkout+ block can be used in a headless Shopify store, contact Recustomer.

## Glossary

### Terms shared by every integration

| Term | Meaning |
| --- | --- |
| Checkout+ product | A product that Recustomer creates in your Shopify store. The SDK adds it to the cart when the shopper checks the box. It has a variant for each range, and its handle starts with `rcmr-checkout-plus-`. Don't show it in the cart line list. In the Shopify admin and at checkout, it appears under the Checkout+ display name |
| Checkout+ display name | The name of the Checkout+ product shown in the Shopify admin and at checkout: 「あんしんプラス」 (Anshin Plus). The banner title (`displaySettings.title`) is set separately |
| Store | The unit in which Checkout+ is used in Recustomer. Each store has its own store ID and Checkout+ settings (such as the benefit set). The shop on Shopify itself is called a "Shopify store" |
| SDK user | The merchant, or its development company, that integrates the SDK. It builds the screens of a headless Shopify store and calls the SDK from code that runs on the screens (the SDK user's code). If it has a server, that server is called the SDK user's server. In chapters 2 to 4 (the integration steps, the reference, and the sample code), the SDK user's code is called your code. People who shop in the Shopify store are called shoppers |
| Store ID (`storeId`) | An ID (UUID) that Recustomer issues for each store; one value identifies one store. You pass it to [`init`](./shopify-headless-reference-init.html) |
| Benefit set | Your store's settings that bundle the Checkout+ commitment charge and benefits (such as free return shipping and coupon cashback) for each range. It reaches the SDK in the Checkout+ metafield, and the SDK calculates the price ([How the benefit set reaches the SDK](./shopify-headless-behavior.html#how-the-benefit-set-reaches-the-sdk)). A benefit set has one currency, currently Japanese yen only |
| Checkout+ metafield | The metafield on the Shopify store's `shop` that holds the benefit set and the exclusion tags. Recustomer writes its value |
| Range | A segment of the benefit set for each range of order amounts (cart amounts) or product quantities. Which one is used depends on the benefit set. Both the amount and the quantity are counted without excluded products. Each range sets the commitment charge and the Checkout+ product variant |
| Commitment charge, price, and merchant-borne amount | The commitment charge is the amount of the Checkout+ product before any discount, set for each range. The merchant-borne amount is the part of the commitment charge that the merchant bears as a discount. The rest, which the shopper pays, is the price of the Checkout+ product (hereafter, the price). The banner shows the price. Whether the commitment charge and the price include tax follows the tax settings of the Shopify store |
| Initial state (`initialSelection`) | The state of the banner checkbox when the page loads. The default is unchecked (`false`). Stores Recustomer has allowed can make it checked (`true`) ([`initialSelection`: Initial state of the checkbox](./shopify-headless-reference-init.html#initialselection-initial-state-of-the-checkbox)) |
| Excluded products (exclusion tags) | Products that Checkout+ does not cover. Products with any of the tags specified in the Checkout+ policy (exclusion tags) are excluded. The exclusion tags reach the SDK in the same Checkout+ metafield as the benefit set. If the cart contains excluded products, the banner shows a notice. For carts with only excluded products, the banner is not shown |
| Coupon cashback (estimated amount) | A benefit for orders with Checkout+: shoppers who don't return or exchange get a coupon some time after the order. The amount is either based on the purchase or a fixed amount. Which one is set in the Checkout+ policy. The banner shows an estimate, and Recustomer calculates the final amount after the order. The SDK's 「クーポンバック」 badge also refers to this benefit. It corresponds to "cashback credit" in the Checkout+ guide |

- Recustomer sets the commitment charges in the benefit set according to your contract. The benefits and exclusion tags are set in the Checkout+ policy in the Recustomer admin dashboard.

### Terms for headless Shopify stores

| Term | Meaning |
| --- | --- |
| Banner | The Checkout+ checkbox and price area shown on the cart page or in the cart drawer. It corresponds to the theme app embed's "card" in the Checkout+ guide |
| Details dialog | The screen that opens when the shopper presses 「詳しく見る」 (See details) on the banner. It corresponds to the theme app embed's "modal" in the Checkout+ guide |
| Checkout button | The button that takes the shopper from the cart page or cart drawer to checkout. Does not include buttons that go to checkout without the cart, such as "Buy it now" on a product page |
| Sample code | The code in this guide. It includes examples that connect to the SDK, examples that connect to your checkout, and the TypeScript type definitions (see the table on the [Sample code](./shopify-headless-sample-code.html#files) page) |
| `CheckoutPlusSession` | The object that `init()` returns. Keep exactly one running `CheckoutPlusSession` per page at all times |
| `CartConnector` | A pair of two functions (`getCart` and `updateCheckoutPlusLines`) that the SDK uses to fetch and update the cart. Implement them with the SDK user's cart logic and pass them to `cart` in `init` ([Step 2: Implement `CartConnector`](./shopify-headless-cart-connector.html)) |
| When the previous screen is shown as is | When the shopper comes back from checkout with Back and the browser shows the previous screen from its cache without reloading the page. How this differs from a page reload is in ⑩ and ⑫ of [What the SDK does for each trigger](./shopify-headless-behavior.html#what-the-sdk-does-for-each-trigger) |
