JS library for implementing Okra. The okrajs-npm module can be found here.
All accounts connected to Okra are done via the widget (Okrajs). The API only allows you access to accounts that have been connected.
Using npm:
$ npm install npm-okrajs
Using yarn:
$ yarn add npm-okrajs
Using CDN:
<script src="https://cdn.okra.ng/v1/bundle.js"></script>
For JS frameworks import it and use
import Okra from 'npm-okrajs'
For others, just use
Okra.buildWithOptions({name: 'Peter the Builder',env: 'production-sandbox',key: '', //Your key from the Okra dashboardtoken: '', //your token from the okra dashboardonSuccess: function(data){console.log('options success', data)},onClose: function(){console.log('options close')}})​Okra.buildWithShortUrl({short_url: '', //Your short url from the link builder})
Name | Type | Required | Default Value | Description |
|
|
| ​ | Your public key from your Okra Dashboard. |
|
|
| ​ | Your token from your Okra Dashboard. |
|
|
|
| production(live)/production-sandbox (test) |
|
|
|
| The Okra products you want to use with the widget. |
|
|
|
| ​ |
|
|
|
| Name on the widget |
|
|
|
| Theme on the widget |
|
|
|
| Statement length |
|
|
| ​ | Filter for widget |
|
|
|
| Corporate or Individual account |
|
|
| ​ | Instruction to connect account |
|
|
| ​ | ​ |
|
|
| ​ | Widget Success Message |
|
|
| ​ | Widget Failed Message |
|
|
| ​ | ​ |
|
|
| ​ | Specify a URL to your success page. Okra fires the redirect when the process is completed. |
|
|
|
| Wallet to bill |
|
|
|
| Expiry date of widget |
|
|
| ​ | You can pass a object custom values eg id |
|
|
| ​ | Action to perform after widget is successful |
|
|
| ​ | Action to perform if widget is closed |
|
|
| ​ | Action to perform on widget Error |
|
|
| ​ | Action to perform before widget close |
|
|
|
| Statement length |
|
|
|
| ISO 3166 code of your country of operation |
|
|
|
| Whether to show |
|
|
|
| Hide exit button while connecting their account(s) |
|
|
|
| Request for guarantors from your client |
|
|
|
| Message to display when requesting for client's guarantor |
|
|
|
| number of guarantors to request from client |
|
|
| This Client | Your Company Name |
Name | Type | Required | Description |
|
| true | Your generated url from link builder. |
|
| false | Action to perform after widget is successful |
|
| false | Action to perform if widget is closed |
This section shows how you can listen for callback whenever a record is created.
You can save your default callback URL in your keys in the dashboard.
In your Node application, create a route called {apiUrl}/callback
in your PHP application, you can create a page to listen to callbacks
router.post('/callback', (req, res) => {switch (req.body.method) {case 'AUTH'://DO SOMETHINGbreak;case 'BALANCE'://DO SOMETHINGbreak;case 'TRANSACTIONS'://DO SOMETHINGbreak;case 'IDENTITY'://DO SOMETHINGbreak;case 'INCOME'://DO SOMETHINGbreak;case 'DIRECT-DEBIT'://DO SOMETHINGbreak;default:break;}})
$body = @file_get_contents('php://input');$data = json_decode($body, true);switch ($data['method']) {case 'AUTH'://DO SOMETHING HERE$fp = file_put_contents('auth.json', print_r($data,true) );break;case 'IDENTITY'://DO SOMETHING HERE$fp = file_put_contents('identity.json', print_r($data,true) );break;case 'BALANCE'://DO SOMETHING HERE$fp = file_put_contents('balance.json', print_r($data,true) );break;case 'TRANSACTIONS'://DO SOMETHING HERE$fp = file_put_contents('transactions.json', print_r($data,true) );break;case 'INCOME'://DO SOMETHING HERE$fp = file_put_contents('income.json', print_r($data,true) );break;case 'DIRECT-DEBIT':$fp = file_put_contents('direct-debit.json', print_r($data,true) );break;default:break;}
The onSuccess callback should take two arguments, the record_id and a metadata object. The metadata object provides the following information:
Parameter | Description |
record_id
| A unique identifier associated with a user's actions and events through the OkraJS flow. Include this identifier when opening a support ticket for faster turnaround. |
bank
| An object with two properties:
- |
accounts
| A list of objects with the following properties:
- |
Checkout the Account section for more detailed documentation. To collect accounts data, you must enable the Select Account view via the Okra Dashboard.
okra.create({...,onSuccess: function(record_id, metadata) {​},})`
// curl // n/a //
The onClose callback is called when a user exits the OkraJS flow. It takes two arguments, a nullable error object and a metadata object.
Parameter | Description |
error
| A nullable object that contains the error type, code, and message of the error that was last encountered by the user. If no error was encountered, error will be null. |
metatdeta
| An object containing information about the last error encountered by the user (if any), bank selected by the user, and the most recent API record ID, and the OkraJS session ID. |
okra.create({...,onClose: function(metadata, error) {​},})`
// curl // n/a //
{"display_message": "The credentials were ...","error_code": "INVALID_CREDENTIALS","error_message": "The credentials were ...","error_type": "RECORD_ERROR",}
{"record_session_id": String,"record_id": String,"bank": {"name": String,"bank_id": String},"status": String}
The onFailure callback is called when an error occurs in the OkraJS flow. It takes two arguments, a nullable error object and a metadata object.
Parameter | Description |
error
| A nullable object that contains the error type, code, and message of the error that was last encountered by the user. If no error was encountered, error will be null. |
metatdeta
| An object containing information about the last error encountered by the user (if any), bank selected by the user, and the most recent API record ID, and the OkraJS session ID. |
okra.create({...,onFailure: function(error, metadata) {​},})`
// curl // n/a //
{"display_message": "The credentials were ...","error_code": "INVALID_CREDENTIALS","error_message": "The credentials were ...","error_type": "RECORD_ERROR",}
{"record_session_id": String,"record_id": String,"bank": {"name": String,"bank_id": String},"status": String}