use of com.tranxactive.j2pay.net.HTTPResponse 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.net.HTTPResponse in project J2PAY by tranxactive.
the class BraintreeGateway method refund.
@Override
public HTTPResponse refund(JSONObject apiParameters, JSONObject refundParameters, float amount) {
boolean hasException = false;
RefundResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HTTPResponse httpResponse = new HTTPResponse();
Result<Transaction> refund = null;
try {
refund = getGatewayObject(apiParameters).transaction().refund(refundParameters.getString(ParamList.TRANSACTION_ID.getName()), new BigDecimal(Float.toString(amount)));
} 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 (refund.isSuccess()) {
successResponse = new RefundResponse();
successResponse.setMessage("Success");
successResponse.setTransactionId(refund.getTarget().getId());
successResponse.setAmount(amount);
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), refund.getTarget().getId()));
} else {
errorResponse.setMessage(refund.getMessage());
}
processFinalResponse(null, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class EasypayGateway method purchase.
@Override
public HTTPResponse purchase(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
String customerVaultId = getUniqueVaultId();
JSONObject requestObject = this.buildPurchaseParameters(apiParameters, customer, customerCard, currency, amount, customerVaultId);
JSONObject responseObject;
String requestString;
String responseString;
requestObject = JSONHelper.encode(requestObject);
requestString = QueryStringHelper.toQueryString(requestObject);
HTTPResponse httpResponse;
PurchaseResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
httpResponse = HTTPClient.httpPost(this.apiURL, requestString, ContentType.APPLICATION_FORM_URLENCODED);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
responseString = httpResponse.getContent();
responseObject = JSONHelper.decode(QueryStringHelper.toJson(responseString));
if (responseObject.getInt("response_code") == 100) {
successResponse = new PurchaseResponse();
successResponse.setMessage(responseObject.getString("responsetext"));
successResponse.setTransactionId(responseObject.get("transactionid").toString());
successResponse.setCardValuesFrom(customerCard);
successResponse.setAmount(amount);
successResponse.setCurrencyCode(currency);
successResponse.setRebillParams(new JSONObject().put("customerVaultId", customerVaultId));
successResponse.setRefundParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), responseObject.get("transactionid").toString()));
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), responseObject.get("transactionid").toString()));
} else {
errorResponse.setMessage(responseObject.getString("responsetext"));
errorResponse.setTransactionId(responseObject.has("transactionid") ? responseObject.getString("transactionid") : null);
}
// final response.
processFinalResponse(responseObject, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class EasypayGateway method voidTransaction.
@Override
public HTTPResponse voidTransaction(JSONObject apiParameters, JSONObject voidParameters) {
JSONObject requestObject = this.buildVoidParameters(apiParameters, voidParameters);
JSONObject responseObject;
String requestString;
String responseString;
requestObject = JSONHelper.encode(requestObject);
requestString = QueryStringHelper.toQueryString(requestObject);
HTTPResponse httpResponse;
VoidResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
httpResponse = HTTPClient.httpPost(this.apiURL, requestString, ContentType.APPLICATION_FORM_URLENCODED);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
responseString = httpResponse.getContent();
responseObject = JSONHelper.decode(QueryStringHelper.toJson(responseString));
if (responseObject.getInt("response_code") == 100) {
successResponse = new VoidResponse();
successResponse.setMessage(responseObject.getString("responsetext"));
successResponse.setTransactionId(responseObject.get("transactionid").toString());
} else {
errorResponse.setMessage(responseObject.getString("responsetext"));
errorResponse.setTransactionId(responseObject.has("transactionid") ? responseObject.getString("transactionid") : null);
}
// final response.
processFinalResponse(responseObject, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class EasypayGateway method capture.
@Override
public HTTPResponse capture(JSONObject apiParameters, JSONObject captureParameters, float amount) {
JSONObject requestObject = this.buildCaptureParameters(apiParameters, captureParameters, amount);
JSONObject responseObject;
String requestString;
String responseString;
requestObject = JSONHelper.encode(requestObject);
requestString = QueryStringHelper.toQueryString(requestObject);
HTTPResponse httpResponse;
CaptureResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
httpResponse = HTTPClient.httpPost(this.apiURL, requestString, ContentType.APPLICATION_FORM_URLENCODED);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
responseString = httpResponse.getContent();
responseObject = JSONHelper.decode(QueryStringHelper.toJson(responseString));
if (responseObject.getInt("response_code") == 100) {
successResponse = new CaptureResponse();
successResponse.setMessage(responseObject.getString("responsetext"));
successResponse.setTransactionId(responseObject.get("transactionid").toString());
successResponse.setAmount(amount);
successResponse.setRefundParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), responseObject.get("transactionid").toString()));
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), responseObject.get("transactionid").toString()));
} else {
errorResponse.setMessage(responseObject.getString("responsetext"));
errorResponse.setTransactionId(responseObject.has("transactionid") ? responseObject.getString("transactionid") : null);
}
// final response.
processFinalResponse(responseObject, httpResponse, successResponse, errorResponse);
return httpResponse;
}
Aggregations