> For the complete documentation index, see [llms.txt](https://docs.zotlo.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zotlo.com/integrating-zotlo/web-sdk/checkout-sdk.md).

# Checkout SDK

The Zotlo Web Checkout SDK allows you to display a seamless checkout form inside your web application. Your users can complete their purchase without leaving your site, while Zotlo securely handles payment processing, subscription creation, and 3D Secure (3DS) authentication.

## **Quick Start**

### **1. Install the SDK**

{% code title="NPM" %}

```bash
npm install zotlo-checkout
```

{% endcode %}

{% code title="Yarn" %}

```bash
yarn add zotlo-checkout
```

{% endcode %}

### **2.** Import the SDK

```javascript
import 'zotlo-checkout/dist/zotlo-checkout.css';
import ZotloCheckout from 'zotlo-checkout';
```

### **3.** Initialize Checkout

```javascript
const checkout = await ZotloCheckout({
  token: 'YOUR_CHECKOUT_TOKEN',
  packageId: 'YOUR_PACKAGE_ID',
  returnUrl: 'YOUR_RETURN_URL',
  language: 'en',
  customParameters: {
    myCustomParam: 'OK!'
  },
  events: {
    onSuccess(result) {
      // Payment succeeded
    },
    onFail(error) {
      // Payment failed
    }
  }
});
```

### **4.** Mount Checkout Form

{% code title="HTML" %}

```html
<div id="zotlo-checkout"></div>
```

{% endcode %}

{% code title="JavaScript" %}

```javascript
checkout.mount('zotlo-checkout');
```

{% endcode %}

## Using via CDN

**UNPKG**

{% code title="HTML" %}

```html
<link rel="stylesheet" href="https://unpkg.com/zotlo-checkout/dist/zotlo-checkout.css" />
<script src="https://unpkg.com/zotlo-checkout/dist/zotlo-checkout.min.js"></script>
```

{% endcode %}

**jsDelivr**

{% code title="HTML" overflow="wrap" %}

```html-derivative
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zotlo-checkout/dist/zotlo-checkout.css" />
<script src="https://cdn.jsdelivr.net/npm/zotlo-checkout/dist/zotlo-checkout.min.js"></script>
```

{% endcode %}

#### **Usage Example**

{% code title="HTML" overflow="wrap" %}

```html
<div id="zotlo-checkout"></div>

<script>
  ZotloCheckout({
    token: 'YOUR_CHECKOUT_TOKEN',
    packageId: 'YOUR_PACKAGE_ID',
    returnUrl: 'YOUR_RETURN_URL',
    language: 'en',
    events: {
      onSuccess(result) {
        alert('Payment Success!');
      },
      onFail(error) {
        alert(error.message);
      }
    }
  }).then(function (checkout) {
    checkout.mount('zotlo-checkout');
  });
</script>
```

{% endcode %}

## **Configuration Parameters**

| Parameter                                           | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| --------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **token**                                           | Yes      | Checkout token from Zotlo Dashboard → Developer Tools → Checkout SDK                                                                                                                                                                                                                                                                                                                                                                                      |
| **apiUrl**                                          | No       | Base URL of the API the checkout sends its requests to. Defaults to the Zotlo Checkout API. **Required in the sandbox environment:** set it to `https://checkout-sandbox.zotlo.com/v1`.                                                                                                                                                                                                                                                                   |
| **packageId**                                       | Yes      | ID of the package to be purchased                                                                                                                                                                                                                                                                                                                                                                                                                         |
| **returnUrl**                                       | Yes      | URL to redirect after payment or 3DS                                                                                                                                                                                                                                                                                                                                                                                                                      |
| **subscriberId**                                    | No       | Prefilled subscriber identifier (email, phone, UUID v4)                                                                                                                                                                                                                                                                                                                                                                                                   |
| **customPriceToken**                                | No       | Single-use token created by your backend for each checkout session. Opens the checkout with a custom price and currency for a one-time package. Different from `token`, which stays the same for every user. Requires SDK version 1.26.0 or later.See Using Custom Price. \|                                                                                                                                                                              |
| <p><strong>enableDiscountCodeEntry</strong><br></p> | No       | <p></p><p>Controls whether customers can enter a discount code on the payment form.</p><ul><li><code>true</code> → The <strong>"I have a discount code"</strong> field is displayed and customers can enter a code.</li><li><code>false</code> → The <strong>"I have a discount code"</strong> field is hidden and code entry is disabled.</li><li><code>null</code> → The <strong>Embedded Form settings in the Zotlo Panel</strong> are used.</li></ul> |
| **style**                                           | No       | Custom styling configuration                                                                                                                                                                                                                                                                                                                                                                                                                              |
| **customParameters**                                | No       | Custom key-values sent to webhooks                                                                                                                                                                                                                                                                                                                                                                                                                        |
| **events**                                          | No       | Event listeners during checkout lifecycle                                                                                                                                                                                                                                                                                                                                                                                                                 |
| events.onLoad                                       | No       | Triggers after form loaded.                                                                                                                                                                                                                                                                                                                                                                                                                               |
| events.onSubmit                                     | No       | Triggered after the form is submitted.                                                                                                                                                                                                                                                                                                                                                                                                                    |
| events.onSuccess                                    | No       | Triggered after a successful payment.                                                                                                                                                                                                                                                                                                                                                                                                                     |
| events.onFail                                       | No       | Triggered when a payment fails.                                                                                                                                                                                                                                                                                                                                                                                                                           |
| events.onOfferFail                                  | No       | Triggered when a post payment offer request fails.                                                                                                                                                                                                                                                                                                                                                                                                        |
| events.onInvalidForm                                | No       | Triggers when form has an invalid field.                                                                                                                                                                                                                                                                                                                                                                                                                  |
| events.onError                                      | No       | Triggers when pre-init errors occurs.                                                                                                                                                                                                                                                                                                                                                                                                                     |

## **Event Listeners**

#### **onLoad**

{% code title="JavaScript" overflow="wrap" %}

```javascript
onLoad?: (params: IFormLoad) => void;
```

{% endcode %}

#### onSubmit

{% code title="JavaScript" overflow="wrap" %}

```javascript
onSubmit?: () => void;
```

{% endcode %}

#### onSuccess

{% code title="JavaScript" overflow="wrap" %}

```javascript
onSuccess?: (result: PaymentDetail) => void;
```

{% endcode %}

#### onFail

{% code title="JavaScript" overflow="wrap" %}

```javascript
onFail?: (error: FailEventData) => void;
```

{% endcode %}

#### onOfferFail

Triggers when a post payment offer request fails. `error.data` holds the offer the decision was sent for.

```
onOfferFail?: (error: FailEventData) => void;
```

**Note:** You can see `error` details on type [`FailEventData`](https://github.com/Zotlo/zotlo-checkout/blob/master/src/lib/types.ts#L167) and the offer on type [`OffersObject`](https://github.com/Zotlo/zotlo-checkout/blob/master/src/lib/types.ts#L754)

```
{
  ...
  events: {
    onOfferFail(error) {
      alert(error.message)
      console.log('Post payment offer failed to process:', error.data.offerId)
    }
  }
}
```

#### onInvalidForm

{% code title="JavaScript" overflow="wrap" %}

```javascript
onInvalidForm?: (error: IFormInvalid) => void;
```

{% endcode %}

## **SDK Methods**

#### **mount(containerId: string)**

Embeds the checkout form into a DOM element.

#### **refresh()**

Reloads the form (e.g., after a style or language update).

#### **unmount()**

Removes checkout form from the DOM.

## **Branding & Styling**

You can override default styles configured in Zotlo Dashboard.

{% code title="JavaScript" overflow="wrap" %}

```javascript
style: {
  design: {
    theme: 'mobileapp',
    borderWidth: 2,
    backgroundColor: '#CCCCCC'
  },
  success: {
    show: true,
    waitTime: 20
  }
}
```

{% endcode %}

More details are available in `IZotloCheckoutStyle`.
