Search in sources :

Example 21 with HTTPResponse

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

the class BillproGateway method rebill.

@Override
public HTTPResponse rebill(JSONObject apiParameters, JSONObject rebillParameters, float amount) {
    JSONObject resp;
    int result;
    RebillResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    HTTPResponse httpResponse;
    String requestString = this.buildRebillParameters(apiParameters, rebillParameters, amount);
    httpResponse = HTTPClient.httpPost(url, requestString, ContentType.APPLICATION_XML);
    if (httpResponse.getStatusCode() == -1) {
        return httpResponse;
    }
    resp = XMLHelper.toJson(httpResponse.getContent());
    result = resp.getJSONObject("Response").getInt("ResponseCode");
    if (result == 100) {
        successResponse = new RebillResponse();
        successResponse.setMessage(resp.getJSONObject("Response").getString("Description"));
        successResponse.setTransactionId(resp.getJSONObject("Response").get("TransactionID").toString());
        successResponse.setAmount(amount);
        successResponse.setRebillParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()).put(REFERENCE, rebillParameters.getString(REFERENCE)));
        successResponse.setRefundParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()));
        successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()));
    } else {
        errorResponse.setMessage(resp.getJSONObject("Response").get("Description").toString());
        errorResponse.setTransactionId(resp.getJSONObject("Response").optString("TransactionID"));
    }
    // final response.
    processFinalResponse(resp, httpResponse, successResponse, errorResponse);
    return httpResponse;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse)

Example 22 with HTTPResponse

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

the class BillproGateway method voidTransaction.

@Override
public HTTPResponse voidTransaction(JSONObject apiParameters, JSONObject voidParameters) {
    JSONObject resp;
    int result;
    String requestString = this.buildVoidParameters(apiParameters, voidParameters);
    VoidResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    HTTPResponse httpResponse = HTTPClient.httpPost(url, requestString, ContentType.APPLICATION_XML);
    if (httpResponse.getStatusCode() == -1) {
        return httpResponse;
    }
    resp = XMLHelper.toJson(httpResponse.getContent());
    result = resp.getJSONObject("Response").getInt("ResponseCode");
    if (result == 100) {
        successResponse = new VoidResponse();
        successResponse.setMessage(resp.getJSONObject("Response").getString("Description"));
        successResponse.setTransactionId(resp.getJSONObject("Response").get("TransactionID").toString());
    } else {
        errorResponse.setMessage(resp.getJSONObject("Response").get("Description").toString());
        errorResponse.setTransactionId(resp.getJSONObject("Response").optString("TransactionID"));
    }
    // final response.
    processFinalResponse(resp, httpResponse, successResponse, errorResponse);
    return httpResponse;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse)

Example 23 with HTTPResponse

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

the class BillproGateway method authorize.

@Override
public HTTPResponse authorize(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
    JSONObject resp;
    int result;
    String reference = getUniqueCustomerId();
    String requestString = this.buildAuthParameters(apiParameters, reference, customer, customerCard, currency, amount);
    AuthResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    HTTPResponse httpResponse = HTTPClient.httpPost(url, requestString, ContentType.APPLICATION_XML);
    if (httpResponse.getStatusCode() == -1) {
        return httpResponse;
    }
    resp = XMLHelper.toJson(httpResponse.getContent());
    result = resp.getJSONObject("Response").getInt("ResponseCode");
    if (result == 100) {
        successResponse = new AuthResponse();
        successResponse.setMessage(resp.getJSONObject("Response").getString("Description"));
        successResponse.setTransactionId(resp.getJSONObject("Response").get("TransactionID").toString());
        successResponse.setAmount(amount);
        successResponse.setCurrencyCode(currency);
        successResponse.setCardValuesFrom(customerCard);
        successResponse.setRebillParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()).put(REFERENCE, reference));
        successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()));
        successResponse.setCaptureParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()));
    } else {
        errorResponse.setMessage(resp.getJSONObject("Response").get("Description").toString());
        errorResponse.setTransactionId(resp.getJSONObject("Response").optString("TransactionID"));
    }
    // final response.
    processFinalResponse(resp, httpResponse, successResponse, errorResponse);
    return httpResponse;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse)

Example 24 with HTTPResponse

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

the class BillproGateway method refund.

@Override
public HTTPResponse refund(JSONObject apiParameters, JSONObject refundParameters, float amount) {
    JSONObject resp;
    int result;
    String requestString = this.buildRefundParameters(apiParameters, refundParameters, amount);
    RefundResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    HTTPResponse httpResponse = HTTPClient.httpPost(url, requestString, ContentType.APPLICATION_XML);
    if (httpResponse.getStatusCode() == -1) {
        return httpResponse;
    }
    resp = XMLHelper.toJson(httpResponse.getContent());
    result = resp.getJSONObject("Response").getInt("ResponseCode");
    if (result == 100) {
        successResponse = new RefundResponse();
        successResponse.setMessage(resp.getJSONObject("Response").getString("Description"));
        successResponse.setTransactionId(resp.getJSONObject("Response").get("TransactionID").toString());
        successResponse.setAmount(amount);
        successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()));
    } else {
        errorResponse.setMessage(resp.getJSONObject("Response").get("Description").toString());
        errorResponse.setTransactionId(resp.getJSONObject("Response").optString("TransactionID"));
    }
    // final response.
    processFinalResponse(resp, httpResponse, successResponse, errorResponse);
    return httpResponse;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse)

Example 25 with HTTPResponse

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

the class BillproGateway method capture.

@Override
public HTTPResponse capture(JSONObject apiParameters, JSONObject captureParameters, float amount) {
    JSONObject resp;
    int result;
    String requestString = this.buildCaptureParameters(apiParameters, captureParameters);
    CaptureResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    HTTPResponse httpResponse = HTTPClient.httpPost(url, requestString, ContentType.APPLICATION_XML);
    if (httpResponse.getStatusCode() == -1) {
        return httpResponse;
    }
    resp = XMLHelper.toJson(httpResponse.getContent());
    result = resp.getJSONObject("Response").getInt("ResponseCode");
    if (result == 100) {
        successResponse = new CaptureResponse();
        successResponse.setMessage(resp.getJSONObject("Response").getString("Description"));
        successResponse.setTransactionId(resp.getJSONObject("Response").get("TransactionID").toString());
        successResponse.setAmount(amount);
        successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()));
        successResponse.setRefundParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()));
    } else {
        errorResponse.setMessage(resp.getJSONObject("Response").get("Description").toString());
        errorResponse.setTransactionId(resp.getJSONObject("Response").optString("TransactionID"));
    }
    // final response.
    processFinalResponse(resp, 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