Search in sources :

Example 51 with HTTPResponse

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;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse)

Example 52 with 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;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse)

Aggregations

HTTPResponse (com.tranxactive.j2pay.net.HTTPResponse)52 JSONObject (org.json.JSONObject)50 ErrorResponse (com.tranxactive.j2pay.gateways.responses.ErrorResponse)12 AuthenticationException (com.braintreegateway.exceptions.AuthenticationException)7 AuthorizationException (com.braintreegateway.exceptions.AuthorizationException)7 ConfigurationException (com.braintreegateway.exceptions.ConfigurationException)7 DownForMaintenanceException (com.braintreegateway.exceptions.DownForMaintenanceException)7 ForgedQueryStringException (com.braintreegateway.exceptions.ForgedQueryStringException)7 InvalidChallengeException (com.braintreegateway.exceptions.InvalidChallengeException)7 InvalidSignatureException (com.braintreegateway.exceptions.InvalidSignatureException)7 NotFoundException (com.braintreegateway.exceptions.NotFoundException)7 ServerException (com.braintreegateway.exceptions.ServerException)7 TimeoutException (com.braintreegateway.exceptions.TimeoutException)7 TooManyRequestsException (com.braintreegateway.exceptions.TooManyRequestsException)7 UnexpectedException (com.braintreegateway.exceptions.UnexpectedException)7 UpgradeRequiredException (com.braintreegateway.exceptions.UpgradeRequiredException)7 Transaction (com.braintreegateway.Transaction)6 BigDecimal (java.math.BigDecimal)5 HashMap (java.util.HashMap)4 TransactionRequest (com.braintreegateway.TransactionRequest)3