Poll method
Simplex Events API endpoints to get the events data.
Using a combination of the Get Events and Delete Events you will be able to track payment events.
When certain changes are made to a payment, the event for that change is generated on the event queue.
The app provider must read these events by polling this API and act accordingly.
Notice
- This API endpoint is intended for server request with a static whitelisted IP.
- This API endpoint may be optional, as the app provider can follow the Blockchain in order to update the end-user’s balance.
Sample Code
Here is some sample code for calling and handling events:
const axios = require("axios");
const simplexURL =
"https://sandbox.test-simplexcc.com/wallet/merchant/v2/events";
const APIKey =
"INSERT_API_KEY";
function getEvents(APIKey) {
return new Promise((resolve, reject) => {
axios
.get(simplexURL, {
headers: {
Authorization: "APIKey " + APIKey,
},
})
.then(({ data }) => {
resolve(data);
})
.catch((error) => {
const responseStatus = error.response.status;
if (responseStatus && responseStatus === 401) {
return reject("wrong ApiKey");
}
reject(error);
});
});
}
function dealWithEvent(event) {
// Do some custom logic with event
// . ....
// Then delete it
return new Promise((resolve, reject) => {
axios
.delete(simplexURL + "/" + event.event_id, {
headers: {
Authorization: "APIKey " + APIKey,
},
})
.then((request) => {
if (request.data.status === "OK") {
resolve();
} else {
reject(request.data);
}
})
.catch((error) => {
reject(error);
});
});
}
getEvents(APIKey)
.then((data) => {
console.log("The result succeeded!", data);
data.events.forEach((event) => {
dealWithEvent(event);
});
})
.catch((error) => {
console.error(error);
});
The correct way of handling events
- Query for all events (GET /events) and Save them locally.
- Delete saved events one by one ( DELETE /events/{event_id} )
- Search the records by payment ID (in case there is more than one item, refer to the newest one)
- Update your system with the new status.
Please make sure you're handling the events immediately as they appear in the queue and use the 'name' field to indicate the status
Reminder: only use the 'name' field in Events api to indicate the status of a payment. The 'status' field should be ignored.
Available Events
Simplex provides with several events that you can read and track.
learn more about events list
Updated 9 months ago