Search in sources :

Example 6 with InvalidSignatureException

use of com.braintreegateway.exceptions.InvalidSignatureException in project J2PAY by tranxactive.

the class BraintreeGateway method capture.

@Override
public HTTPResponse capture(JSONObject apiParameters, JSONObject captureParameters, float amount) {
    boolean hasException = false;
    CaptureResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    HTTPResponse httpResponse = new HTTPResponse();
    Result<Transaction> capture = null;
    try {
        capture = getGatewayObject(apiParameters).transaction().submitForSettlement(captureParameters.getString(ParamList.TRANSACTION_ID.getName()), new BigDecimal(Float.toString(amount)));
    } catch (NotFoundException e) {
        errorResponse.setMessage("No record found");
        hasException = true;
    } catch (AuthenticationException e) {
        errorResponse.setMessage("Invalid credentials");
        hasException = true;
    } catch (AuthorizationException e) {
        errorResponse.setMessage("Not authorized to perform this action");
        hasException = true;
    } catch (ConfigurationException e) {
        errorResponse.setMessage("Configuratoin error");
        hasException = true;
    } catch (DownForMaintenanceException e) {
        errorResponse.setMessage("Server is under maintenance");
        hasException = true;
    } catch (TimeoutException e) {
        errorResponse.setMessage("Request time out");
        hasException = true;
    } catch (ForgedQueryStringException | InvalidChallengeException | InvalidSignatureException | UnexpectedException e) {
        errorResponse.setMessage("Unexpected exception occured");
        hasException = true;
    } catch (ServerException e) {
        errorResponse.setMessage("Server error");
        hasException = true;
    } catch (TooManyRequestsException e) {
        errorResponse.setMessage("Too many requests");
        hasException = true;
    } catch (UpgradeRequiredException e) {
        errorResponse.setMessage("Need to upgrade");
        hasException = true;
    }
    if (hasException) {
        processFinalResponse(null, httpResponse, successResponse, errorResponse);
        return httpResponse;
    }
    if (capture.isSuccess()) {
        successResponse = new CaptureResponse();
        successResponse.setMessage("Success");
        successResponse.setTransactionId(capture.getTarget().getId());
        successResponse.setAmount(amount);
        successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), capture.getTarget().getId()));
        successResponse.setRefundParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), capture.getTarget().getId()));
    } else {
        errorResponse.setMessage(capture.getMessage());
    }
    processFinalResponse(null, httpResponse, successResponse, errorResponse);
    return httpResponse;
}
Also used : InvalidSignatureException(com.braintreegateway.exceptions.InvalidSignatureException) UnexpectedException(com.braintreegateway.exceptions.UnexpectedException) ServerException(com.braintreegateway.exceptions.ServerException) AuthenticationException(com.braintreegateway.exceptions.AuthenticationException) AuthorizationException(com.braintreegateway.exceptions.AuthorizationException) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse) NotFoundException(com.braintreegateway.exceptions.NotFoundException) BigDecimal(java.math.BigDecimal) InvalidChallengeException(com.braintreegateway.exceptions.InvalidChallengeException) ErrorResponse(com.tranxactive.j2pay.gateways.responses.ErrorResponse) UpgradeRequiredException(com.braintreegateway.exceptions.UpgradeRequiredException) TooManyRequestsException(com.braintreegateway.exceptions.TooManyRequestsException) CaptureResponse(com.tranxactive.j2pay.gateways.responses.CaptureResponse) Transaction(com.braintreegateway.Transaction) JSONObject(org.json.JSONObject) ConfigurationException(com.braintreegateway.exceptions.ConfigurationException) ForgedQueryStringException(com.braintreegateway.exceptions.ForgedQueryStringException) DownForMaintenanceException(com.braintreegateway.exceptions.DownForMaintenanceException) TimeoutException(com.braintreegateway.exceptions.TimeoutException)

Example 7 with InvalidSignatureException

use of com.braintreegateway.exceptions.InvalidSignatureException in project J2PAY by tranxactive.

the class BraintreeGateway method rebill.

