Search in sources :

Example 1 with BillingExceptionJson

use of org.killbill.billing.jaxrs.json.BillingExceptionJson in project killbill by killbill.

the class JaxRsResourceBase method createPaymentResponse.

protected Response createPaymentResponse(final UriInfo uriInfo, final Payment payment, final TransactionType transactionType, @Nullable final String transactionExternalKey, final HttpServletRequest request) {
    final PaymentTransaction createdTransaction = findCreatedTransaction(payment, transactionType, transactionExternalKey);
    Preconditions.checkNotNull(createdTransaction, "No transaction of type '%s' found", transactionType);
    final ResponseBuilder responseBuilder;
    final BillingExceptionJson exception;
    switch(createdTransaction.getTransactionStatus()) {
        case PENDING:
        case SUCCESS:
            return uriBuilder.buildResponse(uriInfo, PaymentResource.class, "getPayment", payment.getId(), request);
        case PAYMENT_FAILURE:
            // 402 - Payment Required
            responseBuilder = Response.status(402);
            exception = createBillingException(String.format("Payment decline by gateway. Error message: %s", createdTransaction.getGatewayErrorMsg()));
            break;
        case PAYMENT_SYSTEM_OFF:
            // 503 - Service Unavailable
            responseBuilder = Response.status(Status.SERVICE_UNAVAILABLE);
            exception = createBillingException("Payment system is off.");
            break;
        case UNKNOWN:
            // 503 - Service Unavailable
            responseBuilder = Response.status(Status.SERVICE_UNAVAILABLE);
            exception = createBillingException("Payment in unknown status, failed to receive gateway response.");
            break;
        case PLUGIN_FAILURE:
            // 502 - Bad Gateway
            responseBuilder = Response.status(502);
            exception = createBillingException("Failed to submit payment transaction");
            break;
        default:
            // Should never happen
            responseBuilder = Response.serverError();
            exception = createBillingException("This should never have happened!!!");
    }
    addExceptionToResponse(responseBuilder, exception);
    return uriBuilder.buildResponse(responseBuilder, uriInfo, PaymentResource.class, "getPayment", payment.getId(), request);
}
Also used : PaymentTransaction(org.killbill.billing.payment.api.PaymentTransaction) BillingExceptionJson(org.killbill.billing.jaxrs.json.BillingExceptionJson) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Example 2 with BillingExceptionJson

use of org.killbill.billing.jaxrs.json.BillingExceptionJson in project killbill by killbill.

the class ExceptionMapperBase method serializeException.

protected void serializeException(final Exception e, final UriInfo uriInfo, final Response.ResponseBuilder responseBuilder) {
    final boolean withStackTrace = uriInfo.getQueryParameters() != null && "true".equals(uriInfo.getQueryParameters().getFirst(QUERY_WITH_STACK_TRACE));
    final BillingExceptionJson billingExceptionJson = new BillingExceptionJson(e, withStackTrace);
    try {
        final String billingExceptionJsonAsString = mapper.writeValueAsString(billingExceptionJson);
        responseBuilder.entity(billingExceptionJsonAsString).type(MediaType.APPLICATION_JSON);
    } catch (final JsonProcessingException jsonException) {
        log.warn("Unable to serialize exception", jsonException);
        responseBuilder.entity(e.toString()).type(MediaType.TEXT_PLAIN_TYPE);
    }
}
Also used : BillingExceptionJson(org.killbill.billing.jaxrs.json.BillingExceptionJson) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with BillingExceptionJson

use of org.killbill.billing.jaxrs.json.BillingExceptionJson in project killbill by killbill.

the class JaxRsResourceBase method createBillingException.

private BillingExceptionJson createBillingException(final String message) {
    final BillingExceptionJson exception;
    exception = new BillingExceptionJson(PaymentApiException.class.getName(), null, message, null, null, Collections.<StackTraceElementJson>emptyList());
    return exception;
}
Also used : StackTraceElementJson(org.killbill.billing.jaxrs.json.BillingExceptionJson.StackTraceElementJson) BillingExceptionJson(org.killbill.billing.jaxrs.json.BillingExceptionJson)

Aggregations

BillingExceptionJson (org.killbill.billing.jaxrs.json.BillingExceptionJson)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 StackTraceElementJson (org.killbill.billing.jaxrs.json.BillingExceptionJson.StackTraceElementJson)1 PaymentTransaction (org.killbill.billing.payment.api.PaymentTransaction)1