Installing the SDK
The Benji Connect SDK can be added to your application by including the SDK script in your html headers.
<script src="https://d1ochlq3jv1msw.cloudfront.net/connect/sdk/connect-sdk.js"></script>
or by installing the package via npm
npm install @benji-money/connect-sdk
or by installing the package via yarn
yarn add @benji-money/connect-sdk
or by installing the package via pnpm
pnpm add @benji-money/connect-sdk
Note that you will be able to acces sthe above packages/scripts once authorized to use the Benji SDKs. Contact your account manager for additional info
Initializing the SDK
The SDK is initialized with the following parameters :
This is the environment to be used in the connect flow (‘development’ | ‘sandbox’ | ‘production’).
This is your callback function method, which will be triggered when a member has succesfully connected with a partner loyalty program.
This is your callback function method, which will be triggered when a member has closed the Benji Connect Modal. Note that this function can be whether the onSuccess callback has been called or not.
This is your callback function method, which will be triggered when a member encountered an error while connecting their account.
This is your callback function method, which will be triggered for various events throughout the user journey within the Benji Connect flow.
import { ConnectSDK } from '@benji-money/connect-sdk';
let sdk = null;
function initializeSDK(token) {
sdk = new ConnectSDK({
// Benji Connect Environment
environment: 'sandbox', // | 'development' | 'production',
// Connect Token
token: token,
// onSuccess callback (token: string, metadata: BenjiConnectOnSuccessMetadata)
onSuccess: (_token, _metadata) => {
console.log('Benji Connect successful');
// Handle success event in your code, such as displaying a sucess message on your site and storing the returned token
},
// onError callback (error: Error, error_id: string, metadata: BenjiConnectMetadata)
onError: (_error, _error_id, _metadata) => {
console.log('Benji Connect onError');
// Handle error event in your code, such as displaying an error message or prompting the user to try again
},
// onExit callback (metadata: BenjiConnectOnExitMetadata)
onExit: (_metadata) => {
console.log('Benji Connect onExit');
// Handle close Connect flow, such as log in your system or display a message to the user
},
// onEvent callback (type: BenjiConnectEventType, metadata: BenjiConnectMetadata)
onEvent: (type, _metadata) => {
console.log('Benji Connect onEvent:', type);
// Listen and react to various events in the user flow
}
});
}