Api Connector
Overview
The API connector is a module that simulates clint-server communication between the host application and Synqpay service.
This makes it easier to support new API functionality without reflecting it in POJO objects. When Synqpay is updated with new features, the client doesn't have to update the SDK for this purpose.
The API contains only one method for sending requests as Strings. The request is JSON-RPC based, as described in the API reference.
Methods
| interface ResponseCallback {
void onResponse(String response);
}
interface SynqpayAPI {
void sendRequest(String request, ResponseCallback callback);
}
|
sendRequest
accepts the JSON-RPC as a string
and a callback instance for this request.
onResponse
is called when the method has completed execution or an error has been thrown. This method also receives an error response for the request.
Example
| JSONObject jsonObject = new JSONObject();
try {
jsonObject.
put("jsonrpc","2.0").
put("id","1234").
put("method","getTerminalStatus").
put("params",null);
} catch (JSONException e) {
ResponseCallback.Stub getStatusCallback = new ResponseCallback.Stub() {
@Override
public void onResponse(String response) {
String terminalId,status;
try {
JSONObject jsonResponse = new JSONObject(response);
JSONObject jsonResult = jsonResponse.optJSONObject("result");
if (jsonResult == null)
return;
terminalId = jsonResult.optString("terminalId","");
status = jsonResult.optString("status","");
} catch (JSONException e) {
}
}
};
}
try {
api.sendRequest(jsonObject,toString(),getStatusCallback);
} catch (RemoteException ignored) {
}
|