# Easy Checkout Widget

## **Overview**

This is the recommended method for integrating a payment method selection section into your checkout page form when exclusively using Optty payment methods. This approach ensures that all configuration on the UPP, including checkout widgets and customer fees, are fully utilised on your checkout page.

## Step 1 - Widget Setup & Initialisation

<details>

<summary>Overview of <a data-mention href="widget-setup-and-integration">widget-setup-and-integration</a></summary>

### **1.1 Initiate Widget**

```javascript
<script>
  (function (w, d, s, o, f, js, fjs) {
    w['JS-Widget'] = o;
    w[o] = w[o] || function () { (w[o].q = w[o].q || []).push(arguments) };
    js = d.createElement(s), fjs = d.getElementsByTagName(s)[0];
    js.id = o; js.src = f; js.async = 1; fjs.parentNode.insertBefore(js, fjs);
  }(window, document, 'script', 'mw', 'https://widgets.qa.optty.com/widget-loader.js'));
</script>
```

### **1.2 Load configuration**

```javascript
<script>
    // … widget initiation script …
    mw('init', {
        token: {{CUSTOMER_WIDGET_TOKEN}},
        currency: "string",
        initialAmount: number
        mode: “live”
    });
</script>
```

### **1.3 Setup Optty Easy Checkout Widget**

```javascript
<script>
    mw('optty-easy-checkout-widget', {
        initialAmount: number,
    })
</script>
```

</details>

## **Step 2 -** Add Payment Provider Selection

Add this div where you want the payment provider options to appear, it will show an accordion of the available payment options for the relevant currency.

```html
<div class="optty-easy-checkout-widget"></div>
```

When a payment method is selected, there is a drop down with call to action information about the provider, in the example you can see the AfterPay default content. Explain how the buy now pay later works to the customer before they proceed to checkout.

<figure><img src="https://content.gitbook.com/content/fCUCEi1845pQGMcbjae6/blobs/iQpM09iMRStGfriPcYJA/image.png" alt="" width="375"><figcaption></figcaption></figure>

When a customer selects a payment method there is a`bnplSelected` message sent, this will contain which provider the customer has selected and you must pass it through to either of the following methods to handle creating an order, [create-order-widget](https://docs.optty.com/widget/create-order-widget "mention"), [api-driven-create-order-widget](https://docs.optty.com/widget/api-driven-create-order-widget "mention") or [direct-api-orders](https://docs.optty.com/direct-api-orders "mention")

## Step 3 - Call to Action (CTA) Configuration

The area highlighted in red can be configured from the UPP under the "Checkout Widget" tab when managing a payment method.

<figure><img src="https://3947039319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfCUCEi1845pQGMcbjae6%2Fuploads%2FI5J6gBH68WoFHvf1ZJ3Q%2FScreenshot%202025-07-25%20at%2010.50.01%20am.png?alt=media&#x26;token=244588c2-8456-41e3-91f9-6df6660bef4b" alt="" width="563"><figcaption></figcaption></figure>

You can customize this CTA using the configuration below. Entering an IFrame URL enables the use of the `%iframe` tag in the Text and Layout section to display an iframe as your CTA.

<figure><img src="https://3947039319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfCUCEi1845pQGMcbjae6%2Fuploads%2FyiTNEG3PCftK7KBDAkyx%2Fimage.png?alt=media&#x26;token=3ad13947-5267-48e3-ad84-5ecfdef34dfc" alt="" width="563"><figcaption></figcaption></figure>

## Step 4 - Handling Surcharges (Optional)

Surcharge functionality can be enabled from the UPP, for details on how this surcharge amount is calculate and configured read more here [surcharge-feature](https://docs.optty.com/surcharge-feature "mention"). This surcharge is automatically applied to all orders created through any means.

A consumer must be made aware of the surcharge amount and consent to paying it. The `easy-checkout-widget` handles this.

<figure><img src="https://content.gitbook.com/content/fCUCEi1845pQGMcbjae6/blobs/8S1I8csKDs1YvSFLnCG2/image.png" alt=""><figcaption><p>Surcharge Display on easy-checkout-widget</p></figcaption></figure>

To ensure that the customer has consented to this surcharge before placing the order, you should add `place_order` id onto the button that initiates the payment by the customer. This will set the disabled flag on the button if the customer has selected a payment provider with a surcharge and has not checked the consent tick box or does not have any payment provider selected.

<details>

<summary>Sample React Example of Handling Message</summary>

```javascript
// Some code
useEffect(() => {
    const handleBnplSelected = (event: MessageEvent) => {
    if (event.data.type === "bnplSelected") {
        const newBnplProvider = event.data.bnplName;
        setSelectedBnpl(newBnplProvider);
    }
};
```

</details>
