Test Brick APIs with cURL
In this section, You will learn to use Brick APIs via Curl method.
Brick is currently offering two environments:
- Sandbox - The sandbox environment should use for development and testing purposes.
- Production - The production environment should be used for connection with real accounts.
Please feel free to register yourself if haven't from here.
API Environment
In the below examples, we will use the sandbox environment. Change the base URL to https://api.onebrick.io in each example to switch to production.
Our new version of APIs(v2) is callback-based APIs, So if you have not set up a callback URL till now, Please set it from brick dashboard.
Step 1: Generate a JWT bearer token (Public access token)
Use public token API with sandbox API keys with client_id & client_secret to get a JWT(JSON Web Token). This JWT or what we call a public access token can be used to launch the Brick widget and access the institution list.
curl --request GET \
--url https://sandbox.onebrick.io/v2/payments/auth/token \
--header 'Accept: application/json' \
--header 'password: password' \
--header 'username: username'
This API gives give you a JWT/public access token that is only valid for use One time, After using it once, public_access_token for payments will expire and you have to regenerate this.
{
"status": 200,
"error": null,
"metaData": {
"source": "API",
"entity": "Payment"
},
"data": {
"message": "Access token is valid for 5 minutes and can use one time only",
"accessToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxODQ3IiwiY29sb3VyIjoiIzMzMzMzMyIsInJvbGUiOlsiVVNFUiJdLCJuYW1lIjoiQnJpY2siLCJpc3MiOiJCcmljayIsImV4cCI6MTY1NzA4ODgzOSwiaWF0IjoxNjU3MDg4NTM5LCJqdGkiOiIyZTZmZTIwOS0yN2ZiLTQ0MjctOTI5Mi1lNThiYzMyMDUyMzkiLCJ0cyI6MTY1NzA4ODUzOTg1N30.gexikMhPVvS8z2j9muHhSAZb_TrkUAn4BDWIvOJLZDE",
"issuedAt": "2022-07-06T13:22:19.857147",
"expiresAt": "2022-07-06T13:27:19.857147"
}
}
Step 2: Account verification
This endpoint helps you to verify the bank account for safe and secure transactions. Before you request a fund transfer, make sure to check that the receiving Financial Institution account belongs to the person you intend to send to!
You can use JWT / public access token that was generated in Step 1 to validate the account for the recipient.
curl --request GET \
--url 'https://sandbox.onebrick.io/v2/payments/gs/bank-account-validation?accountNumber=accountNumber&bankShortCode=bankShortCode' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'publicAccessToken: Bearer {{publicAccessToken}}'
You will get the name of the owners for the given account, If it belongs to the right person then you can do the further process of sending money.
{
"status": 200,
"data": {
"message": "We are successfully able to verify the account",
"accountNo": "4124668005",
"accountName": "M.HIBBAN IRSYAD",
"bankShortCode": "PERMATA"
},
"metaData": {
"source": "API",
"entity": "Payment"
},
"error": null
}
Step 3: Send Money
This endpoint helps you to send money to the desired account, We suggest following this step after Step 2 because Step 2 can help you to reduce the risk of sending money to the wrong account.
You can use JWT / public access token that was generated in Step 1 to do the disbursement.
curl --request POST \
--url https://sandbox.onebrick.io/v2/payments/gs/disbursements \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'publicAccessToken: Bearer {{publicAccessToken}}' \
--data '
{
"referenceId": "test-disbursement-1",
"description": "test-disbursement-1",
"amount": 10000,
"disbursementMethod": {
"type": "bank_transfer",
"bankShortCode": "MANDIRI",
"bankAccountNo": "12345678",
"bankAccountHolderName": "PROD ONLY"
}
}
'
This API is Async API, You will get response that we have received the request as below.
{
"status": 200,
"data": {
"message": "We have received your request and are processing it, please check your callback URL for transaction status",
"id": "asdasd123123asdasdasd",
"type": "disbursement",
"attributes": {
"referenceId": "test-disbursement-1",
"description": "test-disbursement-1",
"amount": "10000",
"status": "processing",
"createdAt": "2022-07-21T13:49:39.752+07:00",
"disbursementMethod": {
"type": "bank_transfer",
"bankAccountNo": "12345678",
"bankShortCode": "BCA",
"bankAccountHolderName": "PROD ONLY"
}
}
},
"metaData": {
"source": "API",
"entity": "Payment"
},
"error": null
}
Also, We will send the final response to your callback URL, Request body of callback request will look almost similar as first response with final/Updated status values.
{
"data": {
"id": "asdasd123123asdasdasd",
"type": "disbursement",
"attributes": {
"referenceId": "test-disbursement-1",
"description": "test-disbursement-1",
"amount": "10000",
"status": "completed",
"createdAt": "2022-07-21T13:49:39.752+07:00",
"disbursementMethod": {
"type": "bank_transfer",
"bankAccountNo": "12345678",
"bankShortCode": "BCA",
"bankAccountHolderName": "PROD ONLY",
"bankName" : "Bank Central Asia"
}
}
}
}
Conclusion
Using this step-by-step guide you have been able to get the first preview of Brick's API and how to integrate Brick into your website or application
Updated about 1 year ago