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

# Using Virtual Card SDK

This is the fastest way to get started using the virtual card offering from Sezzle. A virtual card checkout implements the Card Session API to provide an easy to use, in-context solution for issuing and using a Sezzle virtual card as payment.

<Warning>
  The Sezzle non-production environment does not provide a way to test the payment processing using your provider.
</Warning>

<Warning>
  The origin domain needs to be allowlisted by Sezzle for Virtual Card SDK to function. Please contact your Account Manager and they can do this for you.
</Warning>

<CardGroup cols="2">
  <Card title="Checkouts" icon="code">
    Virtual Card Checkout in an iframe or pop-up window.
  </Card>

  <Card title="Card Details" icon="credit-card">
    Enable plain card details through message event or tokenization.
  </Card>

  <Card title="Payments" icon="money-check-dollar-pen">
    Handle payment success, failure, or cancel with your virtual card orders.
  </Card>

  <Card title="Sezzle Button" icon="badge-check">
    Render the Sezzle checkout button on your store.
  </Card>
</CardGroup>

## Include SDK code

Include the following script in the `<head>` section of the page.

```html theme={"system"}
<script
    type="text/javascript"
    src="https://checkout-sdk.sezzle.com/checkout.min.js"
></script>
```

## Checkout Configuration

The first requirement to get started with the Virtual Card SDK is to configure a new Checkout object.

### Configuration Options

