Moving to SDK v2

Move a page from the legacy Card Enrollment SDK to Unified Enrollment SDK v2: script swap, the persona option, reworked callbacks, types and a checklist.

For: developers

What's involved

The Unified Enrollment SDK replaces the legacy Card Enrollment SDK with one flow that covers card entry, bank connections and network bulk feeds. Move to its current version, SDK v2, served from /unified/v2/. Unified Enrollment SDK v2 is its guide; this page covers what changes when you come from the legacy SDK. Migrating is client-side work: swap the script, rename the global, say who your page serves with persona, and rework the callbacks. Your backend keeps working as is, with the same token endpoint, the same webhooks and the same cardId and subscriptionId.

With its default settings, v2 enrolls a card through the card form and 3DS verification, full-screen or in your container, as the legacy SDK does:

  • A page where people connect their own cards (persona: "cardholder") opens on the card form.
  • A page for a company's card admin (persona: "admin") asks for the card's first digits first, then opens the card form with them filled in.
  • The legacy SDK's intro screen ("Link your card to ...", Continue) is gone: v2 opens straight on one of the two screens above.
Two rows. Legacy Card Enrollment SDK: an intro screen, Link your card to Lumen Freight with Continue, then the card form, Enter your card credentials. SDK v2: with persona cardholder, the card form Enter the card you use for work; with persona admin, Connect your company card to Lumen Freight asking for the first 8 digits.

What a person sees first, before and after the move. The legacy intro screen is gone in v2.

Bank linking and bulk feeds stay off until you turn them on server-side, so you can migrate first and adopt them later with no client release; see Which value wins. The bank step and bulk enrollment call more endpoints, with the scopes listed in Token scopes.

What stays the same

  • Authentication. The getAccessToken contract is unchanged: an async function returning a token minted by your backend, with the same 5000 ms default timeout (getAccessTokenTimeoutMs to raise it). Never ship a client secret to the browser.
  • Config options. companyName, subaccountId, terms, statusLabels (same four stages), customerReferenceId (a UUID in both) and container carry over unchanged. metadata is reserved in both SDKs and does nothing yet.
  • onConnect. Fires at the same moment in both SDKs: when the cardholder submits the card form and verification begins. An existing handler carries over as is.
  • Theming. Every legacy setStyle variable keeps its name and the part it colors. The unified SDK adds variables for its other surfaces, listed in Colors with setStyle. In v2 a pale --btn-primary-bg-color is darkened until its button text passes a 4.5:1 contrast ratio; SDK v2: Visual Customization says what else v2 changes.
  • Everything server-side. Webhooks (cardsubscription.created), REST resources, ids, and the subaccount's verificationPolicy are untouched. A backend that assigns cards from webhooks needs no changes.

What changes

LegacyUnified (v2)
Scripthttps://sdk.astrada.co/v1/cardEnrollmentSdk.jshttps://sdk.astrada.co/unified/v2/unifiedEnrollmentSdk.js
Script data-idcard-enrollment-sdkNone: the script finds itself by its src
GlobalCardEnrollmentSdkUnifiedEnrollmentSdk
Open / closeopenForm(config) / closeForm()open(config) / close(); open() resolves false when it refuses the config
Who the page servespersona, required: "cardholder" or "admin"
TypeScript types@astrada.co/card-enrollment-sdk@astrada.co/card-enrollment-sdk/unified (same package, new entry point, version 2.1.0)
onSuccessOne card, at the moment it enrollsThe whole session, once, at close
onError payload{ type, error: { detail, errorCode } }{ flow, code, message }, and the session stays open
onCancelCardholder closed the formSession closed with nothing enrolled
New optionsonEvent, the ways a card can connect (cardEnrollment, bankEnrollment, bulkEnrollment), linkAnotherCard, maxWidth, locale, logo and more; see Options

The renames are mechanical, and persona is one new line. The three callback rows change behavior, so take them one at a time below.

The swap

<script
  type="text/javascript"
  src="https://sdk.astrada.co/v1/cardEnrollmentSdk.js"
  data-id="card-enrollment-sdk"
></script>
<script>
  CardEnrollmentSdk.openForm({
    companyName: "Your company",
    subaccountId: "<subaccountId>",
    getAccessToken: async () => "<access token>",
    onSuccess: (data) => assignCard(data.cardId, data.subscriptionId),
    onError: (data) => showError(data.error.detail),
    onCancel: () => {},
  });
</script>
<script src="https://sdk.astrada.co/unified/v2/unifiedEnrollmentSdk.js"></script>
<script>
  UnifiedEnrollmentSdk.open({
    companyName: "Your company",
    subaccountId: "<subaccountId>",
    persona: "cardholder", // "admin" on a page for a company's card admin
    getAccessToken: async () => "<access token>",
    onSuccess: (result) => {
      for (const card of Object.values(result.cards)) {
        assignCard(card.cardId, card.subscriptionId);
      }
    },
    onError: (err) => showError(err.message),
    onCancel: () => {},
  });
