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.

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
getAccessTokencontract is unchanged: an async function returning a token minted by your backend, with the same 5000 ms default timeout (getAccessTokenTimeoutMsto raise it). Never ship a client secret to the browser. - Config options.
companyName,subaccountId,terms,statusLabels(same four stages),customerReferenceId(a UUID in both) andcontainercarry over unchanged.metadatais 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
setStylevariable 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-coloris 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'sverificationPolicyare untouched. A backend that assigns cards from webhooks needs no changes.
What changes
| Legacy | Unified (v2) | |
|---|---|---|
| Script | https://sdk.astrada.co/v1/cardEnrollmentSdk.js | https://sdk.astrada.co/unified/v2/unifiedEnrollmentSdk.js |
Script data-id | card-enrollment-sdk | None: the script finds itself by its src |
| Global | CardEnrollmentSdk | UnifiedEnrollmentSdk |
| Open / close | openForm(config) / closeForm() | open(config) / close(); open() resolves false when it refuses the config |
| Who the page serves | persona, 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) |
onSuccess | One card, at the moment it enrolls | The whole session, once, at close |
onError payload | { type, error: { detail, errorCode } } | { flow, code, message }, and the session stays open |
onCancel | Cardholder closed the form | Session closed with nothing enrolled |
| New options | onEvent, 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 pageThe 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
onSuccess: one session result, at closeThe 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-enrolledevent ononEvent; it still fires per card, as it happens. - Fields.
enrollmentGuidanceandauthenticationFloware not in the map. Capture them from thecard-enrolledevent 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: falseto keep one-card sessions.
Webhooks stay your system of recordSession callbacks mirror this browser session. The durable record is the
cardsubscription.createdwebhook, which fires for every enrolled card regardless of how the session ended. See Handle what comes back.
onError: new payload, and the flow continues
onError: new payload, and the flow continues| Legacy field | Unified field |
|---|---|
error.errorCode | code |
error.detail | message |
type ("client" / "server") | flow ("card" / "bank" / "feed" / "session") |
verificationId, cardId, subscriptionId | Unchanged: 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
onCancel: means nothing was enrolledIt 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
onEventThe 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 nodata-id. - Rename calls:
CardEnrollmentSdk.openForm()toUnifiedEnrollmentSdk.open(),closeForm()toclose(). - Set
persona:"cardholder"on a page where people connect their own cards,"admin"on a page for a company's card admin. - Rework
onSuccessto iterateresult.cards; readauthenticationFlowandenrollmentGuidancefrom thecard-enrolledevent if you use them. - Rework
onErrorto readcodeandmessage, and stop treating an error as the end of the session. - Re-check
onCancelhandlers; 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
setStyleas 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
enrollmentPolicyon the subaccount (Which value wins) and make sure your SDK client carries their scopes (Token scopes). No client release needed.
Related
- Unified Enrollment SDK v2: how a v2 session runs, with its sub-pages for options, events and scopes.
- Earlier version: SDK v1: only for pages still on v1.
- Legacy SDK: Installation, Configuration and Events & Callbacks: the legacy SDK reference you are migrating from.
- Test Cards & Sandbox Testing: drive success, challenge, and decline paths deterministically.
- Unified Card & Bank Feeds: the shared card model behind every way to connect a card.
Updated 5 days ago
