# Shopify (headless): SDK reference

> STEP 3

This page lists the Checkout+ SDK methods and the functions the SDK calls. Details for each are on the following pages.

- [SDK methods](./shopify-headless-reference-methods.html): called from your code
- [Functions the SDK calls](./shopify-headless-reference-functions.html): implemented by the SDK user and passed to `init()` (`CartConnector` and callbacks)

## Methods and callbacks

| Name | When to use | Role | When it is called |
| --- | --- | --- | --- |
| [`init(options)`](./shopify-headless-reference-init.html) | All stores | Initializes the SDK and returns a `CheckoutPlusSession`. Makes no network requests | Once, after the SDK loads |
| [`mount(target)`](./shopify-headless-reference-mount.html) | All stores | Shows the banner in the given element | When the element for the banner is ready |
| [`refresh()`](./shopify-headless-reference-refresh.html) | All stores | Fetches the cart again and updates the price and the banner | Once right after initialization, and when your code changes the cart |
| [`prepareCheckout()`](./shopify-headless-reference-prepare-checkout.html) | All stores | Adds or removes the Checkout+ product based on the shopper's selection (whether to add the Checkout+ product), then verifies the cart | When the checkout button is pressed |
| [`getCart()`](./shopify-headless-reference-get-cart.html) | All stores | A `CartConnector` function. Returns the latest cart | Called by the SDK |
| [`updateCheckoutPlusLines(change)`](./shopify-headless-reference-update-checkout-plus-lines.html) | All stores | A `CartConnector` function. Adds and removes the Checkout+ product | Called by the SDK |
| [`onCheckoutPlusLinesChange`](./shopify-headless-reference-on-checkout-plus-lines-change.html) | When you show cart lines or a cart total | Notifies you when the SDK adds or removes the Checkout+ product | Called by the SDK |
| [`onError`](./shopify-headless-reference-on-error.html) | All stores (recommended) | Reports why Checkout+ is unavailable, and failures | Called by the SDK |
| [`isCheckoutPlusLine(line)`](./shopify-headless-reference-is-checkout-plus-line.html) | When you render the cart lines | Tells whether a cart line is the Checkout+ product line | Before rendering, once for each cart line |
| [`unmount()`](./shopify-headless-reference-unmount.html) | As needed | Removes one banner shown with `mount` | When you discard the element that shows the banner |
| [`destroy()`](./shopify-headless-reference-destroy.html) | As needed | Removes all banners and shuts down the SDK | When you discard the component that initialized the SDK. When you recreate the SDK with different values passed to `init()`, before calling the new `init()` |

An example written in React is in [4. Sample code](./shopify-headless-sample-code.html). With other frameworks, you call the same methods.

## Exceptions and failures

No failure in the SDK blocks checkout. Your code needs almost nothing to handle failures. As the side that receives failures, all your code does is send what arrives in `onError` to its monitoring system.

### SDK methods do not throw

SDK methods do not throw, and the Promises they return never reject. What happens when the cart or the benefit set (the commitment charge and benefits for each range) cannot be fetched is in [What the SDK does for each trigger](./shopify-headless-behavior.html#what-the-sdk-does-for-each-trigger).

The behavior of each method is in "Exceptions and failures" on its page: [`init(options)`](./shopify-headless-reference-init.html#exceptions-and-failures), [`mount(target)`](./shopify-headless-reference-mount.html#exceptions-and-failures), [`refresh()`](./shopify-headless-reference-refresh.html#exceptions-and-failures), [`prepareCheckout()`](./shopify-headless-reference-prepare-checkout.html#exceptions-and-failures), [`isCheckoutPlusLine(line)`](./shopify-headless-reference-is-checkout-plus-line.html#exceptions-and-failures), [`unmount()`](./shopify-headless-reference-unmount.html#exceptions-and-failures), [`destroy()`](./shopify-headless-reference-destroy.html#exceptions-and-failures)

### When an unexpected failure occurs inside the SDK

What happens when an unexpected failure occurs inside the UI components (the banner or the details dialog) is in the `ui-failure` row of the table in [What the SDK does for each trigger](./shopify-headless-behavior.html#what-the-sdk-does-for-each-trigger).

### When your functions throw

Make `CartConnector` (`getCart` and `updateCheckoutPlusLines`) throw when it fails. Even if a callback throws, the SDK keeps running. The SDK does not wait for Promises returned by callbacks. The SDK never calls a callback synchronously inside the method you called. It calls callbacks after the method returns its return value (a Promise, for methods that return one). It may call them before that Promise settles. This means you can use the `CheckoutPlusSession` returned by `init()` inside a callback.

How the SDK handles each function is in "When it throws" on that function's page: [`getCart`](./shopify-headless-reference-get-cart.html#when-it-throws), [`updateCheckoutPlusLines`](./shopify-headless-reference-update-checkout-plus-lines.html#when-it-throws), [`onCheckoutPlusLinesChange`](./shopify-headless-reference-on-checkout-plus-lines-change.html#when-it-throws), [`onError`](./shopify-headless-reference-on-error.html#when-it-throws)

### What the SDK takes care of

The SDK handles the following, so you do not need to write code for them.

- Discards stale cart responses. When cart fetches overlap, it uses only the result of the fetch that started last
- Merges Checkout+ product lines into one at the checkout button (`prepareCheckout()`) when there are two or more
- Determines the range again from the cart right before checkout, and adds or removes the Checkout+ product as selected ([`prepareCheckout` specification](./shopify-headless-reference-prepare-checkout.html#specification))
- Removes a Checkout+ product left in the cart when the shopper comes back from checkout (⑩ and ⑫ in [What the SDK does for each trigger](./shopify-headless-behavior.html#what-the-sdk-does-for-each-trigger))