<Tabs>
  <Tab title="Template">
    ```javascript theme={"system"}
    const checkoutSdk = new Checkout({
      mode: string,
      publicKey: string,
      apiMode: string,
      isVirtualCard: boolean,
    });
    ```
  </Tab>

  <Tab title="Example">
    ```javascript theme={"system"}
    const checkoutSdk = new Checkout({
      mode: "popup",
      publicKey: "sz_pub_...",
      apiMode: "sandbox",
      isVirtualCard: true,
    });
    ```
  </Tab>

  <Tab title="Options">
    <ParamField path="mode" default="popup" type="string">
      Available options: `popup`, `iframe`, `redirect`

      <Warning>
        If you use `iframe` mode, add `*.sezzle.com` to your site's Content Security Policy (CSP) allowlist so the Sezzle checkout iframe can load.
      </Warning>

      <Note>
        **popup** mode will work out-of-the-box, and Sezzle recommends it for most browser-based SDK integrations.
        If your checkout runs inside a webview or embedded browser where popups may be blocked, use **iframe** mode instead. **iframe** mode will not work properly without first contacting Sezzle. For security reasons, Sezzle must enable **iframe** for your domain(s). To have it enabled, please submit a request with your Sezzle Merchant UUID and a list of domains to be allowed per environment (production and sandbox). For example, [*please enable uat1.mysite.com, uat2.mysite.com in sandbox and www.mysite.com, mysite.com in production*](http://www.mysite.com).
        **redirect** mode is also supported, but it is generally less useful with the SDK because the SDK's main value is handling the in-context checkout experience and window messaging between your site and Sezzle.
      </Note>
    </ParamField>

    <ParamField path="publicKey" type="string" required>
      Used when creating a checkout or capturing payment. Find your API keys at [https://dashboard.sezzle.com/merchant/settings/apikeys](https://dashboard.sezzle.com/merchant/settings/apikeys)
    </ParamField>

    <ParamField path="apiMode" default="live" type="string">
      Environment in which the checkout is to be completed

      Available options: `live`, `sandbox`
    </ParamField>

    <ParamField path="isVirtualCard" type="boolean">
      Use `true` to enable this feature
    </ParamField>
  </Tab>
</Tabs>

## Sezzle Button

### Sezzle Button Configuration

Create a placeholder element for the Sezzle Button to be rendered on the page(s).

<Tabs>
  <Tab title="Template">
    ```html theme={"system"}
    <div id="sezzle-smart-button-container" style="text-align: center"></div>
    ```
  </Tab>

  <Tab title="Example">
    ```html theme={"system"}
    <div
        id="sezzle-smart-button-container"
        style="text-align: center"
        templateText="Pay with %%logo%%"
        borderType="semi-rounded"
        customClass="action,primary,checkout"
    ></div>
    ```
  </Tab>

  <Tab title="Options">
    <ParamField path="templateText" default="Checkout with %%logo%%" type="string">
      Text to appear inside the button. Use `%%logo%%` inside the text to
      display the Sezzle image
    </ParamField>

    <ParamField path="borderType" type="string">
      Available options: `square`, `semi-rounded`
    </ParamField>

    <ParamField path="customClass" type="string">
      Custom classes to be applied
    </ParamField>

    <ParamField path="paddingTop" default="1px" type="string">
      Negative space between top of content and edge of button
    </ParamField>

    <ParamField path="paddingBottom" default="7px" type="string">
      Negative space between bottom of content and edge of button
    </ParamField>

    <ParamField path="paddingLeft" default="30px" type="string">
      Negative space between left side of content and edge of button
    </ParamField>

    <ParamField path="paddingRight" default="30px" type="string">
      Negative space between right side of content and edge of button
    </ParamField>

    <ParamField path="sezzleImageWidth" default="84px" type="string">
      Width of the Sezzle logo within the button
    </ParamField>

    <ParamField path="sezzleImagePositionTop" type="string">
      Position of the Sezzle logo from top.
    </ParamField>

    <ParamField path="sezzleImagePositionBottom" type="string">
      Position of the Sezzle logo from bottom.
    </ParamField>

    <ParamField path="sezzleImagePositionLeft" type="string">
      Position of the Sezzle logo from left.
    </ParamField>

    <ParamField path="sezzleImagePositionRight" type="string">
      Position of the Sezzle logo from right.
    </ParamField>

    <ParamField path="letterSpacing" type="string">
      Spacing between the templateText letter.
    </ParamField>

    <ParamField path="width" type="string">
      Width of the button
    </ParamField>

    <ParamField path="height" default="4.2em" type="string">
      Height of the button.
    </ParamField>
  </Tab>
</Tabs>

### Render the Sezzle Button

Requires having the `checkout` object created from above to render the button. Call `renderSezzleButton` passing the `id` of the placeholder element defined in Button Configuration, above.

```javascript theme={"system"}
checkoutSdk.renderSezzleButton("sezzle-smart-button-container");
```

## Initialize the Checkout

### Event Handlers

The SDK requires the following event handlers that can be used to extend features in your application.

<Tabs>
  <Tab title="Template">
    ```javascript theme={"system"}
    checkoutSdk.init({
      onClick: function () {
        event.preventDefault();
        checkoutSdk.startCheckout({...});
      },
      onComplete: function (response) {
        console.log(response.data);
      },
      onCancel: function () {
        console.log("Checkout cancelled.");
      },
      onFailure: function () {
        console.log("Checkout failed.");
      },
    });
    ```
  </Tab>

  <Tab title="Example">
    ```javascript expandable theme={"system"}
    checkoutSdk.init({
      onClick: function () {
        event.preventDefault();
        checkoutSdk.startCheckout({
                checkout_payload: {
                    amount_in_cents: 1000,
                    currency: "USD",
                    merchant_reference_id: "merchant-checkout-id-max-255",
                    customer: {
                        email: "test@test.com",
                        first_name: "John",
                        last_name: "Doe",
                        phone: "0987654321",
                        billing_address_street1: "3432 Terry Lane",
                        billing_address_street2: "12",
                        billing_address_city: "Katy",
                        billing_address_state: "TX",
                        billing_address_postal_code: "77449",
                        billing_address_country_code: "US",
                    },
                    items: [
                        {
                            name: "Blue tee",
                            sku: "sku123456",
                            quantity: 1,
                            price: {
                                amount_in_cents: 1000,
                                currency: "USD",
                            },
                        },
                    ],
                },
        });
      },
    onComplete: function (response) {
      // Virtual card data is available in response.data.card and response.data.holder.
      // Use this data to charge the card through your own payment processor
      // (e.g., Stripe, Cybersource, Braintree).
      console.log("Card data received:", response.data);
      },
      onCancel: function () {
        console.log("Checkout cancelled.");
      },
      onFailure: function () {
        console.log("Checkout failed.");
      },
    });
    ```
  </Tab>

  <Tab title="Options">
    <ParamField path="onClick" type="function" required>
      Sezzle Button is clicked by the user.

      <Note>
        See [Checkout Initialization](#checkout-initialization) section for payload options.
      </Note>
    </ParamField>

    <ParamField path="onComplete" type="function" required>
      Sezzle payment is successfully completed. A successfully completed Sezzle checkout will trigger an event to the `onComplete` handler. The event should include a data object with data relevant to the start checkout input parameter.
    </ParamField>

    <ParamField path="onCancel" type="function" required>
      Sezzle payment is cancelled. If the user exits the Sezzle checkout for any reason, the `onCancel` handler will be executed.
    </ParamField>

    <ParamField path="onFailure" type="function" required>
      Sezzle payment has failed. If there is an error loading the Sezzle checkout page, the `onFailure` handler will be executed.
    </ParamField>
  </Tab>
</Tabs>

### Checkout Initialization

<Tabs>
  <Tab title="Template">
    ```javascript expandable theme={"system"}
    checkoutSdk.startCheckout({
      checkout_payload: {
        amount_in_cents: integer,
        currency: string,
        merchant_reference_id: string,
        customer: {
            email: string,
            first_name: string,
            last_name: string,
            phone: string,
            billing_address_street1: string,
            billing_address_street2: string,
            billing_address_city: string,
            billing_address_state: string,
            billing_address_postal_code: string,
            billing_address_country_code: string,
        },
        items: [
            {
                name: string,
                sku: string,
                quantity: integer,
                price: {
                    amount_in_cents: integer,
                    currency: string,
                },
            },
        ],
      },
    });
    ```
  </Tab>

  <Tab title="Example">
    ```javascript expandable theme={"system"}
    checkoutSdk.startCheckout({
      checkout_payload: {
        amount_in_cents: 1000,
        currency: "USD",
        merchant_reference_id: "merchant-checkout-id-max-255",
        customer: {
            email: "test@test.com",
            first_name: "John",
            last_name: "Doe",
            phone: "0987654321",
            billing_address_street1: "3432 Terry Lane",
            billing_address_street2: "12",
            billing_address_city: "Katy",
            billing_address_state: "TX",
            billing_address_postal_code: "77449",
            billing_address_country_code: "US",
        },
        items: [
            {
                name: "Blue tee",
                sku: "sku123456",
                quantity: 1,
                price: {
                    amount_in_cents: 1000,
                    currency: "USD",
                },
            },
        ],
      },
    });
    ```
  </Tab>

  <Tab title="Options">
    <Note>
      `checkout_payload` is optional but providing as much information as possible will improve customer experience.
    </Note>

    <ParamField path="amount_in_cents" type="integer">
      The amount of the item in cents
    </ParamField>

    <ParamField path="currency" default="USD" type="string">
      The 3 character currency code as defined by ISO 4217
    </ParamField>

    <ParamField path="merchant_reference_id" type="string">
      Typically a checkout or cart id, currently used for tracking only (must contain only alphanumeric characters, dashes (-), and underscores (\_))

      <Note>
        Used only for troubleshooting. The Reference ID that shows in the Merchant Dashboard can be set using [Set Order Reference ID](#set-order-reference-id)
      </Note>
    </ParamField>

    <ParamField path="customer" type="object">
      The customer for the order

      <Expandable title="child attributes">
        <ParamField path="email" type="string">
          The customer's email address
        </ParamField>

        <ParamField path="first_name" type="string">
          The customer's first name
        </ParamField>

        <ParamField path="last_name" type="string">
          The customer's last name
        </ParamField>

        <ParamField path="phone" type="string">
          The customer's phone number
        </ParamField>

        <ParamField path="billing_address_street1" type="string">
          The street and number of the address
        </ParamField>

        <ParamField path="billing_address_street2" type="string">
          The apt or unit
        </ParamField>

        <ParamField path="billing_address_city" type="string">
          The city
        </ParamField>

        <ParamField path="billing_address_state" type="string">
          The 2 character state code
        </ParamField>

        <ParamField path="billing_address_postal_code" type="string">
          The postal delivery code
        </ParamField>

        <ParamField path="billing_address_country_code" type="string">
          The 2 character country code
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField path="items" type="array">
      The items being purchased

      <Expandable title="child attributes">
        <ParamField path="name" type="string">
          The name of the item
        </ParamField>

        <ParamField path="sku" type="string">
          The sku identifier
        </ParamField>

        <ParamField path="quantity" type="integer">
          The quantity purchased
        </ParamField>

        <ParamField path="price" type="object">
          The price object

          <Expandable title="child attributes">
            <ParamField path="amount_in_cents" type="integer">
              The amount of the item in cents
            </ParamField>

            <ParamField path="currency" default="USD" type="string">
              The 3 character currency code as defined by ISO 4217
            </ParamField>
          </Expandable>
        </ParamField>
      </Expandable>
    </ParamField>
  </Tab>
</Tabs>

### `onComplete` with card data

<Warning>
  This response format delivers the **full card number (PAN) and CVV** directly to your frontend JavaScript. If your systems do not already handle raw cardholder data, this may expand your PCI DSS compliance scope. For a more secure alternative, see [`onComplete` with tokenization](#oncomplete-with-tokenization), which keeps card data out of the browser and limits handling to your server.
</Warning>

The `event.data` will contain a fully formed payload containing the customers payment method. This information is not the payment method used to pay Sezzle but one that can be used through your payment gateway (Cybersource, Stripe, Braintree, etc).

#### `event.data` response

<Tabs>
  <Tab title="Template">
    ```json expandable theme={"system"}
    {
        "session_id": string,
        "card": {
            "firstName": string,
            "lastName": string,
            "pan": string,
            "cvv": string,
            "expiryMonth": string,
            "expiryYear": string
        },
        "holder": {
            "email": string,
            "phone": string,
            "firstName": string,
            "lastName": string,
            "address1": string,
            "address2": string,
            "city": string,
            "state": string,
            "country": string,
            "postalCode": string
        }
    }
    ```
  </Tab>

  <Tab title="Example">
    ```json expandable theme={"system"}
    {
        "session_id": "123",
        "card": {
            "firstName": "John",
            "lastName": "Doe",
            "pan": "4242424242424242",
            "cvv": "123",
            "expiryMonth": "02",
            "expiryYear": "28"
        },
        "holder": {
            "email": "john.doe@example.com",
            "phone": "6125551234",
            "firstName": "John",
            "lastName": "Doe",
            "address1": "123 W Lake St",
            "address2": "Unit 104",
            "city": "Minneapolis",
            "state": "MN",
            "country": "US",
            "postalCode": "55408"
        }
    }
    ```
  </Tab>

  <Tab title="Options">
    <ParamField path="session_id" type="string">
      The unique identifier for this card session
    </ParamField>

    <ParamField path="card" type="object">
      <Expandable>
        <ParamField path="firstName" type="string">
          The first name on the card
        </ParamField>

        <ParamField path="lastName" type="string">
          The last name on the card
        </ParamField>

        <ParamField path="pan" body="The 16 digit card number" type="string">
          The 16 digit card number
        </ParamField>

        <ParamField path="cvv" type="string">
          The security code on back of the card
        </ParamField>

        <ParamField path="expiryMonth" type="string">
          The expiration month on the card
        </ParamField>

        <ParamField path="expiryYear" type="string">
          The expiration year on the card
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField path="holder" type="object">
      <Expandable title="child attributes">
        <ParamField path="email" type="string">
          The customer's email address
        </ParamField>

        <ParamField path="phone" type="string">
          The customer's phone number
        </ParamField>

        <ParamField path="firstName" type="string">
          The customer\`s first name
        </ParamField>

        <ParamField path="lastName" type="string">
          The customer\`s last name
        </ParamField>

        <ParamField path="address1" type="string">
          The street and number of the address
        </ParamField>

        <ParamField path="address2" type="string">
          The apt or unit
        </ParamField>

        <ParamField path="city" type="string">
          The city
        </ParamField>

        <ParamField path="state" type="string">
          The 2 character state code
        </ParamField>

        <ParamField path="country" type="string">
          The 2 character country code
        </ParamField>

        <ParamField path="postalCode" type="string">
          The postal delivery code
        </ParamField>
      </Expandable>
    </ParamField>
  </Tab>
</Tabs>

### `onComplete` with tokenization

<Note>
  **Recommended for most merchants.** Tokenization keeps card data out of your browser and reduces your PCI DSS compliance scope. Card data is retrieved server-side only.
</Note>

Tokenization is a feature developed for merchants who do not want the card information sent directly through the message event. Instead the payload to `onComplete` will contain a card token string, which your server can exchange for card data using the [Virtual Card Data](/docs/api/core/sessions/virtual/carddatabytoken) API. The token is single-use and expires after 24 hours.

#### Checkout initialization

```diff theme={"system"}
checkout.init({
    onClick: function () {
        event.preventDefault();
        checkout.startCheckout({
            checkout_payload: {
                ...
+               "card_response_format":"token"
            }
        });
    },
    onComplete: function (response) {
      console.log(response.data);
    },
    onCancel: function() {
        console.log("checkout canceled");
    },
    onFailure: function() {
        console.log("checkout failed");
    }
})
```

#### `event.data` response

<Tabs>
  <Tab title="Template">
    ```json theme={"system"}
    {
        "card": {
            "token": string
        }
    }
    ```
  </Tab>

  <Tab title="Example">
    ```json theme={"system"}
    {
        "card": {
            "token": "abc12345"
        }
    }
    ```
  </Tab>

  <Tab title="Options">
    <ParamField path="card" type="object">
      <Expandable>
        <ParamField path="token" type="string">
          Single-use token for retrieving card data server-side via the [Virtual Card Data](/docs/api/core/sessions/virtual/carddatabytoken) API. Expires after 24 hours.
        </ParamField>
      </Expandable>
    </ParamField>
  </Tab>
</Tabs>

#### Get card data

The virtual card data can be obtained using the token above using the [Virtual Card Data](/docs/api/core/sessions/virtual/carddatabytoken) method.

## Set Order Reference ID

In many cases, the merchant order ID will not be generated until after the checkout is completed and an order is created. Call `setOrderReferenceID` to set the Sezzle Order Reference ID with the merchant order ID after the virtual card transaction has been successfully completed.

### Using SDK

<Tabs>
  <Tab title="Template">
    ```javascript theme={"system"}
    checkoutSdk.setOrderReferenceID({
        session_id: string,
        order_id: string,
    });
    ```
  </Tab>

  <Tab title="Example">
    ```javascript theme={"system"}
    checkoutSdk.setOrderReferenceID({
        session_id: "example-session-id",
        order_id: "merchant-order-id",
    });
    ```
  </Tab>

  <Tab title="Options">
    <ParamField path="session_id" type="string">
      The unique identifier for the card session, returned in the `onComplete` event data
    </ParamField>

    <ParamField path="order_id" type="string">
      Your merchant order ID to associate with this Sezzle order
    </ParamField>
  </Tab>
</Tabs>

### Using API

The [Update Card Session](/docs/api/core/sessions/virtual/setorderid) API endpoint allows you to update the Order ID for a given card session.
