use of com.tranxactive.j2pay.net.HTTPResponse 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.net.HTTPResponse 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.net.HTTPResponse 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.net.HTTPResponse in project J2PAY by tranxactive.
the class AuthorizeGateway method authorize.
@Override
public HTTPResponse authorize(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
JSONObject resp;
String requestString = this.buildAuthorizeParameters(apiParameters, customer, customerCard, currency, amount);
AuthResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HTTPResponse httpResponse;
int result;
httpResponse = HTTPClient.httpPost(this.getApiURL(), requestString, ContentType.APPLICATION_XML);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
resp = XMLHelper.toJson(httpResponse.getContent());
if (resp.has("createTransactionResponse")) {
if (resp.getJSONObject("createTransactionResponse").get("transactionResponse") instanceof JSONObject) {
result = resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getInt("responseCode");
if (result == 1) {
successResponse = new AuthResponse();
successResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getJSONObject("messages").getJSONObject("message").getString("description"));
successResponse.setTransactionId(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString());
successResponse.setCardValuesFrom(customerCard);
successResponse.setAmount(amount);
successResponse.setCurrencyCode(currency);
if (resp.getJSONObject("createTransactionResponse").getJSONObject("profileResponse").has("customerProfileId")) {
successResponse.setRebillParams(new JSONObject().put("customerProfileId", resp.getJSONObject("createTransactionResponse").getJSONObject("profileResponse").get("customerProfileId").toString()).put("paymentProfileId", resp.getJSONObject("createTransactionResponse").getJSONObject("profileResponse").getJSONObject("customerPaymentProfileIdList").get("numericString").toString()));
} else {
successResponse.setRebillParams(null);
}
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString()));
successResponse.setCaptureParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString()));
} else {
errorResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getJSONObject("errors").getJSONObject("error").getString("errorText"));
}
} else {
errorResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("messages").getJSONObject("message").getString("text"));
}
} else {
errorResponse.setMessage(resp.getJSONObject("ErrorResponse").getJSONObject("messages").getJSONObject("message").getString("text"));
}
if (successResponse == null) {
if (resp.has("createTransactionResponse") && resp.getJSONObject("createTransactionResponse").has("transactionResponse") && resp.getJSONObject("createTransactionResponse").get("transactionResponse") instanceof JSONObject && resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").has("transId")) {
errorResponse.setTransactionId(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").optString("transId"));
}
}
// final response.
processFinalResponse(resp, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class AuthorizeGateway method refund.
@Override
public HTTPResponse refund(JSONObject apiParameters, JSONObject refundParameters, float amount) {
JSONObject resp;
String requestString = this.buildRefundParameters(apiParameters, refundParameters, amount);
RefundResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HTTPResponse httpResponse;
int result;
httpResponse = HTTPClient.httpPost(this.getApiURL(), requestString, ContentType.APPLICATION_XML);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
resp = XMLHelper.toJson(httpResponse.getContent());
if (resp.has("createTransactionResponse")) {
if (resp.getJSONObject("createTransactionResponse").get("transactionResponse") instanceof JSONObject) {
result = resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getInt("responseCode");
if (result == 1) {
successResponse = new RefundResponse();
successResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getJSONObject("messages").getJSONObject("message").getString("description"));
successResponse.setTransactionId(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString());
successResponse.setAmount(amount);
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString()));
} else {
errorResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getJSONObject("errors").getJSONObject("error").getString("errorText"));
}
} else {
errorResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("messages").getJSONObject("message").getString("text"));
}
} else {
errorResponse.setMessage(resp.getJSONObject("ErrorResponse").getJSONObject("messages").getJSONObject("message").getString("text"));
}
if (successResponse == null) {
if (resp.has("createTransactionResponse") && resp.getJSONObject("createTransactionResponse").has("transactionResponse") && resp.getJSONObject("createTransactionResponse").get("transactionResponse") instanceof JSONObject && resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").has("transId")) {
errorResponse.setTransactionId(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").optString("transId"));
}
}
// final response.
processFinalResponse(resp, httpResponse, successResponse, errorResponse);
return httpResponse;
}
Aggregations