use of com.tranxactive.j2pay.gateways.responses.ErrorResponse in project J2PAY by tranxactive.
the class PayeezyGateway method refund.
@Override
public HTTPResponse refund(JSONObject apiParameters, JSONObject refundParameters, float amount) {
JSONObject resp = null;
String requestString = this.buildRefundParameters(apiParameters, refundParameters, amount);
RefundResponse 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 RefundResponse();
successResponse.setMessage(resp.getJSONObject("TransactionResult").getString("Bank_Message"));
successResponse.setTransactionId(resp.getJSONObject("TransactionResult").get("Transaction_Tag").toString());
successResponse.setAmount(amount);
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()).put("authorizationNumber", resp.getJSONObject("TransactionResult").get("Authorization_Num").toString()).put(ParamList.AMOUNT.getName(), amount));
} 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;
}
use of com.tranxactive.j2pay.gateways.responses.ErrorResponse in project J2PAY by tranxactive.
the class PayeezyGateway method capture.
@Override
public HTTPResponse capture(JSONObject apiParameters, JSONObject captureParameters, float amount) {
JSONObject resp = null;
String requestString = this.buildCaptureParameters(apiParameters, captureParameters, amount);
CaptureResponse 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 CaptureResponse();
successResponse.setMessage(resp.getJSONObject("TransactionResult").getString("Bank_Message"));
successResponse.setTransactionId(resp.getJSONObject("TransactionResult").get("Transaction_Tag").toString());
successResponse.setAmount(amount);
successResponse.setRefundParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()).put("authorizationNumber", resp.getJSONObject("TransactionResult").get("Authorization_Num").toString()));
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()).put("authorizationNumber", resp.getJSONObject("TransactionResult").get("Authorization_Num").toString()).put(ParamList.AMOUNT.getName(), amount));
} 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;
}
use of com.tranxactive.j2pay.gateways.responses.ErrorResponse in project J2PAY by tranxactive.
the class PayeezyGateway method authorize.
@Override
public HTTPResponse authorize(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
JSONObject resp = null;
String requestString = this.buildAuthParameters(apiParameters, customer, customerCard, currency, amount);
AuthResponse 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 AuthResponse();
successResponse.setMessage(resp.getJSONObject("TransactionResult").getString("Bank_Message"));
successResponse.setTransactionId(resp.getJSONObject("TransactionResult").get("Transaction_Tag").toString());
successResponse.setAmount(amount);
successResponse.setCurrencyCode(currency);
successResponse.setCardValuesFrom(customerCard);
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()).put("authorizationNumber", resp.getJSONObject("TransactionResult").get("Authorization_Num").toString()).put(ParamList.AMOUNT.getName(), amount));
successResponse.setCaptureParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()).put("authorizationNumber", resp.getJSONObject("TransactionResult").get("Authorization_Num").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;
}
use of com.tranxactive.j2pay.gateways.responses.ErrorResponse in project J2PAY by tranxactive.
the class BraintreeGateway method authorize.
@Override
public HTTPResponse authorize(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
boolean hasException = false;
HTTPResponse createCustomer = createCustomer(apiParameters, customer, customerCard, currency, amount);
if (!createCustomer.isSuccessful()) {
return createCustomer;
}
AuthResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HTTPResponse httpResponse = new HTTPResponse();
String customerId = createCustomer.getJSONResponse().getJSONObject(ParamList.LIBRARY_RESPONSE.getName()).getString(ParamList.TRANSACTION_ID.getName());
TransactionRequest transactionRequest = new TransactionRequest();
transactionRequest.customerId(customerId).amount(new BigDecimal(Float.toString(amount)));
transactionRequest.options().submitForSettlement(false);
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 AuthResponse();
successResponse.setMessage("Success");
successResponse.setTransactionId(sale.getTarget().getId());
successResponse.setCardValuesFrom(customerCard);
successResponse.setAmount(amount);
successResponse.setCurrencyCode(currency);
successResponse.setRebillParams(new JSONObject().put(CUSTOMER_ID, customerId));
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), sale.getTarget().getId()));
successResponse.setCaptureParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), sale.getTarget().getId()));
} else {
errorResponse.setMessage(sale.getMessage());
}
processFinalResponse(null, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.gateways.responses.ErrorResponse in project J2PAY by tranxactive.
the class BraintreeGateway method purchase.
@Override
public HTTPResponse purchase(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
boolean hasException = false;
HTTPResponse createCustomer = createCustomer(apiParameters, customer, customerCard, currency, amount);
if (!createCustomer.isSuccessful()) {
return createCustomer;
}
PurchaseResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HTTPResponse httpResponse = new HTTPResponse();
String customerId = createCustomer.getJSONResponse().getJSONObject(ParamList.LIBRARY_RESPONSE.getName()).getString(ParamList.TRANSACTION_ID.getName());
TransactionRequest transactionRequest = new TransactionRequest();
transactionRequest.customerId(customerId).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 PurchaseResponse();
successResponse.setMessage("Success");
successResponse.setTransactionId(sale.getTarget().getId());
successResponse.setCardValuesFrom(customerCard);
successResponse.setAmount(amount);
successResponse.setCurrencyCode(currency);
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), sale.getTarget().getId()));
successResponse.setRebillParams(new JSONObject().put(CUSTOMER_ID, customerId));
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