Quick Start

Run the Unified Enrollment SDK v2 in sandbox on your own page: set a test subaccount's policy, then try the card form, bank sign-in and company program.

For: developers

This page gets the Unified Enrollment SDK v2 running on a page of your own against sandbox, then connects test cards with it. v2 is the SDK to start a new integration on.

For web developersStart in sandboxYou need sandbox credentials (sign up)

The SDK reads a card's first digits and picks the route from the card's program and from who is on the page: a card admin or an employee. This page uses an admin page. Every route: What users see; every option: Configuration; every event: Events & Callbacks.

1. Serve a token from your backend

Sandbox is the same SDK against the sandbox API, so getAccessToken must return a token minted with your sandbox credentials. Sandbox is self sign-up at astrada.co/sandbox: enter your work email and Astrada sends you a link that creates your sandbox and shows your credentials. Minting a token: Get a token. Your backend mints it and returns it to your page as plain text, with no Bearer in front. The function must resolve within 5 seconds, or within the getAccessTokenTimeoutMs you set. Keep the client secret on your backend; never send it to the browser.

This file is a backend for trying the Quick Start on your machine: it serves the page from step 3 and answers that page's token request with a token it mints from credentials in its own environment, so the credentials never go to the browser. Save it as server.mjs; it needs nothing beyond Node.js.

import http from "node:http";
import { readFileSync } from "node:fs";

const TOKEN_URL =
  "https://api.sandbox.astrada.co/auth/realms/" +
  process.env.ASTRADA_ACCOUNT_ID +
  "/protocol/openid-connect/token";

http
  .createServer(async (req, res) => {
    if (req.method === "GET" && req.url === "/") {
      res.writeHead(200, { "Content-Type": "text/html" });
      return res.end(readFileSync(new URL("./index.html", import.meta.url)));
    }
    if (req.method === "GET" && req.url === "/your-backend/astrada-sandbox-token") {
      // In your own app, check the user's session here: only signed-in users get a token.
      // The token reaches every subaccount of your account, so also check that this user
      // may use the subaccountId your page opens the SDK with.
      try {
        const response = await fetch(TOKEN_URL, {
          method: "POST",
          body: new URLSearchParams({
            grant_type: "client_credentials",
            client_id: process.env.ASTRADA_CLIENT_ID,
            client_secret: process.env.ASTRADA_CLIENT_SECRET,
          }),
        });
        if (!response.ok) throw new Error("the token request answered " + response.status);
        const { access_token } = await response.json();
        res.writeHead(200, { "Content-Type": "text/plain", "Cache-Control": "no-store" });
        return res.end(access_token); // the raw token, with no "Bearer " in front
      } catch (err) {
        console.error(err.message);
        res.writeHead(502);
        return res.end();
      }
    }
    res.writeHead(404);
    res.end();
  })
  .listen(3000, "127.0.0.1"); // this machine only: the token route above has no session check

2. Prepare a test subaccount

  1. Use the subaccount from Getting Started step 3, which already has your webhook, or create one with Visa and Mastercard in its configurations as in Testing Single Card Enrollment and register a webhook on it.

  2. Set its verification policy and the ways a card can connect. This call turns the card form on, the bank link on for American Express cards only, and bulk on as a suggestion:

    PATCH /subaccounts/{subaccountId} HTTP/1.1
    Authorization: Bearer YOUR_ACCESS_TOKEN
    Content-Type: application/json
    
    {
      "verificationPolicy": {
        "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": {
          "stripeValidationLevel": "MEDIUM"
        },
        "enrollmentPolicy": {
          "cardEnrollment": true,
          "bankEnrollment": "amex-only",
          "bulkEnrollment": "suggested"
        }
      }'
    await astrada.subaccounts.update('<sandbox subaccountId>', {
      verificationPolicy: { stripeValidationLevel: 'MEDIUM' },
      enrollmentPolicy: { cardEnrollment: true, bankEnrollment: 'amex-only', bulkEnrollment: 'suggested' },
    });
    client.subaccounts.update(
        "<sandbox subaccountId>",
        {
            "verificationPolicy": {"stripeValidationLevel": "MEDIUM"},
            "enrollmentPolicy": {
                "cardEnrollment": True, "bankEnrollment": "amex-only", "bulkEnrollment": "suggested"
            },
        },
    )
    import co.astrada.client.model.CustomerEnrollmentPolicy;
    import co.astrada.client.model.SubaccountUpdateParams;
    import co.astrada.client.model.VerificationPolicy;
    import java.util.UUID;
    
    client.subaccounts().update(UUID.fromString("<sandbox subaccountId>"),
        new SubaccountUpdateParams()
            .verificationPolicy(new VerificationPolicy()
                .stripeValidationLevel(VerificationPolicy.StripeValidationLevelEnum.MEDIUM))
            .enrollmentPolicy(new CustomerEnrollmentPolicy()
                .cardEnrollment(true)
                .bankEnrollment(CustomerEnrollmentPolicy.BankEnrollmentEnum.AMEX_ONLY)
                .bulkEnrollment(CustomerEnrollmentPolicy.BulkEnrollmentEnum.SUGGESTED)));

    The TypeScript, Python and Java tabs make the same call from your server with the backend SDKs; astrada (TypeScript) and client (Python, Java) are made as in Log in.

    The subaccount's enrollmentPolicy wins field by field over what open() passes (see Which value wins), so set all three enrollmentPolicy fields here. MEDIUM is explained in Verification Risk Tiers.

  3. For the company program card only: the bulk kickoff needs network-bulk-enrollments:write or network-bulk-feeds:write on the token your backend passes to the SDK. A self sign-up sandbox client already holds network-bulk-feeds:write, along with every other scope the SDK uses. A sandbox client Astrada made for you may hold neither; without either, the bulk kickoff answers 403 and the session sends network_bulk_enrollment.forbidden (see Token scopes), so ask your Astrada contact to add one.

3. Open the SDK

Load v2 from the sandbox host and open a session. persona is required: "admin" on a card admin's page, "cardholder" on an employee page.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Astrada sandbox</title>
  </head>
  <body>
    <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",
        customerReferenceId: "<your user's id, a UUID>",
        getAccessToken: async () => {
          const response = await fetch("/your-backend/astrada-sandbox-token");
          if (!response.ok) throw new Error("the token route answered " + response.status);
          return response.text();
        },
        persona: "admin", // "cardholder" on employee pages
        onEvent: (event) => console.log(event),
        onSuccess: (result) => console.log(result.summary),
      });
    </script>
  </body>
