npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mangopay/three-ds-helper

v1.2.1

Published

Mangopay SDK - 3DS Helper

Downloads

187

Readme

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.