Skip to content

withmono/connect-react-native

Mono Connect React Native SDK

The Mono Connect SDK is a quick and secure way to link bank accounts to Mono from within your React Native app. Mono Connect is a drop-in framework that handles connecting a financial institution to your app (credential validation, multi-factor authentication, error handling, etc).

For accessing customer accounts and interacting with Mono's API (Identity, Transactions, Income, TransferPay) use the server-side Mono API.

Documentation

For complete information about Mono Connect, head to the docs.

Getting Started

  1. Register on the Mono website and get your public and secret keys.
  2. Set up a server to exchange tokens to access user financial data with your Mono secret key.

Installation

Using NPM

npm install @mono.co/connect-react-native

Using yarn

yarn add @mono.co/connect-react-native

Also install react-native-webview because it's a peer dependency for this package.

Additional Setup

Android

Add the camera permission to the android.permissions key in your app config (app.json, app.config.js, app.config.ts).

{
  "android": {
    "permissions": ["android.permission.CAMERA"]
  }
}

Or add the camera permission directly to your android/app/src/main/AndroidManifest.xml file.

<uses-permission android:name="android.permission.CAMERA"/>

iOS

Set a camera permission message through the ios.infoPlist key in your app config.

{
  "ios": {
    "infoPlist": {
      "NSCameraUsageDescription": "your usage description here"
    }
  }
}

If editing Info.plist as text, add:

<key>NSCameraUsageDescription</key>
<string>your usage description here</string>

Usage

Before you can open Mono Connect, you need to first create a publicKey. Your publicKey can be found in the Mono Dashboard.

Hooks

import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import { MonoProvider, useMonoConnect } from '@mono.co/connect-react-native';

const config = {
  publicKey: "YOUR_MONO_PUBLIC_KEY_HERE",
  scope: 'auth',
  data: {
    customer: {id: "mono_customer_id"}
  },
  onClose: () => alert('Widget closed'),
  onSuccess: (data) => {
    const code = data.getAuthCode()
    console.log("Access code", code)
  },
  reference: "random_string", // optional
  onEvent: (eventName, data) => { // optional
    console.log(eventName)
    console.log(data)
  }
}

function LinkAccount() {
  const { init } = useMonoConnect()

  return (
    <View style={{marginBottom: 10}}>
      <TouchableOpacity onPress={() => init()}>
        <Text style={{color: 'blue'}}>Link your bank account</Text>
      </TouchableOpacity>
    </View>
  )
}

function ReauthoriseUserAccount({accountId}) {
  const { reauthorise } = useMonoConnect()

  return (
    <View style={{marginBottom: 10}}>
      <TouchableOpacity onPress={() => reauthorise(accountId)}>
        <Text style={{color: 'blue'}}>Reauthorise user account</Text>
      </TouchableOpacity>
    </View>
  )
}

function InitiateDirectDebit() {
  const { init } = useMonoConnect();

  return (
    <View style={{marginBottom: 10}}>
      <TouchableOpacity onPress={() => init()}>
        <Text style={{color: 'blue'}}>Initiate Mono Direct debit</Text>
      </TouchableOpacity>
    </View>
  )
}

export default function App() {
  const accountId = "account_xyz";
  const payConfig = {
    scope: "payments",
    data: {
      payment_id: "txreq_HeqMWnpWVvzdpMXiB4I123456" // The `id` property returned from the Initiate Payments API response object.
    }
  }

  return (
    <MonoProvider {...config}>
      <View style={styles.container}>
        <LinkAccount />

        <MonoProvider {...{...config, ...payConfig}}>
          <InitiateDirectDebit />
        </MonoProvider>

        <ReauthoriseUserAccount accountId={accountId} />
      </View>
    </MonoProvider>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
    paddingHorizontal: 20
  },
});

Components

import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import { MonoConnectButton, MonoProvider } from '@mono.co/connect-react-native';

const config = {
  publicKey: "YOUR_MONO_PUBLIC_KEY",
  scope: "auth",
  customer: {id: "mono_customer_id"},
  onClose: () => alert('Widget closed'),
  onSuccess: (data) => console.log(data)
}

export default function App() {
  return (
    <MonoProvider {...config}>
      <View style={styles.container}>        
        <MonoConnectButton />
        <MonoConnectButton accountId="account_xyz" /> // for reauthorisation with MonoConnectButton
      </View>
    </MonoProvider>
  );
}

Re-authorizing an Account with Mono

Fetching Account ID for previously linked account

You can fetch the Account ID of a linked account from the Mono dashboard or API.

Alternatively, make an API call to the Exchange Token Endpoint with the code from a successful linking and your mono application secret key. If successful, this will return an Account ID.

