Skip to content

Finix.ThreeDSecure

Raises a 3D Secure (3DS) challenge inside your checkout page and reports the outcome to your front end.

Finix.js wraps the 3DS vendor SDK end to end. You don't install a vendor package, you don't allowlist a vendor script in your Content Security Policy, and the buyer never sees a vendor URL. The challenge renders in a full-screen transparent iframe that Finix.js creates and removes, so the buyer stays on your checkout page the whole time.

For the protocol, session states, and liability shift, see 3D Secure. For a walkthrough of a complete checkout, see 3D Secure using Finix.js.

Creating the session

Every challenge runs against a 3D Secure Session, and your server creates it by calling POST /3d_secure_sessions. Finix.js consumes the session you hand it. It never creates one.

Keep credentials and trusted values on your server

Create the session through an authenticated backend endpoint; never expose Finix API credentials in browser code. Derive and validate trusted values such as the merchant and amount on the server, and rate-limit the endpoint to prevent abuse.

Choosing an entry point

Two entry points

Entry pointUse this when
Finix.ThreeDSecure()The card is already on file, or you're PCI compliant and collect card details yourself. You decide when the challenge runs.
The ThreeDSecure form optionYou already tokenize with Finix.PaymentForm(). Finix.js calls your session endpoint, raises the challenge, retries, and manages the submit button for you.

The form option is the shorter integration of the two. Reach for the class when you aren't using the payment form.

Statuses and callbacks

Statuses

Both entry points report the same three statuses.

StatusMeaning
initializedFinix.js has initialized the challenge component
succeededAuthentication finished. Submit the payment and reference the session ID
failedAuthentication did not finish. Read error.code for the cause

Callback payload

Every 3DS callback receives one object.

PropertyTypeDescription
sessionobject | nullThe 3D Secure Session. null only on the payment form path, when createSession fails or returns an unusable session
statusstringinitialized, succeeded, or failed
errorobjectPresent only when status is failed

The error object has two properties:

  • code - A Finix.js error code. See Error codes.
  • reason - A human-readable description of the failure, suitable for logging.

These codes are produced by Finix.js and the 3DS vendor. They are a separate enum from the failure_code field on the 3D Secure Session itself, so don't map one onto the other.

The ThreeDSecure class

Function signature

Finix.ThreeDSecure(environment)
ParameterTypeRequiredDescription
environmentstringYesFinix environment (sandbox or prod)

Returns a ThreeDSecure instance. Both of its methods return that same instance, so calls chain.

environment

Selects the environment to authenticate against, and the vendor credentials Finix.js uses internally.

ValueEnvironment
"sandbox"Sandbox
"prod"Production

These are the same environment strings the rest of Finix.js accepts. Use sandbox with https://finix.sandbox-payments-api.com and prod with https://finix.payments-api.com.

validate()

Raises the challenge for a session.

threeDS.validate(threeDSecureSession, callback)
ParameterTypeRequiredDescription
threeDSecureSessionobjectYesThe entire response body from your server's POST /3d_secure_sessions call
callbackfunction({ session, status, error })NoInline form of on(). Runs on every status change

Pass the response object through whole rather than picking fields out of it. Returns the ThreeDSecure instance.

on()

Registers a listener for one status.

threeDS.on(status, callback)
ParameterTypeRequiredDescription
statusstringYesThe status to listen for: initialized, succeeded, or failed
callbackfunction({ session, status, error })YesRuns when the challenge reaches that status

Call on() once for each status you want to handle. Returns the ThreeDSecure instance.

Usage patterns

The class supports three equivalent styles. Use whichever fits your checkout code.

  • Separate calls - Hold the instance in a variable, then call validate() and on() against it.
  • Chained - Chain on() onto the return value of validate().
  • Inline callback - Pass a single callback to validate() and branch on status.

The ThreeDSecure form option

ThreeDSecure

An optional object in the options you pass to Finix.PaymentForm(). Providing it turns on 3D Secure for the form: Finix.js tokenizes the card, calls your session endpoint, raises the challenge, and reports both results to onSubmit.

PropertyTypeRequiredDescription
createSessionasync function(token)YesCalls your backend and resolves with a 3D Secure Session
onStatusChangefunction({ session, status, error })NoRuns on every status change

createSession

A hook to your own session endpoint. Finix.js calls it once the card is tokenized, and expects it to resolve with the response body from POST /3d_secure_sessions.

createSession: async (token) => ThreeDSecureSession
  • token - The token Finix.js created for the card details in the form.

Handing the call to Finix.js is what makes this path shorter than the class. Because Finix.js owns the timing, it calls your endpoint at the right moment, asks for a fresh session when a buyer cancels or a challenge fails, and disables and re-enables the submit button around the challenge. None of that is automatic when you drive the class yourself.

If createSession throws, rejects, or times out, the form reports SESSION_API_FAILED. If it resolves with something unusable, the form reports SESSION_API_MALFORMED. In both cases session is null.

onStatusChange

Optional. Finix.js raises the challenge, retries, and manages the button without it, so use onStatusChange for your own analytics or buyer-facing messaging.

