Skip to main content

Integrate into Website

bankHub provides script-js to support opening account link links.

Introduction

This is a library used to support opening Pop ups and redirecting account links on your website.

CSP Directive

If you are using Content Security Policy (CSP), use the following commands to allow Link traffic:

default-src https://cdn.bankhub.vn/
script-src https://cdn.bankhub.dev/link/v1/link-initialize.js
frame-src https://dev.link.bankhub.dev
connect-src https://bankhub.dev/

Installation

Declare the bankHub initialization command on each page of your website. It should always be downloaded directly from https://cdn.bankhub.dev, rather than being included in an installation package or self-hosted. Unlike other bankHub SDKs, the JavaScript Web SDK is not versioned; cdn.bankhub.vn will automatically provide the latest SDK available.

<script src="https://cdn.bankhub.dev/link/v1/link-initialize.js"></script>

Initialization

const bankHubLinkConfigs = {
redirectUri: redirect_uri, // required
iframe: true, // required
grantToken: grantToken, // required
feature: productType,
fiServiceType: accountType,
onSuccess: (publicToken, state) => {},
onExit: () => {},
};

Description of the components of bankHubLinkConfigs:

AttributesTypeDescription
redirectUristringThis is the page link used to call the account link
iframebooleanTrue will open with iframe (Popup), False will redirect to bankHub website
grantTokenstringGrant Token
featuretransaction or account or kyc or qrpayProduct type
fiServiceTypeENTERPRISE or PERSONAL or ALLAccount classification
onSuccesscallbackFn: (publicToken, state) => voidExecuted after successfully linking accounts using iframe (iframe = true), publicToken and state of type string
onExitcallbackFn: () => voidExecuted after successfully linking accounts using iframe (iframe = true)

Usage

For iframe = True

At this time, a popup will appear and ask the user to select a bank and log in to link.

  • onSuccess will be called when the user binds successfully.
  • onExit will be called when the user exits the popup.
const bankHubLinkConfigs = {
redirectUri: redirect_uri,
iframe: true,
grantToken: grantToken,
feature: productType,
fiServiceType: accountType,
onSuccess: (publicToken, state) => {},
onExit: () => {},
};

const { open } = BankHub.useBankHubLink(linkBankConfigs);

open();

For iframe = False

The website will now redirect to bankHub's website to link the account. At this point, the user must manually handle the event when the link is successful or exits the bankHub website.

const bankHubLinkConfigs = {
redirectUri: redirect_uri,
iframe: false,
grantToken: grantToken,
feature: productType,
fiServiceType: accountType,
};

const { open } = BankHub.useBankHubLink(linkBankConfigs);

open();
tip

For iframe = False, onSuccess and onExit cannot be used.

After the user successfully links the account, bankHub will call redirectUri again with the publicToken parameter. At this point, the user needs to process the publicToken from queryString and perform the onSuccess function as follows:

const urlParams = new URLSearchParams(window.location.search);
const publicToken = urlParams.get('publicToken');

if (publicToken) {
// Implements the user-defined handleOnSuccess function
handleOnSuccess(publicToken);
}