use of com.braintreegateway.exceptions.InvalidChallengeException in project J2PAY by tranxactive.
the class BraintreeGateway method capture.
@Override
public HTTPResponse capture(JSONObject apiParameters, JSONObject captureParameters, float amount) {
boolean hasException = false;
CaptureResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HTTPResponse httpResponse = new HTTPResponse();
Result<Transaction> capture = null;
try {
capture = getGatewayObject(apiParameters).transaction().submitForSettlement(captureParameters.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 (capture.isSuccess()) {
successResponse = new CaptureResponse();
successResponse.setMessage("Success");
successResponse.setTransactionId(capture.getTarget().getId());
successResponse.setAmount(amount);
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), capture.getTarget().getId()));
successResponse.setRefundParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), capture.getTarget().getId()));
} else {
errorResponse.setMessage(capture.getMessage());
}
processFinalResponse(null, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.braintreegateway.exceptions.InvalidChallengeException in project J2PAY by tranxactive.
the class BraintreeGateway method rebill.
@Override
public HTTPResponse rebill(JSONObject apiParameters, JSONObject rebillParameters, float amount) {
boolean hasException = false;
RebillResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HTTPResponse httpResponse = new HTTPResponse();
TransactionRequest transactionRequest = new TransactionRequest();
transactionRequest.customerId(rebillParameters.getString(CUSTOMER_ID)).amount(new BigDecimal(Float.toString(amount)));
transactionRequest.options().submitForSettlement(true);
Result<Transaction> sale = null;
try {
sale = getGatewayObject(apiParameters).transaction().sale(transactionRequest);
} 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 (sale.isSuccess()) {
successResponse = new RebillResponse();
successResponse.setMessage("Success");
successResponse.setTransactionId(sale.getTarget().getId());
successResponse.setAmount(amount);
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), sale.getTarget().getId()));
successResponse.setRebillParams(new JSONObject().put(CUSTOMER_ID, rebillParameters.getString(CUSTOMER_ID)));
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), sale.getTarget().getId()));
} else {
errorResponse.setMessage(sale.getMessage());
}
processFinalResponse(null, httpResponse, successResponse, errorResponse);
return httpResponse;
}
Aggregations