Sample request:
curl --request POST \
  --url https://api.withmono.com/v2/accounts/auth \
  --header 'Content-Type: application/json' \
  --header 'accept: application/json' \
  --header 'mono-sec-key: your_secret_key' \
  --data '{"code":"string"}'

Configuration Options

publicKey

String: Required

This is your Mono public API key from the Mono dashboard.

scope

String: Required

This is the scope the widget will launch with. This can be auth, reauth, or payments

Customer

Required

// For an existing customer, their customer ID can be passed directly
const customer = { id: '611aa53041247f2801efb222' } // mono customer id

// If you don't have an existing customer, you can create one by providing their details.
// The customer will be created after the account connection is successful.
const customer = {
  name: 'Samuel Olumide',
  email: '[email protected]',
  identity: {
    type: 'bvn',
    number: '2323233239'
  },
}

const config = { 
  key: 'mono_public_key',
  scope: 'auth',
  data: { customer },
};

onSuccess

(data) => { Void }: Required

The closure is called when a user has successfully onboarded their account. It should take a single String argument containing the code that can be exchanged for an account id.

const config = {
  publicKey: "YOUR_MONO_PUBLIC_KEY_HERE",
  scope: 'auth',
  data: {
    customer: {id: "mono_customer_id"}
  },
  onSuccess: (data) => {
    const code = data.getAuthCode()
    console.log("Access code", code)
  }
}

onClose

() => { Void }: Optional

The optional closure is called when a user has specifically exited the Mono Connect flow. It does not take any arguments.

const config = {
  publicKey: "YOUR_MONO_PUBLIC_KEY_HERE",
  scope: 'auth',
  data: {
    customer: {id: "mono_customer_id"}
  },
  onSuccess: (data) => {
    const code = data.getAuthCode()
    console.log("Access code", code)
  },
  onClose: () => alert('Widget closed')
}

onEvent

(eventName, data) => { Void }: Optional

This optional closure is called when certain events in the Mono Connect flow have occurred, for example, when the user selected an institution. This enables your application to gain further insight into what is going on as the user goes through the Mono Connect flow.

See the event details below.

const config = {
  publicKey: "YOUR_MONO_PUBLIC_KEY_HERE",
  scope: 'auth',
  data: {
    customer: {id: "mono_customer_id"}
  },
  onSuccess: (data) => {
    const code = data.getAuthCode()
    console.log("Access code", code)
  },
  onEvent: (eventName, data) => {
    console.log(eventName)
    console.log(data)
  }
}

reference

String: Optional

When passing a reference to the configuration it will be passed back on all onEvent calls.

const config = {
  publicKey: "YOUR_MONO_PUBLIC_KEY_HERE",
  scope: 'auth',
  data: {
    customer: {id: "mono_customer_id"}
  },
  onSuccess: (data) => {
    const code = data.getAuthCode()
    console.log("Access code", code)
  },
  reference: "random_string"
}

Event Details

eventName: String

Event names corespond to the type of event that occurred. Possible options are in the table below.

Event Name Description
OPENED Triggered when the user opens the Connect Widget.
EXIT Triggered when the user closes the Connect Widget.
SUCCESS Triggered when the user successfully links their account and provides the code for autentication.
INSTITUTION_SELECTED Triggered when the user selects an institution.
AUTH_METHOD_SWITCHED Triggered when the user changes authentication method from internet to mobile banking, or vice versa.
SUBMIT_CREDENTIALS Triggered when the user presses Log in.
ACCOUNT_LINKED Triggered when the user successfully links their account.
ACCOUNT_SELECTED Triggered when the user selects a new account.
ERROR Triggered when the widget reports an error.

data: JSON

The data JSON returned from the onEvent callback.

reference: String // reference passed through the connect config
pageName: String // name of page the widget exited on
prevAuthMethod: String // auth method before it was last changed
authMethod: String // current auth method
mfaType: String // type of MFA the current user/bank requires
selectedAccountsCount: Number // number of accounts selected by the user
errorType: String // error thrown by widget
errorMessage: String // error message describing the error
institutionId: String // id of institution
institutionName: String // name of institution
timestamp: Number // unix timestamp of the event as a number

Examples

See more examples here.

Support

If you're having general trouble with Mono Connect React Native SDK or your Mono integration, please reach out to us at [email protected] or come chat with us on Slack. We're proud of our level of service, and we're more than happy to help you out with your integration to Mono.

Contributing

If you would like to contribute to the Mono Connect React Native SDK, please make sure to read our contributor guidelines.

License

MIT for more information.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 11