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 token that you created using the Create Token API in the previous step
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 with their account.
This is your callback function method, which will be triggered for various events throughout the user journey within the Benji Connect flow.
let sdk = null;
function initializeSDK(token) {
sdk = new ConnectSDK({
token: token,
onSuccess: (token, metadata) => {
console.log('Connect successful', token, metadata);
// Handle success event in your code, such as displaying a sucess message on your site and storing the returned token
},
onExit: () => {
console.log('Connect flow exited');
// Handle close Connect flow, such as log in your systen or disokay a message to the user
},
onEvent: (event, metadata) => {
console.log('Event received:', event);
//Listen and react to various events in the user flow.
}
});
}