@Override
public HTTPResponse rebill(JSONObject apiParameters, JSONObject rebillParameters, float amount) {
    boolean hasException = false;
    RebillResponse successResponse = null;
    ErrorResponse errorResponse = new ErrorResponse();
    HTTPResponse httpResponse = new HTTPResponse();
    TransactionRequest transactionRequest = new TransactionRequest();
    transactionRequest.customerId(rebillParameters.getString(CUSTOMER_ID)).amount(new BigDecimal(Float.toString(amount)));
    transactionRequest.options().submitForSettlement(true);
    Result<Transaction> sale = null;
    try {
        sale = getGatewayObject(apiParameters).transaction().sale(transactionRequest);
    } catch (NotFoundException e) {
        errorResponse.setMessage("No record found");
        hasException = true;
    } catch (AuthenticationException e) {
        errorResponse.setMessage("Invalid credentials");
        hasException = true;
    } catch (AuthorizationException e) {
        errorResponse.setMessage("Not authorized to perform this action");
        hasException = true;
    } catch (ConfigurationException e) {
        errorResponse.setMessage("Configuratoin error");
        hasException = true;
    } catch (DownForMaintenanceException e) {
        errorResponse.setMessage("Server is under maintenance");
        hasException = true;
    } catch (TimeoutException e) {
        errorResponse.setMessage("Request time out");
        hasException = true;
    } catch (ForgedQueryStringException | InvalidChallengeException | InvalidSignatureException | UnexpectedException e) {
        errorResponse.setMessage("Unexpected exception occured");
        hasException = true;
    } catch (ServerException e) {
        errorResponse.setMessage("Server error");
        hasException = true;
    } catch (TooManyRequestsException e) {
        errorResponse.setMessage("Too many requests");
        hasException = true;
    } catch (UpgradeRequiredException e) {
        errorResponse.setMessage("Need to upgrade");
        hasException = true;
    }
    if (hasException) {
        processFinalResponse(null, httpResponse, successResponse, errorResponse);
        return httpResponse;
    }
    if (sale.isSuccess()) {
        successResponse = new RebillResponse();
        successResponse.setMessage("Success");
        successResponse.setTransactionId(sale.getTarget().getId());
        successResponse.setAmount(amount);
        successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), sale.getTarget().getId()));
        successResponse.setRebillParams(new JSONObject().put(CUSTOMER_ID, rebillParameters.getString(CUSTOMER_ID)));
        successResponse.setVoidParams(new JSONObject().put(ParamList.TRANSACTION_ID.getName(), sale.getTarget().getId()));
    } else {
        errorResponse.setMessage(sale.getMessage());
    }
    processFinalResponse(null, httpResponse, successResponse, errorResponse);
    return httpResponse;
}
Also used : InvalidSignatureException(com.braintreegateway.exceptions.InvalidSignatureException) UnexpectedException(com.braintreegateway.exceptions.UnexpectedException) ServerException(com.braintreegateway.exceptions.ServerException) AuthenticationException(com.braintreegateway.exceptions.AuthenticationException) AuthorizationException(com.braintreegateway.exceptions.AuthorizationException) HTTPResponse(com.tranxactive.j2pay.net.HTTPResponse) NotFoundException(com.braintreegateway.exceptions.NotFoundException) RebillResponse(com.tranxactive.j2pay.gateways.responses.RebillResponse) TransactionRequest(com.braintreegateway.TransactionRequest) BigDecimal(java.math.BigDecimal) InvalidChallengeException(com.braintreegateway.exceptions.InvalidChallengeException) ErrorResponse(com.tranxactive.j2pay.gateways.responses.ErrorResponse) UpgradeRequiredException(com.braintreegateway.exceptions.UpgradeRequiredException) TooManyRequestsException(com.braintreegateway.exceptions.TooManyRequestsException) Transaction(com.braintreegateway.Transaction) JSONObject(org.json.JSONObject) ConfigurationException(com.braintreegateway.exceptions.ConfigurationException) ForgedQueryStringException(com.braintreegateway.exceptions.ForgedQueryStringException) DownForMaintenanceException(com.braintreegateway.exceptions.DownForMaintenanceException) TimeoutException(com.braintreegateway.exceptions.TimeoutException)

Aggregations

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 ErrorResponse (com.tranxactive.j2pay.gateways.responses.ErrorResponse)7 HTTPResponse (com.tranxactive.j2pay.net.HTTPResponse)7 Transaction (com.braintreegateway.Transaction)6 BigDecimal (java.math.BigDecimal)5 JSONObject (org.json.JSONObject)5 TransactionRequest (com.braintreegateway.TransactionRequest)3 CreditCardAddressRequest (com.braintreegateway.CreditCardAddressRequest)1