use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class EasypayGateway 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;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class EasypayGateway 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 EasypayGateway 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 PayeezyGateway method voidTransaction.
@Override
public HTTPResponse voidTransaction(JSONObject apiParameters, JSONObject voidParameters) {
JSONObject resp = null;
String requestString = this.buildVoidParameters(apiParameters, voidParameters);
VoidResponse 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 VoidResponse();
successResponse.setMessage(resp.getJSONObject("TransactionResult").getString("Bank_Message"));
successResponse.setTransactionId(resp.getJSONObject("TransactionResult").get("Transaction_Tag").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 PayeezyGateway method purchase.
@Override
public HTTPResponse purchase(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
JSONObject resp = null;
String requestString = this.buildPurchaseParameters(apiParameters, customer, customerCard, currency, amount);
PurchaseResponse 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 PurchaseResponse();
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.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;
}
Aggregations