use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class NMIGateway 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;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class PayflowProGateway method capture.
@Override
public HTTPResponse capture(JSONObject apiParameters, JSONObject captureParameters, float amount) {
String requestString = QueryStringHelper.toQueryString(JSONHelper.encode(this.buildCaptureParameters(apiParameters, captureParameters, amount)));
JSONObject responseObject;
HTTPResponse httpResponse;
CaptureResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
httpResponse = HTTPClient.httpPost(this.getApiURL(), requestString, APPLICATION_FORM_URLENCODED);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
responseObject = JSONHelper.decode(QueryStringHelper.toJson(httpResponse.getContent()));
if (responseObject.getInt("RESULT") == 0) {
successResponse = new CaptureResponse();
successResponse.setMessage(responseObject.getString("RESPMSG"));
successResponse.setTransactionId(responseObject.get("PNREF").toString());
successResponse.setAmount(amount);
successResponse.setRefundParams(new JSONObject().put(TRANSACTION_ID.getName(), responseObject.get("PNREF").toString()));
successResponse.setVoidParams(new JSONObject().put(TRANSACTION_ID.getName(), responseObject.get("PNREF").toString()));
} else {
errorResponse.setMessage(responseObject.getString("RESPMSG"));
errorResponse.setTransactionId(responseObject.optString("PNREF"));
}
// final response.
processFinalResponse(responseObject, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class PayflowProGateway method authorize.
@Override
public HTTPResponse authorize(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
String requestString = QueryStringHelper.toQueryString(JSONHelper.encode(this.buildAuthorizeParameters(apiParameters, customer, customerCard, currency, amount)));
JSONObject responseObject;
HTTPResponse httpResponse;
AuthResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
httpResponse = HTTPClient.httpPost(this.getApiURL(), requestString, APPLICATION_FORM_URLENCODED);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
responseObject = JSONHelper.decode(QueryStringHelper.toJson(httpResponse.getContent()));
if (responseObject.getInt("RESULT") == 0) {
successResponse = new AuthResponse();
successResponse.setMessage(responseObject.getString("RESPMSG"));
successResponse.setTransactionId(responseObject.get("PNREF").toString());
successResponse.setCardValuesFrom(customerCard);
successResponse.setAmount(amount);
successResponse.setCurrencyCode(currency);
successResponse.setRebillParams(new JSONObject().put(TRANSACTION_ID.getName(), responseObject.get("PNREF").toString()));
successResponse.setVoidParams(new JSONObject().put(TRANSACTION_ID.getName(), responseObject.get("PNREF").toString()));
successResponse.setCaptureParams(new JSONObject().put(TRANSACTION_ID.getName(), responseObject.get("PNREF").toString()));
} else {
errorResponse.setMessage(responseObject.getString("RESPMSG"));
errorResponse.setTransactionId(responseObject.optString("PNREF"));
}
// final response.
processFinalResponse(responseObject, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class PayflowProGateway method voidTransaction.
@Override
public HTTPResponse voidTransaction(JSONObject apiParameters, JSONObject voidParameters) {
String requestString = QueryStringHelper.toQueryString(JSONHelper.encode(this.buildVoidParameters(apiParameters, voidParameters)));
JSONObject responseObject;
HTTPResponse httpResponse;
VoidResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
httpResponse = HTTPClient.httpPost(this.getApiURL(), requestString, APPLICATION_FORM_URLENCODED);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
responseObject = JSONHelper.decode(QueryStringHelper.toJson(httpResponse.getContent()));
if (responseObject.getInt("RESULT") == 0) {
successResponse = new VoidResponse();
successResponse.setMessage(responseObject.getString("RESPMSG"));
successResponse.setTransactionId(responseObject.get("PNREF").toString());
} else {
errorResponse.setMessage(responseObject.getString("RESPMSG"));
errorResponse.setTransactionId(responseObject.optString("PNREF"));
}
// final response.
processFinalResponse(responseObject, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class PayflowProGateway method purchase.
@Override
public HTTPResponse purchase(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
String requestString = QueryStringHelper.toQueryString(JSONHelper.encode(this.buildPurchaseParameters(apiParameters, customer, customerCard, currency, amount)));
JSONObject responseObject;
HTTPResponse httpResponse;
PurchaseResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
httpResponse = HTTPClient.httpPost(this.getApiURL(), requestString, APPLICATION_FORM_URLENCODED);
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
responseObject = JSONHelper.decode(QueryStringHelper.toJson(httpResponse.getContent()));
if (responseObject.getInt("RESULT") == 0) {
successResponse = new PurchaseResponse();
successResponse.setMessage(responseObject.getString("RESPMSG"));
successResponse.setTransactionId(responseObject.get("PNREF").toString());
successResponse.setCardValuesFrom(customerCard);
successResponse.setAmount(amount);
successResponse.setCurrencyCode(currency);
successResponse.setRebillParams(new JSONObject().put(TRANSACTION_ID.getName(), responseObject.get("PNREF").toString()));
successResponse.setRefundParams(new JSONObject().put(TRANSACTION_ID.getName(), responseObject.get("PNREF").toString()));
successResponse.setVoidParams(new JSONObject().put(TRANSACTION_ID.getName(), responseObject.get("PNREF").toString()));
} else {
errorResponse.setMessage(responseObject.getString("RESPMSG"));
errorResponse.setTransactionId(responseObject.optString("PNREF"));
}
// final response.
processFinalResponse(responseObject, httpResponse, successResponse, errorResponse);
return httpResponse;
}
Aggregations