Installation
Load SDK v2 from its own path, try every route in sandbox with test cards, use it in React with typed events, and allow the SDK host in your page's CSP.
v2 is served from its own path. /unified/v1/ keeps serving v1, so you move one page at a time by changing one script src, and a page can stay on v1 for as long as it needs:
<!-- v1, unchanged -->
<script src="https://sdk.astrada.co/unified/v1/unifiedEnrollmentSdk.js"></script>
<!-- v2 -->
<script src="https://sdk.astrada.co/unified/v2/unifiedEnrollmentSdk.js"></script>
Load one version per pageNever put the v1 and v2 script tags on the same page. The loader looks for a
/unified/v1/tag first, so a page with both opens the v1 screens.
Try it in sandbox
Sandbox is the same SDK against the sandbox API, so getAccessToken must return a token minted with your sandbox credentials.
-
Ask your Astrada contact to add
network-bulk-enrollments:writeto your sandbox SDK client, the OAuth client whose tokens your backend passes to the SDK. Tokens minted after that carry it. Without it, the bulk kickoff and the confirm request answer403(see Token scopes). -
Create a test subaccount with Visa and Mastercard in its
configurations, as in Testing Single Card Enrollment. -
Set its verification policy and its rails. This call puts the subaccount in sandbox mode (its bank links go to Plaid Sandbox), lets frictionless test cards verify without a challenge, and sets policy A from the table below:
PATCH /subaccounts/{subaccountId} HTTP/1.1 Authorization: Bearer YOUR_ACCESS_TOKEN Content-Type: application/json { "verificationPolicy": { "sandbox": true, "stripeValidationLevel": "MEDIUM" }, "enrollmentPolicy": { "cardEnrollment": true, "bankEnrollment": "amex-only", "bulkEnrollment": "suggested" } }curl -X PATCH https://api.sandbox.astrada.co/subaccounts/{subaccountId} \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "verificationPolicy": { "sandbox": true, "stripeValidationLevel": "MEDIUM" }, "enrollmentPolicy": { "cardEnrollment": true, "bankEnrollment": "amex-only", "bulkEnrollment": "suggested" } }'What happens next: the subaccount's
enrollmentPolicywins field by field over whatopen()passes (see Choose your rails), so set all three rail fields here. Allow up to 60 seconds before you open a bank link (see Bank linking in sandbox).MEDIUMis explained in Verification Risk Tiers. -
Load v2 from the sandbox host and open a session.
personais required:"admin"on a card admin's page,"cardholder"on an employee page.<script type="text/javascript" src="https://sdk.sandbox.astrada.co/unified/v2/unifiedEnrollmentSdk.js" data-id="unified-enrollment-sdk" ></script> <script> UnifiedEnrollmentSdk.open({ subaccountId: "<sandbox subaccountId>", companyName: "Your company", getAccessToken: () => fetch("/your-backend/astrada-sandbox-token").then((r) => r.text()), persona: "admin", // "cardholder" on employee pages onEvent: (event) => console.log(event), onSuccess: (result) => console.log(result.summary), }); </script>Where the tags go: inside
<body>, or callopen()once the page has loaded. The SDK attaches todocument.body, so a call that runs in<head>opens nothing and logs aTypeError.What happens next:
open()resolvestrueonce the SDK is on the page, orfalsewhen it refused the config; the console then lists every field to fix.To try a session without writing a page, use the SDK playground. Its presets set
persona(the employee page uses"cardholder"; the finance admin presets use"admin") and the three rail options, and show theopen()call they produce. -
Drive each route with a test card. On an admin page, type the number on the card number screen and press Continue (it needs 8 digits). On an employee page, type it on the card form: the SDK routes the card once 8 digits are typed.
The tests use three subaccount policies; switch between them with the same
PATCH:Policy enrollmentPolicyA card true, bank"amex-only", bulk"suggested"B card true, bank"off", bulk"suggested"C card true, bank"off", bulk"off"Type this (policy, page) What you see routeinroute-decidedAny number starting 34or37(B, admin)The program screen for an American Express program. Connect all company cards opens the kickoff form, which ends on "Request sent" or "Next: write to your bank" and sends bulk-enrollment-requested.amex-kickoff5555 5511, then Continue (A, admin)The program screen with Connect all company cards and This doesn't look right. The kickoff ends on "Request sent" or "Next: write to your bank", with Connect this card now. proven-single5555 5522, then Continue (A, admin)The callout "You may be able to connect all your cards at once", with Ask Astrada to check and Connect this card now. Sending the request fires bulk-confirmation-requested.high-singleAny number starting 34or37(A, admin or employee)The Amex bank screen (on an employee page, once the card form has the first 8 digits), then the Plaid window (First Platypus Bank in sandbox). Sign in with user_good/pass_goodand pick the credit card account. You getbank-linked, thencard-enrolledwithenrollmentType: "bank-feed".amex-bank4242 4242 4242 4242, expiry12/34, CVC123(A, admin or employee)On an admin page, the card form with the first digits filled in; on an employee page, the card form you are typing in stays open. The card verifies without a challenge and sends card-enrolled.card-only(admin),cardholder-card(employee)5555 5525 0000 1001, any future expiry, CVC123(A, admin)The card form, a 3DS challenge, then success and card-enrolled.card-onlyAny number starting 34or37(C, admin)"This card can't be connected here". amex-not-eligibleAny number starting 34or37(B or C, employee)Once the card form has the first 8 digits, "Your company connects this card", and company-connection-needed.cardholder-company-connectsAbout the kickoff rows: the kickoff ends on "Request sent" when Astrada contacts the bank, or on "Next: write to your bank" when the admin contacts it. Once your account has a kickoff open for the program,
5555 5511opens "Already under way" instead.5555 5511and5555 5522exist only to show these screens in sandbox. They are not full test cards, so a card started from them can't finish the card form: sandbox enrolls only the published test cards. In sandbox, kickoffs and confirm requests never reach a bank or a card network. -
Run it again. Each test card enrolls once per subaccount: enrolling it again reports the existing card with
alreadyEnrolled: true. For a fresh run, delete the subaccount and create another.
Using it in React (TypeScript)
The runtime is the hosted script; the types are a separate package, @astrada.co/card-enrollment-sdk, whose ./unified entry types window.UnifiedEnrollmentSdk, the config and every payload. Install it as a dev dependency:
npm install --save-dev @astrada.co/card-enrollment-sdk@^2.1.0
Check the versionSDK v2 needs version 2.1.0 of the types or later (
personarequired,open()resolving a boolean,bulk-reference-enteredin place offeed-created,logo, andsingleDecisionReasononroute-decided). Versions 1.x type SDK v1. Check withnpm view @astrada.co/card-enrollment-sdk versionbefore you install.
This component loads the SDK, opens a typed session, narrows each onEvent payload by event.type, and closes the session when it unmounts:
import { useEffect } from "react";
import type {
EnrollmentSuccess,
SdkErrorEvent,
SdkEvent,
UnifiedEnrollmentSdkConfig,
} from "@astrada.co/card-enrollment-sdk/unified";
// Sandbox while you test; production is https://sdk.astrada.co/unified/v2/unifiedEnrollmentSdk.js
const SDK_SRC = "https://sdk.sandbox.astrada.co/unified/v2/unifiedEnrollmentSdk.js";
// Loads the script once; the loader defines window.UnifiedEnrollmentSdk. The
// promise is cached at module level, so two components mounting at once (or
// React StrictMode's mount, unmount, mount in development) add one tag.
let sdkLoad: Promise<void> | undefined;
function loadSdk(): Promise<void> {
sdkLoad ??= new Promise((resolve, reject) => {
if (window.UnifiedEnrollmentSdk) return resolve();
const script = document.createElement("script");
script.src = SDK_SRC;
// The loader finds its own tag by src; data-id only matches the HTML snippets above.
script.dataset.id = "unified-enrollment-sdk";
script.onload = () => resolve();
script.onerror = () => {
script.remove();
sdkLoad = undefined; // let the next mount try again
reject(new Error("The Unified Enrollment SDK did not load"));
};
document.head.appendChild(script);
});
return sdkLoad;
}
export function ConnectCards({ subaccountId }: { subaccountId: string }) {
useEffect(() => {
let unmounted = false;
let opened = false; // close() on unmount only for a session this component opened
const config: UnifiedEnrollmentSdkConfig = {
subaccountId,
companyName: "Your company",
persona: "admin", // "cardholder" on an employee page
getAccessToken: () => fetch("/your-backend/astrada-token").then((r) => r.text()),
onEvent: (event: SdkEvent) => {
// event.type narrows the union: each branch sees only its own fields.
switch (event.type) {
case "route-decided":
console.log(event.route, event.bin6);
break;
case "card-enrolled":
console.log(event.cardId, event.enrollmentType, event.last4);
break;
case "bank-linked":
console.log(event.bankLinkId, event.bankAccounts.map((account) => account.id));
break;
case "bulk-enrollment-requested":
console.log(event.enrollmentId, event.alreadyRequested ?? false);
break;
case "closed":
if (event.next === "invite-team") console.log("open your invite page", event.teamLink?.url);
break;
}
},
onSuccess: (result: EnrollmentSuccess) => {
for (const card of Object.values(result.cards)) console.log(card.cardId, card.subscriptionId);
},
onError: (error: SdkErrorEvent) => console.error(error.flow, error.code, error.message),
onCancel: () => console.log("nothing enrolled"),
};
loadSdk()
.then(() => (unmounted ? undefined : window.UnifiedEnrollmentSdk.open(config)))
.then((result) => {
if (result === false) console.error("The SDK refused the config; the console lists each field.");
if (result === true) opened = true;
})
.catch((error: unknown) => console.error(error)); // the script did not load: show your own retry
return () => {
unmounted = true;
if (opened) window.UnifiedEnrollmentSdk?.close();
};
}, [subaccountId]);
return null; // the SDK renders its own overlay; pass `container` to render inline instead
}What happens next: open() tears down any session already open before it opens a new one, so re-rendering with another subaccountId is safe. A session your page ends with close() still gets its one onSuccess (built from the events delivered so far) or onCancel.
What your page's CSP must allow
If your page sends a Content Security Policy, allow the SDK host in two directives. The host is sdk.astrada.co in production and sdk.sandbox.astrada.co in sandbox.
| Directive | Value | Why |
|---|---|---|
script-src | https://sdk.astrada.co | The <script> tag that loads unifiedEnrollmentSdk.js. |
frame-src | https://sdk.astrada.co | The loader opens the card screens in an iframe whose src is on the same host as the script. |
Use https://sdk.sandbox.astrada.co in both rows while you test in sandbox.
For the rest of your policy:
- The loader needs no
style-srcorimg-srcrow: it sets the iframe's and its container's styles through script properties (iframe.style.x = ...) and creates only adivand aniframe, never a<style>element or an image. - It makes no network requests of its own. The only call it triggers from your page is your
getAccessTokenfunction, so yourconnect-srcmust allow wherever that function fetches the token (usually your own backend). - The calls to the Astrada API come from inside the iframe, under the iframe page's own policy, which is Astrada's and needs nothing from you. The same goes for the hosted enrollment pages: they are separate pages on the SDK host with their own policy.
Updated about 1 hour ago
