use of uk.gov.pay.api.model.PaymentError in project pay-publicapi by alphagov.
the class RequestJsonParser method validateAndGetSource.
private static Source validateAndGetSource(JsonNode paymentRequest) {
if (paymentRequest.has(INTERNAL)) {
JsonNode internalNode = paymentRequest.get(INTERNAL);
if (internalNode.has(SOURCE_FIELD_NAME)) {
String errorMessage = "Accepted values are only CARD_PAYMENT_LINK, CARD_AGENT_INITIATED_MOTO";
PaymentError paymentError = aPaymentError(SOURCE_FIELD_NAME, CREATE_PAYMENT_VALIDATION_ERROR, errorMessage);
String sourceString = validateSkipNullValueAndGetString(internalNode.get(SOURCE_FIELD_NAME), paymentError);
try {
Source source = Source.valueOf(sourceString);
if (ALLOWED_SOURCES.contains(source)) {
return source;
}
throw new BadRequestException(paymentError);
} catch (IllegalArgumentException e) {
throw new WebApplicationException(Response.status(SC_UNPROCESSABLE_ENTITY).entity(paymentError).build());
}
}
}
return CARD_API;
}
use of uk.gov.pay.api.model.PaymentError in project pay-publicapi by alphagov.
the class CreateRefundExceptionMapper method toResponse.
@Override
public Response toResponse(CreateRefundException exception) {
PaymentError paymentError;
Response.Status status;
if (exception.getErrorStatus() == NOT_FOUND.getStatusCode()) {
paymentError = aPaymentError(CREATE_PAYMENT_REFUND_NOT_FOUND_ERROR);
status = NOT_FOUND;
} else if (exception.getErrorIdentifier() == ErrorIdentifier.REFUND_NOT_AVAILABLE && exception.hasReason()) {
paymentError = aPaymentError(CREATE_PAYMENT_REFUND_NOT_AVAILABLE, exception.getReason());
status = BAD_REQUEST;
} else if (exception.getErrorIdentifier() == ErrorIdentifier.REFUND_AMOUNT_AVAILABLE_MISMATCH) {
paymentError = aPaymentError(CREATE_PAYMENT_REFUND_AMOUNT_AVAILABLE_MISMATCH);
status = PRECONDITION_FAILED;
} else {
paymentError = aPaymentError(CREATE_PAYMENT_REFUND_CONNECTOR_ERROR);
status = INTERNAL_SERVER_ERROR;
}
if (status == INTERNAL_SERVER_ERROR) {
LOGGER.info("Connector invalid response was {}.\n Returning http status {} with error body {}", exception.getMessage(), status, paymentError);
}
return Response.status(status).entity(paymentError).build();
}
use of uk.gov.pay.api.model.PaymentError in project pay-publicapi by alphagov.
the class ViolationExceptionMapper method toResponse.
@Override
public Response toResponse(JerseyViolationException exception) {
LOGGER.info(exception.getMessage());
ConstraintViolation<?> firstException = exception.getConstraintViolations().iterator().next();
String fieldName = getApiFieldName(firstException.getPropertyPath());
PaymentError paymentError;
if (firstException.getConstraintDescriptor() != null && firstException.getConstraintDescriptor().getAnnotation() != null && firstException.getConstraintDescriptor().getAnnotation().annotationType() == NotBlank.class || firstException.getConstraintDescriptor().getAnnotation().annotationType() == NotEmpty.class || firstException.getConstraintDescriptor().getAnnotation().annotationType() == NotNull.class) {
paymentError = PaymentError.aPaymentError(fieldName, CREATE_PAYMENT_MISSING_FIELD_ERROR);
} else {
paymentError = PaymentError.aPaymentError(fieldName, CREATE_PAYMENT_VALIDATION_ERROR, firstException.getMessage());
}
return Response.status(422).entity(paymentError).build();
}
use of uk.gov.pay.api.model.PaymentError in project pay-publicapi by alphagov.
the class GetRefundExceptionMapper method toResponse.
@Override
public Response toResponse(GetRefundException exception) {
PaymentError paymentError;
Response.Status status;
if (exception.getErrorStatus() == NOT_FOUND.getStatusCode()) {
paymentError = aPaymentError(GET_PAYMENT_REFUND_NOT_FOUND_ERROR);
status = NOT_FOUND;
} else {
paymentError = aPaymentError(GET_PAYMENT_REFUND_CONNECTOR_ERROR);
status = INTERNAL_SERVER_ERROR;
LOGGER.error("Connector invalid response was {}.\n Returning http status {} with error body {}", exception.getMessage(), status, paymentError);
}
return Response.status(status).entity(paymentError).build();
}
use of uk.gov.pay.api.model.PaymentError in project pay-publicapi by alphagov.
the class CancelChargeExceptionMapper method toResponse.
@Override
public Response toResponse(CancelChargeException exception) {
int errorStatus = exception.getErrorStatus();
PaymentError paymentError;
Response.Status status;
if (errorStatus == NOT_FOUND.getStatusCode()) {
paymentError = aPaymentError(CANCEL_PAYMENT_NOT_FOUND_ERROR);
status = NOT_FOUND;
} else if (errorStatus == BAD_REQUEST.getStatusCode()) {
paymentError = aPaymentError(CANCEL_PAYMENT_CONNECTOR_BAD_REQUEST_ERROR);
status = BAD_REQUEST;
} else if (errorStatus == CONFLICT.getStatusCode()) {
paymentError = aPaymentError(CANCEL_PAYMENT_CONNECTOR_CONFLICT_ERROR);
status = CONFLICT;
} else {
paymentError = aPaymentError(CANCEL_PAYMENT_CONNECTOR_ERROR);
status = INTERNAL_SERVER_ERROR;
}
if (status == INTERNAL_SERVER_ERROR) {
LOGGER.error("Connector invalid response was {}.\n Returning http status {} with error body {}", exception.getMessage(), status, paymentError);
}
return Response.status(status).entity(paymentError).build();
}
Aggregations