Search in sources :

Example 11 with HTTPResponse

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

the class PayeezyGateway method refund.

@Override
public HTTPResponse refund(JSONObject apiParameters, JSONObject refundParameters, float amount) {
    JSONObject resp = null;
    String requestString = this.buildRefundParameters(apiParameters, refundParameters, amount);
    RefundResponse 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 RefundResponse();
            successResponse.setMessage(resp.getJSONObject("TransactionResult").getString("Bank_Message"));
            successResponse.setTransactionId(resp.getJSONObject("TransactionResult").get("Transaction_Tag").toString());
            successResponse.setAmount(amount);
            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;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse) RefundResponse(com.tranxactive.j2pay.gateways.responses.RefundResponse) ErrorResponse(com.tranxactive.j2pay.gateways.responses.ErrorResponse)

Example 12 with HTTPResponse

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

the class PayeezyGateway method capture.

@Override
public HTTPResponse capture(JSONObject apiParameters, JSONObject captureParameters, float amount) {
    JSONObject resp = null;
    String requestString = this.buildCaptureParameters(apiParameters, captureParameters, amount);
    CaptureResponse 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 CaptureResponse();
            successResponse.setMessage(resp.getJSONObject("TransactionResult").getString("Bank_Message"));
            successResponse.setTransactionId(resp.getJSONObject("TransactionResult").get("Transaction_Tag").toString());
            successResponse.setAmount(amount);
            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;
}
Also used : JSONObject(org.json.JSONObject) CaptureResponse(com.tranxactive.j2pay.gateways.responses.CaptureResponse) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse) ErrorResponse(com.tranxactive.j2pay.gateways.responses.ErrorResponse)

Example 13 with HTTPResponse

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

the class PayeezyGateway method authorize.

@Override
public HTTPResponse authorize(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
    JSONObject resp = null;
    String requestString = this.buildAuthParameters(apiParameters, customer, customerCard, currency, amount);
    AuthResponse 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 AuthResponse();
            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.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()).put("authorizationNumber", resp.getJSONObject("TransactionResult").get("Authorization_Num").toString()).put(ParamList.AMOUNT.getName(), amount));
            successResponse.setCaptureParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), successResponse.getTransactionId()).put("authorizationNumber", resp.getJSONObject("TransactionResult").get("Authorization_Num").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;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse) AuthResponse(com.tranxactive.j2pay.gateways.responses.AuthResponse) ErrorResponse(com.tranxactive.j2pay.gateways.responses.ErrorResponse)

Example 14 with HTTPResponse

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

the class AuthorizeGateway method authorize.

@Override
public HTTPResponse authorize(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
    JSONObject resp;
    String requestString = this.buildAuthorizeParameters(apiParameters, customer, customerCard, currency, amount);
    AuthResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    HTTPResponse httpResponse;
    int result;
    httpResponse = HTTPClient.httpPost(this.getApiURL(), requestString, ContentType.APPLICATION_XML);
    if (httpResponse.getStatusCode() == -1) {
        return httpResponse;
    }
    resp = XMLHelper.toJson(httpResponse.getContent());
    if (resp.has("createTransactionResponse")) {
        if (resp.getJSONObject("createTransactionResponse").get("transactionResponse") instanceof JSONObject) {
            result = resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getInt("responseCode");
            if (result == 1) {
                successResponse = new AuthResponse();
                successResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getJSONObject("messages").getJSONObject("message").getString("description"));
                successResponse.setTransactionId(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString());
                successResponse.setCardValuesFrom(customerCard);
                successResponse.setAmount(amount);
                successResponse.setCurrencyCode(currency);
                if (resp.getJSONObject("createTransactionResponse").getJSONObject("profileResponse").has("customerProfileId")) {
                    successResponse.setRebillParams(new JSONObject().put("customerProfileId", resp.getJSONObject("createTransactionResponse").getJSONObject("profileResponse").get("customerProfileId").toString()).put("paymentProfileId", resp.getJSONObject("createTransactionResponse").getJSONObject("profileResponse").getJSONObject("customerPaymentProfileIdList").get("numericString").toString()));
                } else {
                    successResponse.setRebillParams(null);
                }
                successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString()));
                successResponse.setCaptureParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString()));
            } else {
                errorResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getJSONObject("errors").getJSONObject("error").getString("errorText"));
            }
        } else {
            errorResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("messages").getJSONObject("message").getString("text"));
        }
    } else {
        errorResponse.setMessage(resp.getJSONObject("ErrorResponse").getJSONObject("messages").getJSONObject("message").getString("text"));
    }
    if (successResponse == null) {
        if (resp.has("createTransactionResponse") && resp.getJSONObject("createTransactionResponse").has("transactionResponse") && resp.getJSONObject("createTransactionResponse").get("transactionResponse") instanceof JSONObject && resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").has("transId")) {
            errorResponse.setTransactionId(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").optString("transId"));
        }
    }
    // final response.
    processFinalResponse(resp, httpResponse, successResponse, errorResponse);
    return httpResponse;
}
Also used : JSONObject(org.json.JSONObject) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse)

Example 15 with HTTPResponse

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

the class AuthorizeGateway method refund.

@Override
public HTTPResponse refund(JSONObject apiParameters, JSONObject refundParameters, float amount) {
    JSONObject resp;
    String requestString = this.buildRefundParameters(apiParameters, refundParameters, amount);
    RefundResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    HTTPResponse httpResponse;
    int result;
    httpResponse = HTTPClient.httpPost(this.getApiURL(), requestString, ContentType.APPLICATION_XML);
    if (httpResponse.getStatusCode() == -1) {
        return httpResponse;
    }
    resp = XMLHelper.toJson(httpResponse.getContent());
    if (resp.has("createTransactionResponse")) {
        if (resp.getJSONObject("createTransactionResponse").get("transactionResponse") instanceof JSONObject) {
            result = resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getInt("responseCode");
            if (result == 1) {
                successResponse = new RefundResponse();
                successResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getJSONObject("messages").getJSONObject("message").getString("description"));
                successResponse.setTransactionId(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString());
                successResponse.setAmount(amount);
                successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").get("transId").toString()));
            } else {
                errorResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").getJSONObject("errors").getJSONObject("error").getString("errorText"));
            }
        } else {
            errorResponse.setMessage(resp.getJSONObject("createTransactionResponse").getJSONObject("messages").getJSONObject("message").getString("text"));
        }
    } else {
        errorResponse.setMessage(resp.getJSONObject("ErrorResponse").getJSONObject("messages").getJSONObject("message").getString("text"));
    }
    if (successResponse == null) {
        if (resp.has("createTransactionResponse") && resp.getJSONObject("createTransactionResponse").has("transactionResponse") && resp.getJSONObject("createTransactionResponse").get("transactionResponse") instanceof JSONObject && resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").has("transId")) {
            errorResponse.setTransactionId(resp.getJSONObject("createTransactionResponse").getJSONObject("transactionResponse").optString("transId"));
        }
    }
    // 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