> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orderprotection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stay AI

> All your subscription orders can now offer guaranteed delivery

<Note>
  The Order Protection widget integrates with Stay AI and your Shopify store,
  enhancing the subscription order experience for users with all relevant
  information in one place.

  The widget addition to the cart simplifies the claim-filing process for users reducing friction and eliminating the need for manual navigation to the Order Protection website.
</Note>

## Installation

<Steps>
  <Step title="Generate an API Token">
    Access the Stay AI Account page: [Stay AI
    Admin](https://app.retextion.com/account/api-keys)

    * Go to `Accounts` in the Sidebar.
    * Click `API Tokens` tab at the top button.
    * Click `"New API Key"` button in the top right.
    * Choose a `Name`, `Description`, and `Email`
      * Name: Order Protection
      * Description: Order Protection Subscriptions Integration
      * Email: [onboarding@orderprotection.com](mailto:onboarding@orderprotection.com)
    * Choose permissions: Leave scopes set to `All`.
    * Click `"OK"` button.

    <Frame caption="Creating an API Token">
      <img src="https://mintcdn.com/orderprotectioncom/GDuchlp6KbhScehe/public/assets/img/stay-ai/creating-api-toke-stay-ai.png?fit=max&auto=format&n=GDuchlp6KbhScehe&q=85&s=6691d4c9fbcb9f6e91ef33dd2e51824d" alt="API Token" width="1411" height="906" data-path="public/assets/img/stay-ai/creating-api-toke-stay-ai.png" />
    </Frame>
  </Step>

  <Step title="Install Scripts in Customer Portal Designer">
    To install the Stay AI Integration on Stay AI, follow these steps:

    * In the left navigation, go to `Customer Portal` and select `Design`
          <img src="https://mintcdn.com/orderprotectioncom/GDuchlp6KbhScehe/public/assets/img/stay-ai/customer-portal-stay-ai.png?fit=max&auto=format&n=GDuchlp6KbhScehe&q=85&s=89b3fbd4d143e9db2d5d1b18d56d5ea4" alt="stay ai customer portal" width="1419" height="908" data-path="public/assets/img/stay-ai/customer-portal-stay-ai.png" />
    * Within the `HTML block`, add the following code:

    ```html theme={null}
    <link rel="stylesheet" href="https://cdn.orderprotection.com/widget/subscriptions/5.28.11/style.css">

    <script src="https://cdn.orderprotection.com/widget/core/latest/orderprotection.js"></script>

    <div id="order-protection"></div>
    ```

    * Within the JavaScript block, add the following function script:

    ```javascript theme={null}
    (function () {
      const script = document.createElement("script");
      script.src = "https://cdn.orderprotection.com/widget/subscriptions/5.28.11/orderprotection.js";
      script.onload = function () {
        console.log("ready to go");
        const stayWidget = OrderProtection.createOrderProtectionWidget({
          integration: "stay-ai",
        });
        stayWidget.cart.debug = false;
        stayWidget.widget.on('toggled', () => {
          const totalWOp = window.orderProtection.cart.subtotal + window.orderProtection.price;
          const totalNoOp = window.orderProtection.cart.subtotal;
          const formatter = new Intl.NumberFormat(undefined, {
            style: 'currency',
            currency: window.Shopify.currency.active
          });
          const formattedSubtotalOP = formatter.format(totalWOp / 100);
          const formattedSubtotalNoOp = formatter.format(totalNoOp / 100);
          const subtotalElm = document.querySelector('.txt-order-total-value');
          if (!subtotalElm) return;
          subtotalElm.innerText = window.orderProtection.enabled ? formattedSubtotalOP : formattedSubtotalNoOp;
        });
        const interval = setInterval(() => {
          if (!stayWidget.cart.isReady()) {
            return;
          }
          clearInterval(interval);
          stayWidget.cart.setup();
          stayWidget.cart.subscription = {};
          stayWidget.init();
        }, 500);
        setInterval(() => {
          stayWidget.attach();
        }, 1000);
      };
      document.body.appendChild(script);
    })
    ```

    * Click `Submit`.
  </Step>

  <Step title="Integrate Stay AI within the Order Protection Platform">
    Within the Order Protection app, do the following:

    * Navigate to `Integrations` in the left navigation.
    * Find the Stay AI block under the `Available` tab.
    * Take the API token you created in Step 1 and add it to the API Token field and save.
    * Once saved, click on the `Active` tab and the API token field within the Stay AI block will have a hidden value. This means that your token successfully uploaded.

          <img src="https://mintcdn.com/orderprotectioncom/GDuchlp6KbhScehe/public/assets/img/stay-ai/stay-ai-integration-op-settings.png?fit=max&auto=format&n=GDuchlp6KbhScehe&q=85&s=4261fd803dcbe02000b5ec354e0a52d1" alt="stay ai api token in op app" width="1450" height="911" data-path="public/assets/img/stay-ai/stay-ai-integration-op-settings.png" />
  </Step>

  <Step title="Checking the Widget UX on the Customer Subscription Portal">
    * Navigate to `Subscription Data` in the left navigation and click `Subscriptions`.
    * Click the `Get Customer Portal Link` and open it in a new tab.
    * Scroll down to the `Subscription Details` section and check that the Order Protection widget is showing as expected.
      * *This may be slighlty different depending on your specific Customer Portal design.*

            <img src="https://mintcdn.com/orderprotectioncom/GDuchlp6KbhScehe/public/assets/img/stay-ai/customer-portal-widget-check-stay-ai.png?fit=max&auto=format&n=GDuchlp6KbhScehe&q=85&s=8ce993b3dad7567c24f3117040943459" alt="stay ai widget preview" width="1403" height="796" data-path="public/assets/img/stay-ai/customer-portal-widget-check-stay-ai.png" />
  </Step>
</Steps>

<Check>
  Once set up, Order Protection will be added to all cart instances within
  Shopify subscription orders using Stay AI. Customers can choose to opt-in or
  opt out of Order Protection for their subscription orders.
</Check>

<Note>
  Customers will be able to file/edit claims per your normal store settings once
  an order confirmation email has been sent.
</Note>

<Tip>
  **Did you know?** You can customize the Order Protection widget styling specifically for your subscription portal. When creating a new widget, select **Subscription** as the widget type to create a dedicated subscription widget.

  <img src="https://mintcdn.com/orderprotectioncom/6PHukXPBD9AnZd7s/public/assets/img/education-basecamp/widgets/widget-subscription-type-selector.png?fit=max&auto=format&n=6PHukXPBD9AnZd7s&q=85&s=2d2cf94caf2c4df7a0850230b0cd8ac9" alt="Widget type selector with Subscription option highlighted" width="3562" height="2232" data-path="public/assets/img/education-basecamp/widgets/widget-subscription-type-selector.png" />

  <img src="https://mintcdn.com/orderprotectioncom/6PHukXPBD9AnZd7s/public/assets/img/education-basecamp/widgets/widget-subscription-list.png?fit=max&auto=format&n=6PHukXPBD9AnZd7s&q=85&s=05fe38e82bc6c46e6c0a331df1a64605" alt="Widgets list showing a Subscription widget type" width="3584" height="2226" data-path="public/assets/img/education-basecamp/widgets/widget-subscription-list.png" />

  For full customization options, visit the [Widget Customization](https://docs.orderprotection.com/education-basecamp/customizations/widgets) page.
</Tip>