</script>
📘

Both SDKs can share a page

The two SDKs use separate globals, and the unified loader listens only to its own iframe, so a page can load both script tags during a staged rollout. Open one SDK at a time, and don't mount both into the same container. Load one unified version per page: never the /unified/v1/ and /unified/v2/ tags together.

Rework the callbacks

onSuccess: one session result, at close

The legacy SDK fired onSuccess the moment a card enrolled, with that one card. The unified SDK fires it once, when the session closes with at least one completed action, with a map of everything the session created. Iterate the map instead of reading data.cardId:

onSuccess: (result) => {
  for (const card of Object.values(result.cards)) {
    assignCard(card.cardId, card.subscriptionId);
  }
},

Three things to check in your handler:

  • Timing. If you acted at the moment of enrollment (advancing your own UI, polling the subscription), read the card-enrolled event on onEvent; it still fires per card, as it happens.
  • Fields. enrollmentGuidance and authenticationFlow are not in the map. Capture them from the card-enrolled event if you use them.
  • Multiple cards. The success screen offers Connect another company card, so one session can produce several. The loop above handles that; pass linkAnotherCard: false to keep one-card sessions.
🚧

Webhooks stay your system of record

Session callbacks mirror this browser session. The durable record is the cardsubscription.created webhook, which fires for every enrolled card regardless of how the session ended. See Handle what comes back.

onError: new payload, and the flow continues

Legacy fieldUnified field
error.errorCodecode
error.detailmessage
type ("client" / "server")flow ("card" / "bank" / "feed" / "session")
verificationId, cardId, subscriptionIdUnchanged: present once the objects exist

Errors no longer end the enrollment. The SDK shows the error screen and lets the person try again or try a different card, so treat onError as a signal for logging and support, and let onSuccess or onCancel tell you how the session ended.

If you intercepted card_subscription.card_must_be_network_bulk_enrolled and called closeForm() to run your own flow, retire that workaround. On an admin page with bulk on, v2 sends a card whose program goes in bulk to its bulk step before the card form; see What users see.

onCancel: means nothing was enrolled

It fires only when the session closes with zero completed actions. A session that enrolled a card and then closed fires onSuccess, never onCancel. If your handler assumed no card was created, that assumption now always holds. If you only need to know the surface closed, listen on onEvent for closed, which ends a session with completed actions and carries the same maps onSuccess gets, and for cancelled, which ends one without.

Optional: switch to onEvent

The callbacks above are enough for a like-for-like migration. onEvent is the unified SDK's primary callback and streams every action as it happens: card-enrolled, bank-linked, route-decided, bulk-enrollment-requested, error, closed, cancelled and more, listed in Events and callbacks. Adopt it when you want per-action reactions, and before you turn on the bank step or bulk enrollment.

Update the types

Same package, new entry point. The root export keeps typing the legacy SDK, so both imports coexist while you migrate. SDK v2 needs version 2.1.0 or later:

npm install --save-dev @astrada.co/card-enrollment-sdk@^2.1.0
// Before
import type { CardEnrollmentSdkConfig, EnrollmentSuccess } from "@astrada.co/card-enrollment-sdk";

// After
import type {
  UnifiedEnrollmentSdkConfig,
  EnrollmentSuccess, // now the consolidated session result
  SdkEvent,          // the onEvent union
} from "@astrada.co/card-enrollment-sdk/unified";

EnrollmentSuccess exists at both entry points with different shapes. Import it from the entry point that matches the SDK you're calling.

Migration checklist

  • Swap the script for https://sdk.astrada.co/unified/v2/unifiedEnrollmentSdk.js; it needs no data-id.
  • Rename calls: CardEnrollmentSdk.openForm() to UnifiedEnrollmentSdk.open(), closeForm() to close().
  • Set persona: "cardholder" on a page where people connect their own cards, "admin" on a page for a company's card admin.
  • Rework onSuccess to iterate result.cards; read authenticationFlow and enrollmentGuidance from the card-enrolled event if you use them.
  • Rework onError to read code and message, and stop treating an error as the end of the session.
  • Re-check onCancel handlers; it now fires only when nothing was enrolled.
  • Retire any closeForm() workaround for bulk-eligible cards.
  • Point TypeScript imports at @astrada.co/card-enrollment-sdk/unified, version 2.1.0 or later.
  • Keep setStyle as is (same variables); add the new ones when you want them.
  • Test the full flow in sandbox before switching production traffic: Testing.
  • When you're ready for bank linking or bulk feeds, set enrollmentPolicy on the subaccount (Which value wins) and make sure your SDK client carries their scopes (Token scopes). No client release needed.

Related


Did this page help you?