onStatusChange: ({ session, status, error }) => void

It receives the same payload as the on() callbacks. The same callback is also documented on the Callbacks page alongside onLoad, onUpdate, and onSubmit.

Custom submit buttons

The option works with the submit button the form renders and with your own button calling form.submit(). Finix.js manages the enabled state of the form's own button. With a custom button, keep using onUpdate and hasErrors as you do today. See Form Instance.

Submit response

threeDSecure

When the ThreeDSecure option is set, the response passed to onSubmit carries a threeDSecure key alongside data.

KeyDescription
dataThe token. See Token Response
threeDSecureThe authentication result: { session, status, error }
Read status, not session.state

threeDSecure.session.state still reads PENDING when status is succeeded. The API state only advances once Finix processes the authentication result from the vendor, which happens after your onSubmit runs. Decide whether to charge from threeDSecure.status, then submit the payment referencing threeDSecure.session.id.

Error codes

error.code values

CodeMeaning
CARD_NOT_ENROLLEDThe session came back FAILED. The card can't be authenticated. This isn't a decline, so whether you charge it anyway is a policy decision
CHALLENGE_FAILEDThe issuer declined the authentication. No further detail is available
USER_CANCELLEDThe buyer closed the overlay
MERCHANT_CANCELLEDThe challenge was cancelled programmatically
CHALLENGE_TIMEOUTThe challenge page didn't load within 20 seconds. Retryable
CHALLENGE_LOAD_FAILEDThe challenge component couldn't be initialized. Retryable
SESSION_API_FAILEDcreateSession threw or timed out. Payment form only, and session is null
SESSION_API_MALFORMEDcreateSession returned an unusable session. Payment form only, and session is null
ERRORAn unclassified vendor failure. The vendor's own message is logged to the browser console

Retrying CHALLENGE_TIMEOUT or CHALLENGE_LOAD_FAILED means creating a new session first. Sessions expire five minutes after they're created, and each one covers a single payment. On the payment form path, Finix.js calls createSession again for you.

3D Secure Session object

Session shape

The session property in every callback is the object your backend returned from POST /3d_secure_sessions, unchanged.

{
  "id": "3d_secure_session_f3fG3Zj8K958MTP5vpXAXX",
  "created_at": "2026-08-13T16:37:59.211335Z",
  "updated_at": "2026-08-13T16:37:59.469140Z",
  "3d_secure_authentication": null,
  "3d_secure_authentication_session_id": "tds_visa_0367b8b7ebd8",
  "3d_secure_authentication_url": null,
  "3d_secure_version": null,
  "amount": 1000,
  "currency": "USD",
  "authentication_type": null,
  "failure_code": null,
  "failure_message": null,
  "merchant_id": "MUmUNeW5N9Yw8RkLhLcGghy4",
  "payment_instrument_id": null,
  "redirect_url": null,
  "state": "PENDING",
  "tags": {}
}

Finix.js uses camelCase for its own options and callbacks, but this object comes straight from the Finix API and keeps its snake_case field names. That mix is expected.

// 1. Standalone class — you already have a session and control the timing
Finix.ThreeDSecure("sandbox")
  .validate(threeDSecureSession)
  .on("succeeded", ({ session }) => {
    // Submit the payment with session.id
  });

// 2. Payment form option — Finix.js calls your endpoint and runs the challenge
Finix.PaymentForm("payment-form", "sandbox", "APgPDQrLD52TYvqazjHJJchM", {
  ThreeDSecure: {
    createSession: async (token) => createSessionOnYourBackend(token),
  },
  onSubmit: function (error, response) { /* ... */ },
});

// Returns a ThreeDSecure instance
const threeDS = Finix.ThreeDSecure("sandbox");

Finix.ThreeDSecure("qa");      // QA
Finix.ThreeDSecure("sandbox"); // Sandbox
Finix.ThreeDSecure("prod");    // Production

// Your backend creates the session and returns the response body untouched
const threeDSecureSession = await fetch("/your/backend/3d-secure-sessions", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ paymentInstrumentId: "PI6iQcTtJNCS8GZAVKYi5Ueb", amount: 1000, currency: "USD" }),
}).then((response) => response.json());

const threeDS = Finix.ThreeDSecure("sandbox");

// Pass the whole session object, not just the id
threeDS.validate(threeDSecureSession);

const threeDS = Finix.ThreeDSecure("sandbox");
threeDS.validate(threeDSecureSession);

threeDS.on("initialized", ({ session }) => {
  console.log("Challenge initialized for", session.id);
});

threeDS.on("succeeded", ({ session }) => {
  // Submit the payment with session.id
});

threeDS.on("failed", ({ error }) => {
  console.error(error.code, error.reason);
});

Finix.ThreeDSecure("sandbox").validate(threeDSecureSession, ({ session, status, error }) => {
  switch (status) {
    case "initialized":
      // The challenge component is initialized
      break;
    case "succeeded":
      // Authentication finished — submit the payment with session.id
      break;
    case "failed":
      // Authentication did not finish — read error.code
      console.error(error.code, error.reason);
      break;
  }
});

