use of com.tranxactive.j2pay.gateways.responses.VoidResponse in project J2PAY by tranxactive.
the class BraintreeGateway method voidTransaction.
@Override
public HTTPResponse voidTransaction(JSONObject apiParameters, JSONObject voidParameters) {
boolean hasException = false;
VoidResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HTTPResponse httpResponse = new HTTPResponse();
Result<Transaction> voidTransaction = null;
try {
voidTransaction = getGatewayObject(apiParameters).transaction().voidTransaction(voidParameters.getString(ParamList.TRANSACTION_ID.getName()));
} catch (NotFoundException e) {
errorResponse.setMessage("No record found");
hasException = true;
} catch (AuthenticationException e) {
errorResponse.setMessage("Invalid credentials");
hasException = true;
} catch (AuthorizationException e) {
errorResponse.setMessage("Not authorized to perform this action");
hasException = true;
} catch (ConfigurationException e) {
errorResponse.setMessage("Configuratoin error");
hasException = true;
} catch (DownForMaintenanceException e) {
errorResponse.setMessage("Server is under maintenance");
hasException = true;
} catch (TimeoutException e) {
errorResponse.setMessage("Request time out");
hasException = true;
} catch (ForgedQueryStringException | InvalidChallengeException | InvalidSignatureException | UnexpectedException e) {
errorResponse.setMessage("Unexpected exception occured");
hasException = true;
} catch (ServerException e) {
errorResponse.setMessage("Server error");
hasException = true;
} catch (TooManyRequestsException e) {
errorResponse.setMessage("Too many requests");
hasException = true;
} catch (UpgradeRequiredException e) {
errorResponse.setMessage("Need to upgrade");
hasException = true;
}
if (hasException) {
processFinalResponse(null, httpResponse, successResponse, errorResponse);
return httpResponse;
}
if (voidTransaction.isSuccess()) {
successResponse = new VoidResponse();
successResponse.setMessage("Success");
successResponse.setTransactionId(voidTransaction.getTarget().getId());
} else {
errorResponse.setMessage(voidTransaction.getMessage());
}
processFinalResponse(null, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.gateways.responses.VoidResponse in project J2PAY by tranxactive.
the class PayeezyGateway method voidTransaction.
@Override
public HTTPResponse voidTransaction(JSONObject apiParameters, JSONObject voidParameters) {
JSONObject resp = null;
String requestString = this.buildVoidParameters(apiParameters, voidParameters);
VoidResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HTTPResponse httpResponse = HTTPClient.httpPost(this.getApiURL(), requestString, ContentType.APPLICATION_XML);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
if (httpResponse.getContent().trim().startsWith("<")) {
resp = XMLHelper.toJson(httpResponse.getContent());
boolean transactionError = resp.getJSONObject("TransactionResult").getBoolean("Transaction_Error");
boolean transactionApproved = resp.getJSONObject("TransactionResult").getBoolean("Transaction_Approved");
if (transactionApproved) {
successResponse = new VoidResponse();
successResponse.setMessage(resp.getJSONObject("TransactionResult").getString("Bank_Message"));
successResponse.setTransactionId(resp.getJSONObject("TransactionResult").get("Transaction_Tag").toString());
} else {
errorResponse.setMessage(resp.getJSONObject("TransactionResult").get(transactionError ? "EXact_Message" : "Bank_Message").toString());
errorResponse.setTransactionId(resp.getJSONObject("TransactionResult").optString("Transaction_Tag"));
}
} else {
errorResponse.setMessage(httpResponse.getContent());
}
// final response.
processFinalResponse(resp, httpResponse, successResponse, errorResponse);
return httpResponse;
}
Aggregations