You can import the SDK classes and types from the payment
entrypoint:
The PaymentSDK
class has a static method that gives you an instance of the SDK configured with your API credentials:
Now you can import FIB
from anywhere in your project and call its methods to create payments, check payment status or canceling them.
Checkout FIB Web Payment documentations for more info and how to obtain your credentials
authenticate(signal?: AbortSignal)
: Authenticates the client and returns an access token.createPayment(paymentInput: PaymentInput, accessToken: string, signal?: AbortSignal)
: Creates a payment.getPaymentStatus(paymentId: string, accessToken: string, signal?: AbortSignal)
: Gets the status of a payment.cancelPayment(paymentId: string, accessToken: string, signal?: AbortSignal)
: Cancels a payment.refundPayment(paymentId: string, accessToken: string, signal?: AbortSignal)
: Refunds a payment.This method sends a request to the First Iraqi Bank's identity server, giving you necessary token and other related information to authenticate your next requests like creating or canceling a payment.
access_token
is the most important part of the response, since you need to pass it to the next request otherwise it'll fail with Authentication error!
Access tokens are designed to be short-lived, expires_in
will tell you how many seconds you have until the access token expires. Make sure to fetch a new access token before your next API call if the token is expired by calling authenticate
as described above.
This method sends a request to the First Iraqi Bank's server, creating a payment based on the provided information, which are parameters to function:
payment
: an object with below possible properties:
amount
: a number, indicating the payment's amount in IQD. Must be bigger than 250
.
description
(optional): a string used as description and might be shown to the customer when they try to pay in the FIB app.
expiresIn
(optional): a Duration object indicating when the transaction expires, it must be:
refundableFor
(optional): a Duration object indicating till when the transaction can be refunded after it was paid, it must be:
redirectUri
(optional): an instance of URL
class, you can provide
a URL of your app where the user should be redirected when the payment was authorized, for example if you want FIB app to redirect user
back to some screen inside your app/website, this is used when you use Pay with FIB button in your.
statusCallbackUrl
(optional): an instance of URL
class, this must be the URL of your backend and specifically of an endpoint that can accept POST
request, as FIB backend will call this endpoint when the status of the transaction changes. Omit it if you're not interested.
extraData
(optional): an array of up to 10 objects, each with a key
and value
property, allowing you to attach additional metadata to the payment (e.g., order IDs, customer info, etc.).accessToken
: a previously fetched access token from authenticate
method.signal
(optional): an AbortSignal that can use to abort the fetch request. Checkout Canceling a request on MDN for detailed explanation.Example:
This method returns a JSON response, that is the details of transaction that you just created, represented by Payment
type:
paymentId
: a string indicating the id of the paymentreadableCode
: a 12-character alpha-numeric string used to generate the qrCode
property.qrCode
: a URL-encoded PNG image that can be shown to the user to scan and pay the amount.validUntil
: An ISO-8601-formatted date-time string, representing a moment in time when the payment expires.personalAppLink
: a string representing the personal deep link that users can visit which automatically opens the payment details in the FIB app.businessAppLink
: a string representing the personal deep link that users can visit which automatically opens the payment details in the FIB app.corporateAppLink
: a string representing the personal deep link that users can visit which automatically opens the payment details in the FIB app.Users can pay the amount either by scanning the QRCode, manually typing the readableCode
or visiting the deep-links like personalAppLink
, we recommend showing all 3 options to the user to make it more convenient for your users to fulfill the payment
Users might refresh your page, or close your application and come back, make sure you save the transaction details in your database as it contains information that can helpful to you or your customers later.
When you generated a payment, you can use this method to retrieve information about the status of the payment, this provides details on when the payment is paid, or if its canceled then why and some other useful information:
When a payment is created, you might want to cancel the payment for any reason, this can be done before he payment is fulfilled:
After a payment is fulfilled, it can be refunded depending on the refundableFor
option you created the payment with:
There are two types of errors you might want to watch out for:
When the requests return a Response
, but its not in 2xx
range, in this case
FIB backend returns an error message and some traceId, that we can inspect the
request for you if the error is not expected.
When the request fails with an Error
, which might happen for several reasons, for example
a NetworkError
or other runtime exceptions.