use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class CheckoutGateway method purchase.
@Override
public HTTPResponse purchase(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
String trackId = getUniqueVaultId();
JSONObject requestObject = this.buildPurchaseParameters(trackId, customer, customerCard, currency, amount);
JSONObject responseObject;
HTTPResponse httpResponse;
PurchaseResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HashMap headers = new HashMap<String, String>();
headers.put("Authorization", apiParameters.getString("Authorization"));
httpResponse = HTTPClient.httpPost(this.getApiURL() + "/card", 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 PurchaseResponse();
successResponse.setMessage(responseObject.get("responseMessage").toString());
successResponse.setTransactionId(responseObject.get("id").toString());
successResponse.setCardValuesFrom(customerCard);
successResponse.setAmount(amount);
successResponse.setCurrencyCode(currency);
successResponse.setRebillParams(new JSONObject().put("customerId", responseObject.getJSONObject("card").get("customerId").toString()).put("currency", currency).put("cardId", responseObject.getJSONObject("card").get("id").toString()).put("trackId", trackId));
successResponse.setRefundParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), responseObject.get("id").toString()).put("trackId", trackId));
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), responseObject.get("id").toString()).put("trackId", trackId));
} 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 CheckoutGateway method voidTransaction.
@Override
public HTTPResponse voidTransaction(JSONObject apiParameters, JSONObject voidParameters) {
JSONObject requestObject = this.buildVoidParameters(voidParameters);
JSONObject responseObject;
requestObject = JSONHelper.encode(requestObject);
HTTPResponse httpResponse;
HashMap headers = new HashMap<String, String>();
headers.put("Authorization", apiParameters.getString("Authorization"));
VoidResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
httpResponse = HTTPClient.httpPost(this.getApiURL() + "/" + voidParameters.get("transactionId") + "/void", 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 VoidResponse();
successResponse.setMessage(responseObject.get("responseMessage").toString());
successResponse.setTransactionId(responseObject.get("id").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 NMIGateway method authorize.
@Override
public HTTPResponse authorize(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
String customerVaultId = getUniqueVaultId();
JSONObject requestObject = this.buildAuthorizeParameters(apiParameters, customer, customerCard, currency, amount, customerVaultId);
JSONObject responseObject;
String requestString;
String responseString;
requestObject = JSONHelper.encode(requestObject);
requestString = QueryStringHelper.toQueryString(requestObject);
HTTPResponse httpResponse;
AuthResponse 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 AuthResponse();
successResponse.setMessage(responseObject.getString("responsetext"));
successResponse.setTransactionId(responseObject.get("transactionid").toString());
successResponse.setCardValuesFrom(customerCard);
successResponse.setAmount(amount);
successResponse.setCurrencyCode(currency);
successResponse.setRebillParams(new JSONObject().put("customerVaultId", customerVaultId));
successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), responseObject.get("transactionid").toString()));
successResponse.setCaptureParams(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 purchase.
@Override
public HTTPResponse purchase(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
String customerVaultId = getUniqueVaultId();
JSONObject requestObject = this.buildPurchaseParameters(apiParameters, customer, customerCard, currency, amount, customerVaultId);
JSONObject responseObject;
String requestString;
String responseString;
requestObject = JSONHelper.encode(requestObject);
requestString = QueryStringHelper.toQueryString(requestObject);
HTTPResponse httpResponse;
PurchaseResponse 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 PurchaseResponse();
successResponse.setMessage(responseObject.getString("responsetext"));
successResponse.setTransactionId(responseObject.get("transactionid").toString());
successResponse.setCardValuesFrom(customerCard);
successResponse.setAmount(amount);
successResponse.setCurrencyCode(currency);
successResponse.setRebillParams(new JSONObject().put("customerVaultId", customerVaultId));
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 refund.
@Override
public HTTPResponse refund(JSONObject apiParameters, JSONObject refundParameters, float amount) {
JSONObject requestObject = this.buildRefundParameters(apiParameters, refundParameters, amount);
JSONObject responseObject;
String requestString;
String responseString;
requestObject = JSONHelper.encode(requestObject);
requestString = QueryStringHelper.toQueryString(requestObject);
HTTPResponse httpResponse;
RefundResponse 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 RefundResponse();
successResponse.setMessage(responseObject.getString("responsetext"));
successResponse.setTransactionId(responseObject.get("transactionid").toString());
successResponse.setAmount(amount);
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;
}
Aggregations