Events & Callbacks

What SDK v2 passes to onSuccess, onError and onCancel, and every onEvent type with its fields, when it fires and what changed from v1.

Events and callbacks

onCancel and onError are called the same way as in SDK v1. onSuccess gets the v1 payload:

  • without bulkFeeds and summary.feedsCreated (v2 registers no feed);
  • plus bulkReferences;
  • plus next: "invite-team" whenever the session ends from Invite your team (the value closed.next carries, so a page that only handles onSuccess learns it too);
  • plus teamLink only when the admin made a team link there.

Everything else reaches onEvent only. The names below are the type values of the SdkEvent union in the types package.

EventIn v2
card-enrolled, bank-linked, errorUnchanged. error gains fixed code values for the failures the SDK finds itself (invalid-config, access_token.failed, subaccount.not_found, subaccount.forbidden, subaccount.read_failed, enrollment_policy.empty, bank_link.create_failed, bank_link.timed_out, bank_link.wrong_institution, bank_account.not_found, network_bulk_enrollment.forbidden, network_bulk_confirmation.forbidden, resume-unavailable); the card form keeps its own codes. Branch on code, never on message.
route-decidedNew. { route, network?, persona, bin6, policy?, provenance?, reason?, singleDecisionReason? }, once per Continue on the card number screen (on an employee page that opens on the card form, once the 8th digit is typed there), and once more with the new route when a later screen re-routes the card (below the table). Only the card's first 6 digits are reported.
company-connection-neededNew. { network, bin6 }, when an employee page gets an Amex card that its bank link can't take (below the table). The employee sees "Your company connects this card".
bulk-confirmation-requestedNew. The admin asked Astrada to confirm a likely bulk program: requestId, confirmationId, subaccountId, network, the issuer details (issuerName, issuerCountry, cardType, each omitted when unknown), companyLegalName, cardAdminEmail, and customerReferenceId when you set one.
bin-disputedNew. { bin6, route }, when the admin presses This doesn't look right on the program screen. route is the one the screen showed.
bulk-enrollment-requestedAdds cardCount, which is absent when the admin leaves the kickoff form's card count empty (the count is optional). It no longer needs bulkFlow: "kickoff".
bulk-reference-enteredNew. The end of a resume session: { networkBulkEnrollmentId, subaccountId, network, networkReference, feedType?, expectedCardCount? }. The SDK registers nothing; your backend sends these fields to POST /network-bulk-feeds with your API client (feedType goes as type).
feed-createdRemoved. The SDK creates no feed, so read bulk-reference-entered.
closedAdds next: "invite-team" whenever the session ends from Invite your team, the bulkReferences map, and summary.confirmationsRequested and summary.referencesEntered. It adds teamLink: { id, url, expiresAt } only when the admin made a team link this session. onSuccess carries the same next and teamLink.
cancelledAdds lastScreen, for example "card-entry" or "program". An employee page that opens on the card form reports "card-link" when it is closed before a card is typed.

More on route-decided, company-connection-needed, bulk-confirmation-requested, bin-disputed and bulk-enrollment-requested:

  • route-decided: a later screen re-routes the card when
    • the bank link refuses the card's country, or refuses the link with 403 BANK_ENROLLMENT_DISABLED while Astrada has locked the account's bank link value;
    • a different card is typed over the routed one on the card form;
    • the admin presses This doesn't look right on the program screen (this one follows bin-disputed);
    • the admin presses This is a small business card on an American Express program screen, which sends the card to its refusal;
    • or the server refuses a Visa on single enrollment.
  • route-decided fields: policy and provenance come on the session's first one and again when they change; reason ("policy" or "card") comes on the not-eligible routes, and singleDecisionReason is described below the table.
  • company-connection-needed: the bank link can't take the Amex card when bank linking is off for Amex, the card is debit or prepaid, or the bank link refused the card (its country, or the account's locked bank link value).
  • bulk-confirmation-requested: when the program already has an open request, the event adds alreadyRequested: true and confirmationId is that request's.
  • bin-disputed: the SDK re-routes the same card as not bulk (the bank step, the card form or "This card can't be connected here"), and a route-decided with the new route follows this event.
  • bulk-enrollment-requested: when the program already has an open kickoff, the event carries that kickoff's enrollmentId, alreadyRequested: true and its state, without outreach, companyLegalName, cardAdminEmail or the card count. The SDK sends it the same way whether it finds the kickoff before the form (when the card is looked up) or when the form is sent.

On route-decided, singleDecisionReason is the reason Astrada gave for refusing the card single enrollment on the subaccount:

  • singleDecision.reason from POST /enrollment-methods, for example "card-type" or "bank-enrollment-required";
  • or "bank-enrollment-required" when POST /card-subscriptions refuses a Visa from the card form with reasonCode: "card_subscription.bank_enrollment_required", which re-routes the card.

It comes only when Astrada refused with a reason, and again when the same card is routed again. Expect "coverage" on many cards that can't enroll one at a time, such as an American Express card. It is a plain string: new values can appear without an SDK release.

A card whose program couldn't be graded gets one of the ordinary routes: the route type still lists unchecked-single, unchecked-bank and unchecked-confirm-only, marked deprecated, but they are never sent.

A confirm request and an entered reference count as completed actions, so onSuccess can fire with no card, bank account or kickoff: read summary. If your code switches over every event type, add the new ones and drop feed-created:

onEvent: (event) => {
  switch (event.type) {
    case "route-decided": // once per Continue (or at an employee card form's 8th digit), and again if a later screen re-routes the card
      console.log(event.route, event.persona, event.bin6);
      break;
    case "bulk-confirmation-requested": // Astrada emails event.cardAdminEmail once it has checked
      break;
    case "company-connection-needed": // an employee's Amex: let the finance admin know
      break;
    case "closed":
      if (event.next === "invite-team") openYourInvitePage();
      break;
  }
};

Did this page help you?