# Web Payments

The Web SDK makes it easy to integrate payment flows into your web and browser-based experiences.

## Additional resources

* WHITELABEL offers a [TypeScript library](https://www.npmjs.com/package/@yuno-payments/sdk-web-types) that complements the SDK.
* See [Choose the right integration for you](/docs/sdks/overview/choose-integration) if you're unsure which flow to follow.
* See the [Demo App](https://github.com/yuno-payments/yuno-sdk-web) for a complete implementation (clone from the repository).

## Requirements

* A [customer](/reference/customers/create-customer) created in WHITELABEL and a [checkout session](/reference/checkout-sessions/create-checkout-session): reference each API when setting up your backend.
* Public API key (obtain from the [WHITELABEL Dashboard](https://dashboard.whitelabel.com/) → **Developers** > **Credentials**)

The first step is including the library in your project. The integration guide provides three flexible methods:

1. **Direct HTML script inclusion**: Add the script tag to your page.
2. **Dynamic JavaScript injection**: Load the SDK at runtime.
3. **NPM module installation**: Install via npm (recommended).

**Option 1: NPM (Recommended)**

```bash
npm install @yuno-payments/sdk-web
```

When using the NPM package, `loadScript` injects the SDK script and resolves with the `Whitelabel` object. Pass `sri: true` to have the browser verify the script against its published hash. Initializing is a separate step: call `Yuno.initialize` with your public API key to get the instance you use for the rest of the integration.

```javascript
import { loadScript } from '@yuno-payments/sdk-web';

const Whitelabel = await loadScript({ sri: true });
const whitelabel = await Yuno.initialize('YOUR_PUBLIC_KEY');
```

<Note>
If your account is in the EU region, pass `region: 'eu'` to `loadScript` as well.
</Note>

<Tip>
`loadScript()` only starts downloading the SDK when your app calls it. Add a preload for `main.js` and preconnects to the WHITELABEL hosts in your HTML `<head>` so the download starts while the page loads. See [Preload the SDK script](/docs/sdks/resources/references/web#preload-the-sdk-script).
</Tip>

**Option 2: HTML Script Tag**

```html
<script 
  src="https://sdk-web.whitelabel.com/v1.10/main.js"
  async
  defer
></script>
```

<Note>
`v1.10` is a global path: it receives every patch released on that line, so you get fixes without changing your integration.

Do not add an `integrity` attribute to this URL. Because the file is republished on each patch release, any hash you pin to it stops matching and the browser blocks the script. Subresource Integrity requires the immutable full-version URL instead — see [Subresource Integrity](/docs/sdks/resources/references/web#subresource-integrity-sri).
</Note>

**Option 3: Dynamic JavaScript**

```javascript
const script = document.createElement('script');
script.src = 'https://sdk-web.whitelabel.com/v1.10/main.js';
script.async = true;
script.defer = true;
document.head.appendChild(script);
```

Once Step 1 is complete, continue with the full-checkout integration.

## Parameters

These are the parameters covered in this guide. For the full list of parameters and callbacks, see the [Web SDK Common Reference](/docs/sdks/resources/references/web).

| Parameter                         | Description                                                                                                   |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| `checkoutSession`                 | Checkout session ID from your backend (Create checkout session API). Required for all flows.                  |
| `elementSelector`                 | CSS selector for the element where the SDK mounts (e.g. `#root`).                                             |
| `countryCode`                     | ISO country code where the payment runs (e.g. `FR`, `US`).                                                    |
| `language`                        | Language code for the UI (e.g. `fr-FR`, `ar`). Optional; defaults to browser language when available.               |
| `showLoading`                     | Show SDK loading spinner. Optional.                                                                           |
| `showPaymentStatus`               | Show payment result screen. Optional.                                                                         |
| `yunoCreatePayment(oneTimeToken)` | Callback: send one-time token to your backend to create the payment; then call `await whitelabel.continuePayment()`.      |
| `yunoPaymentResult(status, subStatus)` | Callback: payment finished. Receives [payment status](/reference/payments/status-and-response-codes/payment) (e.g. `SUCCEEDED`, `DECLINED`, `PENDING`) and an optional `subStatus` qualifying it. See [Shopper-cancelled steps](/docs/sdks/resources/references/web#shopper-cancelled-steps). |
| `yunoError(message, data)`        | Callback: error during the flow.                                                                              |
| `onLoading`                       | Callback: loading state updates.                                                                              |
| `onChange`                        | Reports whether the payment form is complete. Receives `{ form: { isValid } }`. Use with `showPayButton: false` to control your own pay button. Available since v1.10.11. |
| `card`                            | Card form options (e.g. `onChange`, `isCreditCardProcessingOnly`). Optional.                                  |

## full-checkout

Implement WHITELABEL's Full integration: pre-built checkout UI with full control over branding, forms, and flow. Use this when you want WHITELABEL to render the checkout experience while you manage customer and checkout session creation on your backend.

### Step 1: Include the library in your project

Follow the steps in [Include the library in your project](#include-the-library-in-your-project) above.

### Step 2: Initialize the SDK

After including the library ([step 1](#step-1-include-the-library-in-your-project)), initialize the SDK. See [Quickstart guide](/docs/sdks/overview/quickstart#web-sdk-integration) for initialization.

### Step 3: Start the checkout process

Use the `await whitelabel.startCheckout()` function to start the checkout process with the necessary parameters.

See [Parameters](#parameters) for all options. For styling, themes, and additional configurations, see [SDK customizations](/docs/sdks/resources/references/web).

```javascript
await whitelabel.startCheckout({
  checkoutSession: "438413b7-4921-41e4-b8f3-28a5a0141638",
  elementSelector: "#root",
  countryCode: "FR",
  language: "fr-FR",
  showLoading: true,
  issuersFormEnable: true,
  showPaymentStatus: true,
  card: {
    isCreditCardProcessingOnly: true,
    onChange: ({ error, data }) => {
      if (error) {
        console.log('Card form error:', error);
      } else {
        console.log('Card form data:', data);
      }
    },
  },
  onLoading: (args) => {
    console.log(args);
  },
  onPaymentMethodSelected: () => {
    console.log("Payment method selected");
  },
  yunoPaymentResult: (status) => {
    console.log("Payment result:", status);
  },
  yunoError: (message, data) => {
    console.error("Payment error:", message, data);
  },
  async yunoCreatePayment(oneTimeToken) {
    await createPayment({ oneTimeToken, checkoutSession });
    await whitelabel.continuePayment({ showPaymentStatus: true });
  },
});
```

By default, WHITELABEL SDK renders as a modal. You can specify the element where the SDK will render. See [Render mode](/docs/sdks/resources/references/web#render-mode) for details.

For all APMs (Google Pay, Apple Pay, PayPal), `onPaymentMethodSelected` triggers when the customer chooses the payment method (before the payment flow begins). Define `onPaymentMethodSelected` in `await whitelabel.startCheckout()` before `await whitelabel.mountCheckout()`. For PayPal, the payment sheet opens immediately after selection—no extra confirmation click required.

### Step 4: Mount the SDK

Display the payment methods:

```javascript
await whitelabel.mountCheckout();
```

### Step 5: Initiate the payment process

Call `await whitelabel.startPayment()` to initiate the payment flow after the user selects a payment method:

```javascript
const PayButton = document.querySelector("#button-pay");

PayButton.addEventListener("click", async () => {
  await whitelabel.startPayment();
});
```

### Step 6: Get the OTT (one-time token)

After the customer fills out the requested data in WHITELABEL's payment forms, the SDK provides the one-time token. The configuration function `yunoCreatePayment(oneTimeToken)` is then triggered with the one-time token.

```javascript
yunoCreatePayment(oneTimeToken);
```

You can also use `tokenWithInformation` to receive additional information provided by the customer in the checkout, such as installments or document type/number:

```javascript
yunoCreatePayment(oneTimeToken, tokenWithInformation);
```

Use WHITELABEL's default loader or implement your own with the required configuration.

### Step 7: Create the payment

Create a payment using the [Create Payment endpoint](/reference/payments/create-payment). The merchant's backend should call this endpoint to create the payment in WHITELABEL using the one-time token and checkout session.

After Step 6, the basic payment flow is implemented. Test using the checkout session and one-time token. For additional features, see [Complementary features](#complementary-features).

**Required**: After creating a payment, integrate the `continuePayment` method. When the API response sets `sdk_action_required` to `true`, call `await whitelabel.continuePayment()` to present the necessary screens.

Card payments that come back `DECLINED` or `ERROR` also require calling `continuePayment` to run payment retry (keeps the card form open with the decline shown); if neither of those applies, call `unmountSdk` to clean up. See [Payment retry](/docs/sdks/resources/references/web#payment-retry) for details.

### `continuePayment` return value or null

For payment methods that require merchant-side action (e.g., when the payment provider requires a redirect URL in a webview), the `await whitelabel.continuePayment()` method returns either an object with the following structure or null:

```typescript
{
  action: 'REDIRECT_URL'
  type: string
  redirect: {
    init_url: string
    success_url: string
    error_url: string
  }
} | null
```

When the method returns an object, you can handle your application's payment flows that require custom redirect handling. When it returns null, no additional merchant-side action is needed.

### Complementary features

For styling, themes, form options, and additional configurations, see [SDK customizations](/docs/sdks/resources/references/web). [Changelog](/changelog/web#v1-3-0).

## Common reference

For full parameter and customization details, see the [Web SDK Common Reference](/docs/sdks/resources/references/web).