use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class StripeGateway method voidTransaction.
@Override
public HTTPResponse voidTransaction(JSONObject apiParameters, JSONObject voidParameters) {
VoidResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
JSONObject requestObject = this.buildVoidParameters(voidParameters, voidParameters.getInt("amount"));
JSONObject responseObject;
String requestString;
requestObject = JSONHelper.encode(requestObject);
requestString = QueryStringHelper.toQueryString(requestObject);
HTTPResponse httpResponse;
httpResponse = HTTPClient.httpPostWithBasicAuth(this.apiURL + "/refunds", requestString, ContentType.APPLICATION_FORM_URLENCODED, null, apiParameters.getString("userName"), "");
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
responseObject = httpResponse.getJSONResponse();
if (httpResponse.getStatusCode() >= 200 && httpResponse.getStatusCode() < 300) {
successResponse = new VoidResponse();
successResponse.setMessage("Success");
successResponse.setTransactionId(responseObject.getString("id"));
} else {
errorResponse.setMessage(responseObject.getJSONObject("error").getString("message"));
errorResponse.setTransactionId(null);
}
// final response.
processFinalResponse(responseObject, httpResponse, successResponse, errorResponse);
return httpResponse;
}
use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.
the class StripeGateway method refund.
@Override
public HTTPResponse refund(JSONObject apiParameters, JSONObject refundParameters, float amount) {
RefundResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
JSONObject requestObject = this.buildRefundParameters(refundParameters, amount);
JSONObject responseObject;
String requestString;
requestObject = JSONHelper.encode(requestObject);
requestString = QueryStringHelper.toQueryString(requestObject);
HTTPResponse httpResponse;
httpResponse = HTTPClient.httpPostWithBasicAuth(this.apiURL + "/refunds", requestString, ContentType.APPLICATION_FORM_URLENCODED, null, apiParameters.getString("userName"), "");
if (httpResponse.getStatusCode() == -1) {
return httpResponse;
}
responseObject = httpResponse.getJSONResponse();
if (httpResponse.getStatusCode() >= 200 && httpResponse.getStatusCode() < 300) {
successResponse = new RefundResponse();
successResponse.setMessage("Success");
successResponse.setTransactionId(responseObject.getString("id"));
successResponse.setAmount(amount);
successResponse.setVoidParams(null);
} else {
errorResponse.setMessage(responseObject.getJSONObject("error").getString("message"));
errorResponse.setTransactionId(null);
}
// final response.
processFinalResponse(responseObject, httpResponse, successResponse, errorResponse);
return httpResponse;
}
Aggregations