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);
}
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);
}
}
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;
}
Aggregations