</html>

Save this file as index.html next to server.mjs, with your subaccount ID in place of <sandbox subaccountId>. Keep both scripts inside <body>: the SDK attaches to document.body, so a call to open() that runs in <head> opens nothing and logs a TypeError. Start the server with your sandbox credentials in its environment, then open http://localhost:3000:

ASTRADA_ACCOUNT_ID="..." \
ASTRADA_CLIENT_ID="..." \
ASTRADA_CLIENT_SECRET="..." \
node server.mjs

open() resolves true once the SDK is on the page, or false when it refused the config; the console then lists every field to fix.

To try a session before you write a page, use the SDK playground. Building in React? The typed component is in Using it in React (TypeScript).

4. Try test cards

Type the number on the card number screen and press Continue (it needs 8 digits). With the policy from step 2:

Type thisWhat you seeroute in route-decided
4242 4242 4242 4242, expiry 12/34, CVC 123The card form with the first digits filled in. The card verifies without a challenge and sends card-enrolled.card-only
5555 5525 0000 1001, any future expiry, CVC 123The card form, a 3DS challenge, then success and card-enrolled.card-only
Any number starting 34 or 37The Amex bank screen, then the Plaid window (First Platypus Bank in sandbox). Sign in with user_good / pass_good and pick the credit card account. You get bank-linked, then card-enrolled with enrollmentType: "bank-feed".amex-bank
5555 5511, then ContinueThe 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-single

5555 5511 exists only to show these screens in sandbox. It is not a full test card, so a card started from it can't finish the card form: sandbox enrolls only the published test cards. If the kickoff form says "We couldn't send this from here", your SDK client lacks the scope from step 2.

On a sandbox client Astrada made for you, the browser console may show a 403 for GET /bin-lookup or GET /network-bulk-enrollments/open. Both are tolerated: your SDK client lacks cards:read or a bulk scope, and the SDK carries on without that call (Token scopes).

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. Every route, with the other two policies and an employee page: Testing.

5. Handle what comes back

  • Your page. onEvent gets each step as it happens. onSuccess fires once when the SDK closes, or onCancel if the session completed nothing. onError gets failures: branch on an error's code, never on its message. All payloads: Events and callbacks.
  • Your backend. For a card connected on the card form, your backend gets cardsubscription.created with state reqSCA once the form is submitted, then cardsubscription.updated with state active once the card is connected. Both events carry the customerReferenceId you passed to open(), so your backend knows whose card it is without trusting the browser. Register a webhook on the test subaccount to receive them, as in Testing Single Card Enrollment.

Next

📘

Already on another Astrada SDK?

On the legacy Card Enrollment SDK (cardEnrollmentSdk.js, openForm)? Its quick start is now Legacy SDK: Quick Start, and Moving to SDK v2 moves a page to v2. A page on Unified Enrollment SDK v1 moves to v2 with the steps in Moving a v1 page.


Did this page help you?