Refresh transactions
Overview
/transactions/refresh
is an optional endpoint for users of the transactions product. It initiates an on-demand extraction to fetch the newest transactions for an item.
This on-demand extraction takes place in addition to the periodic extractions that automatically occur multiple times a day for any transactions-enabled Item.
Changes to transactions are discovered after calling /transactions/refresh
.
curl -X POST https://api.okra.ng/v2/transactions/refresh
-H 'Content-Type: application/json'
-H 'Authorisation: Bearer <secretKey>'
-d '{
"account_id": OKRA ACCOUNT ID, // Account ID of connected customer
}'
{
"status": "success",
"message": "Transactions processing...",
"data": {
"callback_url": "https://api.okra.ng/v2/callback?record={record_id}&method=REFRESH_TRANSACTIONS"
}
Transactions callback
When you refresh the balance, the response is not instantaneous because we must interact with the customer's financial institution. As a result, you will receive a callback_url
as in the JSON response example above. You can view an example of how to handle the response and retrieve the balance in real-time.
exports.fetchTransactions = async (req, res, next) => {
req.setTimeout(0)
const baseURL = 'https://api.okra.ng/v2'
const {account_id,record_id,currency,waitTime} = req.body //waitTime is in minutes
const token = `Your_JWT_token`
let config = {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${sekretKey}`
}
}
const getTransactionReq = () => {
try {
return axios.post(`${baseURL}/transactions/refresh`, { account_id: account_id, record_id: record_id, currency: currency }, config)
} catch (error) {
console.error(error)
}
}
const getCallBackData = (data) => {
try {
return axios.get(data, config)
} catch (error) {
console.error(error)
}
}
const getCallBackReq = async () => {
getTransactionReq()
.then(async response => {
if (response.data.data) {
await waitFor(waitTime * 60000) // convert minutes to millisconds
return [response.data.data.callback_url.replace("undefined", "callback")].join('')
}
}).then(callBack => {
getCallBackData(callBack)
.then(response => {
res.json(response.data)
})
.catch(error => {
console.log(error)
})
})
.catch(error => {
console.log(error)
})
}
getCallBackReq()
}
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
Make a refresh-transaction request in real-time, from our API Reference.
Updated 9 months ago