threeDS.on("failed", ({ session, status, error }) => {
  // session - the 3D Secure Session passed to validate()
  // status  - "initialized" | "succeeded" | "failed"
  // error   - { code, reason }, present only when status is "failed"
  console.error(error.code, error.reason);
});

// Separate calls
const threeDS = Finix.ThreeDSecure("sandbox");
threeDS.validate(threeDSecureSession);
threeDS.on("succeeded", ({ session }) => {
  // Submit the payment with session.id
});

// Chained
Finix.ThreeDSecure("sandbox")
  .validate(threeDSecureSession)
  .on("succeeded", ({ session }) => {
    // Submit the payment with session.id
  });

// Inline callback
Finix.ThreeDSecure("sandbox").validate(threeDSecureSession, ({ session, status, error }) => {
  if (status === "succeeded") {
    // Submit the payment with session.id
  }
});

Finix.PaymentForm("payment-form", "sandbox", "APgPDQrLD52TYvqazjHJJchM", {
  ThreeDSecure: {
    createSession: async (token) => createSessionOnYourBackend(token), // required
    onStatusChange: ({ session, status, error }) => {                  // optional
      console.log("3D Secure status:", status);
    },
  },
  onSubmit: function (error, response) { /* ... */ },
});

Finix.PaymentForm("payment-form", "sandbox", "APgPDQrLD52TYvqazjHJJchM", {
  ThreeDSecure: {
    // Finix.js calls this once the card is tokenized.
    // Resolve with the response body from POST /3d_secure_sessions.
    createSession: async (token) => {
      const response = await fetch("/your/backend/3d-secure-sessions", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ token: token, amount: 1000, currency: "USD" }),
      });
      return response.json();
    },
  },
  onSubmit: function (error, response) { /* ... */ },
});

Finix.PaymentForm("payment-form", "sandbox", "APgPDQrLD52TYvqazjHJJchM", {
  ThreeDSecure: {
    createSession: async (token) => createSessionOnYourBackend(token),
    onStatusChange: ({ session, status, error }) => {
      // Optional — use it for your own analytics or messaging
      analytics.track("3ds_status", { status: status });

      if (status === "failed") {
        showMessage(error.reason);
      }
    },
  },
  onSubmit: function (error, response) { /* ... */ },
});

const form = Finix.PaymentForm("payment-form", "sandbox", "APgPDQrLD52TYvqazjHJJchM", {
  paymentMethods: ["card"],
  ThreeDSecure: {
    createSession: async (token) => createSessionOnYourBackend(token),
  },
});

document.getElementById("pay-btn").addEventListener("click", function () {
  form.submit(function (error, response) {
    if (error) {
      console.error("Tokenization failed:", error);
      return;
    }
    const { data, threeDSecure } = response;
    if (threeDSecure.status === "succeeded") {
      // Charge data.id and reference threeDSecure.session.id
    }
  });
});

Finix.PaymentForm("payment-form", "sandbox", "APgPDQrLD52TYvqazjHJJchM", {
  paymentMethods: ["card"],
  ThreeDSecure: {
    createSession: async (token) => createSessionOnYourBackend(token),
  },
  onSubmit: function (error, response) {
    if (error) {
      console.error("Tokenization failed:", error);
      return;
    }

    const tokenData = response.data || {};
    const threeDSecure = response.threeDSecure || {};

    // threeDSecure.session.state still reads "PENDING" here, even on success.
    // Branch on threeDSecure.status instead.
    if (threeDSecure.status === "succeeded") {
      fetch("/your/backend", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
          token: tokenData.id,
          threeDSecureSessionId: threeDSecure.session.id,
        }),
      });
    }
  },
});

threeDS.on("failed", ({ error }) => {
  switch (error.code) {
    case "USER_CANCELLED":
      // The buyer closed the overlay — offer to try again
      break;
    case "CHALLENGE_TIMEOUT":
    case "CHALLENGE_LOAD_FAILED":
      // Retryable — create a new session and call validate() again
      break;
    case "CARD_NOT_ENROLLED":
    case "CHALLENGE_FAILED":
      // This card will not authenticate — charging anyway is your policy call
      break;
    default:
      console.error(error.code, error.reason);
  }
});

// The object your backend returns from POST /3d_secure_sessions,
// and the object Finix.js hands back as `session`:
// {
//   "id": "3d_secure_session_f3fG3Zj8K958MTP5vpXAXX",
//   "created_at": "2026-08-13T16:37:59.211335Z",
//   "updated_at": "2026-08-13T16:37:59.469140Z",
//   "3d_secure_authentication": null,
//   "3d_secure_authentication_session_id": "tds_visa_0367b8b7ebd8",
//   "3d_secure_authentication_url": null,
//   "3d_secure_version": null,
//   "amount": 1000,
//   "currency": "USD",
//   "authentication_type": null,
//   "failure_code": null,
//   "failure_message": null,
//   "merchant_id": "MUmUNeW5N9Yw8RkLhLcGghy4",
//   "payment_instrument_id": null,
//   "redirect_url": null,
//   "state": "PENDING",
//   "tags": {}
// }