This SDK registers a global bridge between your web app and the First Iraqi Bank's native mobile app, allowing you to communicate with the native app for a seamless experience to authenticate users, pay for products and services when we include your web app in our native app.
This feature is experimental, and is not available in the latest
version yet. Please install the SDK with pre
tag instead:
This SDK is designed to be used in the browser, it accesses the global window
object to register
the bridge and communicate with the native app.
To use this functionality, you need to import the registerFIBNativeBridge
function and call it in
your JavaScript code, as soon as your web app loads.
For example if you're using React Router, you need to import it and call it in entry.client.tsx
file,
or in Vite you need to import it in the main JS/TS module inside index.html which is called an entry file.
For other frameworks, please consult their documentation on how to run code when the app loads.
This will ensure that the bridge is registered and ready to use when your code needs to communicate with the native app or the native bridge needs to send an event to your app.
If your web application could be deployed to be embedded as FIB App in App and also run independently
in the browser, you might need to check whether the current environment supports FIB Native Bridge or not.
For this purpose, you can use the window.FIBNativeBridge.isFIBBridgeAvailable
, it'll return true
if your
app is embedded as FIB App in App, otherwise it'll return false
.
When you want to send an event to the native app, you can use the window.FIBNativeBridge.sendMessage
object:
The Native app can send events to your app as well, when you're expecting such events and want to handle them, you can use the window.FIBNativeBridge.addEventListener
method:
Checkout Single Sign on to authenticate your users and use Payment API to create FIB transactions.
There are two types of errors you might want to watch out for:
When the SDK is used in an app the isn't integrated with the First Iraqi Bank's
native app, in this case the SDK will throw an UnsupportedPlatformError
error when you try to send a message
to the native app. You can catch this error and handle it gracefully, for example by showing an error message to the user.
When you try to send a message to the native app, but the message type is not one of the supported
sendable message types, or the body of the message doesn't contain necessary information, the SDK will
throw an InvalidMessageError
error.
or
Here is how a typical flow of your web app would look like when using the native app bridge:
When you want to send a message from your web app to the native app, you can use the sendMessage
method on the FIBNativeBridge
object. This method takes an object
with two properties:
type
: a string indicating the type of the message, for example "AUTHENTICATE"
or "PAYMENT"
.body
: an object containing the data you want to send to the native app, for example, it can contain a readableId
or other relevant information.AUTHENTICATE
eventYou can send this message to the native bridge after you obtained the readableId
from your backend, this will trigger the native app to authenticate
the readableId with user logged in on the Native FIB App.
Make sure you remove all -
characters from the readableId
before sending it to the native app, as the native app expects a clean ID without any dashes.
When FIB Native app successfully authenticates the readableId, it will send an AUTHENTICATED
event back to your web app.
You should add an event listener for this event to handle the authentication result.
PAYMENT
eventYou can use FIB's payment API to create a payment when a user tries to purchase a product or service in your web app.
Then, you can send a PAYMENT
message to the native app bridge, which will display the payment screen in the FIB app.
Make sure you remove all -
characters from the readableId
before sending it to the native app, as the native app expects a clean ID without any dashes.
When the payment is authorized and successfully completed, the native app will send a PAYMENT_SUCCESSFULLY_PAID
event back to your web app, which you can handle
by adding an event listener for this event.
Otherwise if the payment is canceled or failed, the native app will send a PAYMENT_FAILED
event back to your web app, which you can also handle by adding an event listener for this event.
EXIT
eventIf you want to close your web app and return to the native app, you can send an EXIT
message to the native app bridge.
This will close the web view and return to First Iraqi Bank's native mobile Home Screen, allowing the user to continue using the native app.
FIBNativeBridge
extends the EventTarget
interface, which means you can listen to events sent from the native app to your web app.
Use the window.FIBNativeBridge.addEventListener
to register events and window.FIBNativeBridge.removeEventListener
to remove them.
AUTHENTICATED
eventWhen the native app successfully authenticates the readableId, it will send an AUTHENTICATED
event back to your web app.
AUTHENTICATION_FAILED
eventWhen the native app fails to authenticate the readableId, it will send an AUTHENTICATION_FAILED
event back to your web app.
Authenticating can fail for various reasons, and you should handle this event to provide a better user experience, for example, by showing a retry screen or an error message.
PAYMENT_SUCCESSFULLY_PAID
eventWhen the native app successfully completes the payment, it will send a PAYMENT_SUCCESSFULLY_PAID
event back to your web app.
PAYMENT_FAILED
eventWhen the native app fails to complete the payment, it will send a PAYMENT_FAILED
event back to your web app.