Search in sources :

Example 31 with HTTPResponse

use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.

the class PayflowProGateway method rebill.

@Override
public HTTPResponse rebill(JSONObject apiParameters, JSONObject rebillParameters, float amount) {
    String requestString = QueryStringHelper.toQueryString(JSONHelper.encode(this.buildRebillParameters(apiParameters, rebillParameters, amount)));
    JSONObject responseObject;
    HTTPResponse httpResponse;
    RebillResponse 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 RebillResponse();
        successResponse.setMessage(responseObject.getString("RESPMSG"));
        successResponse.setTransactionId(responseObject.get("PNREF").toString());
        successResponse.setAmount(amount);
        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;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse)

Example 32 with HTTPResponse

use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.

the class PayflowProGateway method refund.

@Override
public HTTPResponse refund(JSONObject apiParameters, JSONObject refundParameters, float amount) {
    String requestString = QueryStringHelper.toQueryString(JSONHelper.encode(this.buildRefundParameters(apiParameters, refundParameters, amount)));
    JSONObject responseObject;
    HTTPResponse httpResponse;
    RefundResponse 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 RefundResponse();
        successResponse.setMessage(responseObject.getString("RESPMSG"));
        successResponse.setTransactionId(responseObject.get("PNREF").toString());
        successResponse.setAmount(amount);
        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;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse)

Example 33 with HTTPResponse

use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.

the class StripeGateway method capture.

@Override
public HTTPResponse capture(JSONObject apiParameters, JSONObject captureParameters, float amount) {
    CaptureResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    JSONObject requestObject = this.buildCaptureParameters(amount);
    JSONObject responseObject;
    String requestString;
    requestObject = JSONHelper.encode(requestObject);
    requestString = QueryStringHelper.toQueryString(requestObject);
    HTTPResponse httpResponse;
    httpResponse = HTTPClient.httpPostWithBasicAuth(this.apiURL + "/charges/" + captureParameters.getString("chargeId") + "/capture", 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 CaptureResponse();
        successResponse.setMessage("Success");
        successResponse.setTransactionId(responseObject.getString("id"));
        successResponse.setAmount(amount);
        successResponse.setVoidParams(new JSONObject().put("chargeId", responseObject.getString("id")).put("amount", amount));
        successResponse.setRefundParams(new JSONObject().put("chargeId", 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 34 with HTTPResponse

use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.

the class StripeGateway method authorize.

@Override
public HTTPResponse authorize(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
    HTTPResponse tokenHTTPResponse = HTTPClient.httpPostWithBasicAuth(apiURL + "/tokens", QueryStringHelper.toQueryString(JSONHelper.encode(this.buildTokenParameters(customer, customerCard, currency))), ContentType.APPLICATION_FORM_URLENCODED, null, apiParameters.getString("userName"), "");
    AuthResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    if (tokenHTTPResponse.getStatusCode() == -1) {
        return tokenHTTPResponse;
    }
    JSONObject tokenJSONResponse = tokenHTTPResponse.getJSONResponse();
    if (!(tokenHTTPResponse.getStatusCode() >= 200 && tokenHTTPResponse.getStatusCode() < 300)) {
        errorResponse.setMessage(tokenJSONResponse.getJSONObject("error").getString("message"));
        processFinalResponse(tokenJSONResponse, tokenHTTPResponse, successResponse, errorResponse);
        return tokenHTTPResponse;
    }
    HTTPResponse saveCustomerHTTPResponse = HTTPClient.httpPostWithBasicAuth(apiURL + "/customers", QueryStringHelper.toQueryString(JSONHelper.encode(this.buildSaveCustomerParameters(tokenJSONResponse.getString("id")))), ContentType.APPLICATION_FORM_URLENCODED, null, apiParameters.getString("userName"), "");
    if (saveCustomerHTTPResponse.getStatusCode() == -1) {
        return saveCustomerHTTPResponse;
    }
    JSONObject saveCustomerJSONResponse = saveCustomerHTTPResponse.getJSONResponse();
    if (!(saveCustomerHTTPResponse.getStatusCode() >= 200 && saveCustomerHTTPResponse.getStatusCode() < 300)) {
        errorResponse.setMessage(saveCustomerJSONResponse.getJSONObject("error").getString("message"));
        processFinalResponse(saveCustomerJSONResponse, saveCustomerHTTPResponse, successResponse, errorResponse);
        return saveCustomerHTTPResponse;
    }
    JSONObject requestObject = this.buildAuthorizeParameters(saveCustomerJSONResponse.getString("id"), currency, amount);
    JSONObject responseObject;
    String requestString;
    requestObject = JSONHelper.encode(requestObject);
    requestString = QueryStringHelper.toQueryString(requestObject);
    HTTPResponse httpResponse;
    httpResponse = HTTPClient.httpPostWithBasicAuth(this.apiURL + "/charges", 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 AuthResponse();
        successResponse.setMessage("Success");
        successResponse.setTransactionId(responseObject.getString("id"));
        successResponse.setCardValuesFrom(customerCard);
        successResponse.setAmount(amount);
        successResponse.setCurrencyCode(currency);
        successResponse.setRebillParams(new JSONObject().put("customerId", saveCustomerJSONResponse.getString("id")).put("currency", currency));
        successResponse.setVoidParams(new JSONObject().put("chargeId", responseObject.getString("id")).put("amount", amount));
        successResponse.setCaptureParams(new JSONObject().put("chargeId", 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 35 with HTTPResponse

use of com.tranxactive.j2pay.net.HTTPResponse in project J2PAY by tranxactive.

the class StripeGateway method rebill.

@Override
public HTTPResponse rebill(JSONObject apiParameters, JSONObject rebillParameters, float amount) {
    RebillResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    JSONObject requestObject = this.buildRebillParameters(rebillParameters.getString("customerId"), Currency.valueOf(rebillParameters.getString("currency")), amount);
    JSONObject responseObject;
    String requestString;
    requestObject = JSONHelper.encode(requestObject);
    requestString = QueryStringHelper.toQueryString(requestObject);
    HTTPResponse httpResponse;
    httpResponse = HTTPClient.httpPostWithBasicAuth(this.apiURL + "/charges", 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 RebillResponse();
        successResponse.setMessage("Success");
        successResponse.setTransactionId(responseObject.getString("id"));
        successResponse.setAmount(amount);
        successResponse.setRebillParams(new JSONObject().put("customerId", rebillParameters.getString("customerId")).put("currency", rebillParameters.getString("currency")));
        successResponse.setVoidParams(new JSONObject().put("chargeId", responseObject.getString("id")).put("amount", (int) (amount * 100)));
        successResponse.setRefundParams(new JSONObject().put("chargeId", 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)

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