1.1.5 • Published 9 days ago

@mangopay/three-ds-helper v1.1.5

Weekly downloads
-
License
ISC
Repository
-
Last release
9 days ago

Three DS helper - User integration guide

Installation

The Mangopay three-ds-helper is available on npm. See @mangopay/three-ds-helper for a reference.

npm install --save @mangopay/three-ds-helper
# or
yarn add @mangopay/three-ds-helper

Key Features:

openThreeDSPopup: A function to open a pop-up window for 3DS authentication.

runThreeDSRedirectListener: A function to listen for successful 3DS authentication and handle the post-authentication redirection process.

Result and Error Handling: Handle outcomes of the 3DS process, such as success, failure, and errors.

The 3DS Helper offers both hook-based and class-based implementations, ensuring flexibility and ease of integration across different types of JavaScript or TypeScript projects.

Hook-based implementation usage

Importing

import { useThreeDSHelper } from '@mangopay/three-ds-helper';

Initialization

const { openThreeDSPopup, runThreeDSRedirectListener } = useThreeDSHelper(params);

params it is an optional object with a set of callbacks with the following type definition:

onSuccess: A callback function triggered upon a successful 3DS authentication.

onFailure: A callback function triggered when 3DS authentication fails.

onError: A callback function triggered in case of an error during the authentication process.

Opening 3DS Pop-up (Hook-based)

openThreeDSPopup(secureModeRedirectURL);

secureModeRedirectURL: The URL for 3DS authentication.

Running the 3DS Redirect Listener

runThreeDSRedirectListener();

This listener checks for 3DS parameters in the URL. If found, it manages the redirection process.

Example: Hook-based Usage

import { ThreeDSHelperResult, useThreeDSHelper } from '@mangopay/three-ds-helper';

const handle3DSResult = (result: ThreeDSHelperResult) => {
  // handle 3DS result
};

const { runThreeDSRedirectListener, openThreeDSPopup } = useThreeDSHelper({
  onSuccess: handle3DSResult,
  onFailure: handle3DSResult,
});

// On a certain user action or event
const handlePayment = () => {
  const secureModeRedirectURL = 'https://example-3ds-url.com';
  openThreeDSPopup(secureModeRedirectURL);
};

// Run the listener, e.g., on component mount
useEffect(() => {
  runThreeDSRedirectListener();
}, [runThreeDSRedirectListener]);

Class-based implementation usage

Importing

import { ThreeDSHelper } from '@mangopay/three-ds-helper';

Initialization

const threeDSHelper = new ThreeDSHelper(params);

params it is an optional object with a set of callbacks.

Opening 3DS Pop-up (Class-based)

threeDSHelper.present(secureModeRedirectURL);

secureModeRedirectURL: The URL for 3DS authentication.

Running the 3DS Redirect Listener

threeDSHelper.runThreeDSRedirectListener();

This method checks for 3DS parameters in the URL and manages the redirection process accordingly.

Example: Class-based Usage

import { ThreeDSHelper, ThreeDSHelperResult } from '@mangopay/three-ds-helper';

const handle3DSResult = (result: ThreeDSHelperResult) => {
  // handle 3DS result
};

const threeDS = new ThreeDSHelper({
  onSuccess: handle3DSResult,
  onFailure: handle3DSResult,
});

// On certain user action or event
function handlePayment() {
  const secureModeRedirectURL = 'https://example-3ds-url.com';
  threeDSHelper.present(secureModeRedirectURL);
}

// Run the 3DS Redirect Listener, e.g., on page load or after certain user actions
threeDS.runThreeDSRedirectListener();

Types

enum ThreeDSStatus {
  Succeeded = 'SUCCEEDED',
  Failed = 'FAILED',
  Error = 'ERROR',
}

enum TransactionType {
  CARD_DIRECT = 'CARD_DIRECT',
  PREAUTHORIZE = 'PREAUTHORIZE',
  CARD_VALIDATION = 'CARD_VALIDATION',
}

interface ThreeDSHelperResult {
  Id: string;
  Status: ThreeDSStatus;
  Type: TransactionType;
}

interface TypedError {
  Status?: string;
  ResultCode?: string;
  ResultMessage?: string;
}

interface ThreeDSHelperParams {
  onSuccess?: (result: ThreeDSHelperResult) => void;
  onFailure?: (result: ThreeDSHelperResult) => void;
  onError?: (error: TypedError) => void;
}

Events

The package listens for message events from the authentication iframe. Recognized events trigger the handleThreeDSHelper function, which in turn invokes the appropriate callback (onSuccess, onFailure, onError) based on the result.

1.1.6-alpha.1

9 days ago

1.1.6-alpha.2

9 days ago

1.1.6-alpha.0

10 days ago

1.1.5

1 month ago

1.1.5-beta.1

1 month ago

1.1.5-beta.0

1 month ago

1.1.4

1 month ago

1.1.4-beta.0

2 months ago

1.1.3

2 months ago

1.1.2

2 months ago

1.1.2-beta.1

2 months ago

1.1.2-beta.0

2 months ago

1.1.1

2 months ago

1.1.1-beta.0

2 months ago

1.1.0

2 months ago

1.0.18-alpha.5

2 months ago

1.0.17

3 months ago

1.0.16

3 months ago

1.0.15-alpha.1

3 months ago

1.0.15-alpha.2

3 months ago

1.0.15

3 months ago

1.0.14

3 months ago

1.0.13

5 months ago

1.0.12

6 months ago

1.0.11

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago