> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.runpayments.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.runpayments.io/_mcp/server.

# Run Tokenization Migration Guide

## Overview

This guide is for ISVs and developers who already collect card or bank account details with **Runner v1** ([`runner.js`](/docs/guides/tokenization/runner-js), versions 1.x) and want to move to **Runner v2** (`runner-v2.js`).

Runner v2 is the SDK for [Run Tokenization](/docs/guides/tokenization/run-tokenization). It renders a single, themeable card form that stays the same whichever gateway processes your transactions. Run turns on Run Tokenization for each MID.

**In short:** swap the script tag, keep your existing `init()` and `tokenize()` code, set `useCvv` and `useExpiry` explicitly, and check whether your server reuses browser tokens.

> **Info**
>
> **Migration is optional.** Runner v1 continues to work and is not deprecated.

## Do I Need to Migrate?

| Current Implementation                                                                         | How to Update                                                                     |
| ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| You want Run Tokenization (one themeable card form that works across gateways)                 | Migrate to v2 and ask Run to enable Run Tokenization on your MIDs.                |
| You only use ACH, or your MIDs will stay on their gateway's hosted fields                      | Optional. On these MIDs, v2 renders the same gateway form as v1.                  |
| You pin a 1.x version (for example `…/javascripts/1.5.5/runner.js`) and don't want any changes | No action needed. Pinned 1.x bundles never change and never use Run Tokenization. |

> **Note**
>
> Run enables Run Tokenization on each MID; your code doesn't. Loading v2 on a MID without Run Tokenization enabled changes nothing visible.

## Migration Steps

#### Replace the Script Tag

```html
<!-- Before: Runner v1 -->
<script src="https://javelin.runpayments.io/javascripts/1.5.5/runner.js"></script>

<!-- After: Runner v2, pinned -->
<script src="https://javelin.runpayments.io/javascripts/2.0.4/runner-v2.js"></script>
```

Load `runner-v2.js`, not `runner.js`. In production, pin a specific version (such as `2.0.4`) instead of `latest`, so a new release never reaches your checkout before you've tested it.

| Environment | `env` value            | Script host                              |
| ----------- | ---------------------- | ---------------------------------------- |
| Production  | `production` (default) | `https://javelin.runpayments.io`         |
| Staging     | `staging`              | `https://javelin-staging.runpayments.io` |

#### Keep Your Integration Code

The global is still `Runner`, and the public API is the same as in v1:

```javascript
var runner = new Runner({ env: 'production' });

runner.init({
  element:   '#card-form',
  publicKey: 'pk_live_xxx',
  mid:       '496160873888',
});

runner.tokenize(function (result) {
  if (result.account_token) {
    // Send result.account_token to your server
  } else {
    console.error(result.tokenizererror);
  }
});
```

These all still work: `init`, `tokenize(done, expMonth?, expYear?)`, `destroy`, `onLoaded`, `onTokenize`, `getTokenizerError`, `cardDataChanged`, `validationMessageChange`, the Plaid methods, and every v1 option.

#### Set useCvv and useExpiry Explicitly

On MIDs with Run Tokenization enabled, these options default to `true` (in v1 they defaulted to `false`). If you've never set them, your form will start showing CVV and expiry fields. Set them explicitly so the form looks the way you intend:

```javascript
runner.init({
  element:   '#card-form',
  publicKey: 'pk_live_xxx',
  mid:       '496160873888',
  useCvv:    true,
  useExpiry: true,
});
```

#### Enable Run Tokenization on a Test MID

