Handling the response | Response Received Callback
Handling the response of the integrated report function in iClient involves the use of the responseReceivedCallback. The specification for the callback is given below.
Response Received Callback
Function | Description | Usage Required |
---|---|---|
responseReceivedCallback | Invoked when the request has been completed on the terminal. Called with a single object containing the following fields, as shown in the below table. | Required |
Field | Type | Description | Usage Required |
---|---|---|---|
result | String | The result of the report request, will be either ‘success’ or ‘failure’. | Required |
format | String | The format requested is passed back for convenience, will be either ‘summary’ or ‘detailed’. | Optional |
type | String | The type requested is passed back for convenience, will be either ‘txt’ or ‘xml’ | Optional |
data | String | The report. Pre-formatted text when format is txt. Parsable xml when format xml. | Required |
error | String | An error message to show the merchant. Only present when result is failure. | Required |
Steps to Follow
The steps to follow in handling the response for the reconciliationReport() function are as follows:
- The report requested by the POS using the reconciliationReport() function is returned using the responseReceivedCallback, the POS must provide the function required to handle the callback response.
- The data field contains the unparsed text or XML version of the report (as per the request), for reference, the format and type for the requested report are also passed back in the format and the type fields.
- The POS must then parse the report data, if it is a text format report, the POS must remove the labels, and if it is a XML format report, the POS must then parse the XML to obtain the data for the transactions performed in a given day.
Important
If the request is unsuccessful, the POS will be provided the result and the error message in the result and the error fields, the POS must use them, and display the result and the error message on the screen for the user’s reference.
Callback Function
var reportCallback = function(response) {
console.log(JSON.stringify(response));
var report=response.data;
//Parsing the Text version of the report to remove the labels//
if (($("input[name='format']:checked").val())=="txt"){
report = report.replace(/NEW_LINE/g," ");
report = report.replace(/MEDIUM_CENTRED:/g," ");
report = report.replace(/MEDIUM:/g," ");
report = report.replace(/MEDIUM_RIGHT:/g," ");
report = report.replace(/MEDIUM_BOLD:/g," ");
report = report.replace(/LARGE_CENTRED:/g," ");
report = report.replace(/FORM_FEED/g," ");
report = report.replace(/SMALL:/g," ");
report = report.replace(/SMALL:/g," ");
}
console.log(report);
$("#result").html(response.result);
$("#data").html("<pre>" + escapeHtml(report) + "</pre>");
$("#error").html(response.error);
};
Example Response
Below is an xml response example for the Report request
{"result":"success",
"format":"xml",
"type":"summary",
"data":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
<reconciliation-summary mid=\"200\" tid=\"200\" terminal-business-day=\"2024-01-17\" total=\"1620.00\">\n
<card type=\"visa\" purchases=\"280.00\" refunds=\"-70.00\" total=\"210.00\"/>\n
<card type=\"mastercard\" purchases=\"200.00\" refunds=\"-80.00\" total=\"120.00\"/>\n
<card type=\"eftpos\" purchases=\"1100.00\" cash-out=\"50.00\" refunds=\"0.00\" total=\"1150.00\"/>\n
<card type=\"amex\" purchases=\"30.00\" refunds=\"0.00\" total=\"30.00\"/>\n
<card type=\"diners\" purchases=\"70.00\" refunds=\"0.00\" total=\"70.00\"/>\n
<card type=\"jcb\" purchases=\"40.00\" refunds=\"0.00\" total=\"40.00\"/>\n
</reconciliation-summary>\n"
}