use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class CheckoutGateway method refund.
@Override
public HTTPResponse refund(JSONObject apiParameters, JSONObject refundParameters, float amount) {
JSONObject requestObject = this.buildRefundParameters(amount);
JSONObject responseObject;
requestObject = JSONHelper.encode(requestObject);
HTTPResponse httpResponse;
RefundResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HashMap headers = new HashMap<String, String>();
headers.put("Authorization", apiParameters.getString("Authorization"));
httpResponse = HTTPClient.httpPost(this.getApiURL() + "/" + refundParameters.get("transactionId") + "/refund", requestObject.toString(), ContentType.APPLICATION_JSON, headers);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
responseObject = httpResponse.getJSONResponse();
if (responseObject.has("responseCode") && (responseObject.get("responseCode").toString().startsWith("10"))) {
successResponse = new RefundResponse();
successResponse.setMessage(responseObject.get("responseMessage").toString());
successResponse.setTransactionId(responseObject.get("id").toString());
successResponse.setAmount(amount);
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), responseObject.get("id").toString()).put("trackId", refundParameters.get("trackId").toString()));
} else {
errorResponse.setMessage(responseObject.get("message").toString());
errorResponse.setTransactionId(responseObject.optString("id"));
}
// final response.
processFinalResponse(responseObject, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class AuthorizeGateway method rebill.
@Override
public HTTPResponse rebill(JSONObject apiParameters, JSONObject rebillParameters, float amount) {
JSONObject resp;
String requestString = this.buildRebillParameters(apiParameters, rebillParameters, amount);
RebillResponse 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) {
String cardLast4 = resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("accountNumber").toString();
cardLast4 = cardLast4.substring(cardLast4.length() - 4, cardLast4.length());
successResponse = new RebillResponse();
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.setRebillParams(rebillParameters);
successResponse.setRefundParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString()).put(ParamList.CARD_LAST_4.getName(), cardLast4));
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;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class AuthorizeGateway method capture.
@Override
public HTTPResponse capture(JSONObject apiParameters, JSONObject captureParameters, float amount) {
JSONObject resp;
String requestString = this.buildCaptureParameters(apiParameters, captureParameters, amount);
CaptureResponse 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) {
String cardLast4 = resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("accountNumber").toString();
cardLast4 = cardLast4.substring(cardLast4.length() - 4, cardLast4.length());
successResponse = new CaptureResponse();
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()));
successResponse.setRefundParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString()).put(ParamList.CARD_LAST_4.getName(), cardLast4));
} 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 NMIGateway method rebill.
@Override
public HTTPResponse rebill(JSONObject apiParameters, JSONObject rebillParameters, float amount) {
JSONObject requestObject = this.buildRebillParameters(apiParameters, rebillParameters, amount);
JSONObject responseObject;
String requestString;
String responseString;
requestObject = JSONHelper.encode(requestObject);
requestString = QueryStringHelper.toQueryString(requestObject);
HTTPResponse httpResponse;
RebillResponse 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 RebillResponse();
successResponse.setMessage(responseObject.getString("responsetext"));
successResponse.setTransactionId(responseObject.get("transactionid").toString());
successResponse.setAmount(amount);
successResponse.setRebillParams(rebillParameters);
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 NMIGateway 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;
}
Aggregations