Send your Run representative the MIDs you want enabled. Start with one staging MID, work through the [testing checklist](#testing-checklist) below, then roll out one MID at a time.

#### Update Your Server If It Reuses Browser Tokens

Most integrations need to check this step. See [Server-side changes](#server-side-changes) below.

## What Isn't Changing

* **Same global and methods.** `new Runner(...)`, `init()`, `tokenize()`, `destroy()` and the v1 callbacks keep their names and signatures.
* **MIDs without Run Tokenization behave exactly as in v1.** CardConnect, CyberSource, Payroc and iStream MIDs get the same gateway hosted fields, option defaults and result shape.
* **ACH and Plaid work as before.** Continue to pass the Plaid attempt ID on the charge as you do today.
* **Card readers** (`cardReaderInputId`) still tokenize through the gateway, even on Run Tokenization MIDs, because encrypted reader data is tied to that gateway.
* **The Charge API is unchanged.** Send the token as `account_token` to `POST /api/v1/charge`, with the same payload and response.
* **Validation errors** still arrive as JSON (`{ "message": "…" }`) through `validationMessageChange` and the hidden `#tokenizererror` field.

## Changes for Run Tokenization

### The Card Form

| Feature                                                                                     | Runner v1                                                        | Runner v2 (Run Tokenization MID)                                                                                                                                       |
| ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Form                                                                                        | The gateway's hosted fields                                      | One Run-hosted iframe containing card number, expiry and CVV                                                                                                           |
| `useCvv` / `useExpiry` default                                                              | `false`                                                          | `true`                                                                                                                                                                 |
| Expiry input                                                                                | Separate month and year (on some gateways)                       | One `MM/YY` field                                                                                                                                                      |
| Default expiry label                                                                        | Expiration Date                                                  | Expiry                                                                                                                                                                 |
| `yearPlaceholder` and per-field selectors (`cardNumberFieldSelector`, `payroc*Selector`, …) | Supported                                                        | Ignored; the form renders inside `element`                                                                                                                             |
| Styling                                                                                     | Gateway-specific CSS format                                      | One CSS string or object, filtered by an allowlist                                                                                                                     |
| `inactivityto`                                                                              | Defaults to `300`; only works with `tokenizeAutomatically: true` | Defaults to `0` and fires on its own. This applies only to Run Tokenization fields: on CardConnect, v2 still defaults to `300` and still needs `tokenizeAutomatically` |

### New Options

| Option         | Default     | Description                                                              |
| -------------- | ----------- | ------------------------------------------------------------------------ |
| `layout`       | `'default'` | Field arrangement: `default`, `single-row`, `stacked` or `custom`        |
| `errorDisplay` | `'inline'`  | Show errors inline next to each field, or in one summary region          |
| `updateMode`   | `false`     | For updating a card on file: the expiry field is not shown or required   |
| `autoAdvance`  | `true`      | Moves focus from card number to expiry to CVV as each field is completed |

### New Callbacks

Set these on the `Runner` class, not on an instance:

| Callback               | Fires when                                                                             |
| ---------------------- | -------------------------------------------------------------------------------------- |
| `Runner.onFieldChange` | A field changes. Returns `{ field, state, valid }`; never the field value.             |
| `Runner.onBinInfo`     | The first six digits are entered. Returns the card brand and first six digits.         |
| `Runner.onIdleTimeout` | Card data that was entered but not submitted is cleared after 5 minutes of inactivity. |

### The Token Result

```javascript
// Success (Runner v2, Run Tokenization MID)
{ account_token: "3f2b…", bin: "411111", last4: "1111", brand: "visa", expiry: "12/28" }

// Failure
{ account_token: null, tokenizererror: "Invalid card number" }
```

The result no longer includes `card_info`, `bank_account` or `risk_info`. Use `bin`, `last4` and `brand` instead. `cardDataChanged` does not fire on Run Tokenization MIDs; read the same data from the `tokenize()` result or from `onTokenize`.

For the full list of options and styling, see the [Run Tokenization](/docs/guides/tokenization/run-tokenization) reference.

## Potential Hurdles

| Issue                                              | Cause                                                                                      | Fix                                                                    |
| -------------------------------------------------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- |
| CVV and expiry fields appear unexpectedly          | These now default to `true` on Run Tokenization MIDs                                       | Set `useCvv` and `useExpiry` explicitly (step 3)                       |
| Server-side charges with saved browser tokens fail | Run Tokens are now short-lived and single-use                                              | Save a vault instead (see [Server-side changes](#server-side-changes)) |
| The form doesn't load and shows an error           | An unrecognized `env` value. v1 silently fell back to a different host; v2 refuses to load | Use only `production` or `staging`                                     |

### Good to Know

* **Layout.** Card number, expiry and CVV live in one iframe. You can arrange them with `layout` or `css`, but you can't place your own inputs between them.
* **CSS.** Properties such as `position`, `z-index`, `transform`, `url(...)` and `@import` are removed. Colors, fonts, borders, spacing and grid placement are allowed.
* **Single-page apps.** Call `runner.destroy()` before mounting the form again.

## Server-Side Changes

On a Run Tokenization MID, the `account_token` returned to the browser is a **Run Token**, a short-lived card session reference:

* It **expires 5 minutes** after tokenization.
* It is **single-use**: the first charge or vault creation consumes it.
* It only works for **MIDs under the same customer** as the MID that created it.

`POST /api/v1/bin-info` and `POST /api/v1/surcharge` read the token without consuming it, so you can call them before the charge.

If your server saves the browser token to charge later, that will stop working. Save a vault instead:

| You want to…                         | Do this                                                                      |
| ------------------------------------ | ---------------------------------------------------------------------------- |
| Charge now and keep the card on file | Charge with `vault: "Y"`, then use the returned `vault_id` for later charges |
| Keep a card from a previous charge   | `POST /api/v1/vault_payment_accounts/from_transaction`                       |
| Charge a saved card                  | Charge with `vault_id`, as you do today                                      |

Existing vaults keep working after you migrate. As long as Run Tokenization stays enabled on a MID, vaults created through it can still be charged even if Run later moves that MID to a different gateway.

If you charge with a Run Token on a MID that doesn't have Run Tokenization enabled, the charge is declined with the message *Card token is invalid or expired — please re-enter card details.* If you see this, ask the customer to enter their card again.

## Testing Checklist

Run these checks on a **staging MID with Run Tokenization enabled**:

* [ ] The form shows the fields you expect (CVV, expiry).
* [ ] A valid test card returns `account_token`, `bin`, `last4` and `brand`.
* [ ] An invalid card number shows an error and returns `account_token: null`.
* [ ] A charge with the token is approved, and a second charge with the same token is declined.
* [ ] A charge with `vault: "Y"` creates a vault, and a later charge with that `vault_id` is approved.
* [ ] A charge on a vault created before the migration is approved.
* [ ] Your styling, layout and error placement look right on mobile and desktop.
* [ ] If you use `updateMode`, the expiry you pass to `tokenize()` reaches the charge.

## Rolling Back

To roll back, restore your pinned v1 script tag. Vaults are stored by Run, so vaults created while you were on v2 keep working. If you also want a MID taken off Run Tokenization, ask your Run representative to disable it.