use of uk.gov.pay.api.exception.BadRequestException 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.exception.BadRequestException in project pay-publicapi by alphagov.
the class CreatePaymentRefundRequestDeserializerTest method deserialize_shouldThrowBadRequestException_whenJsonIsNotWellFormed.
@Test
public void deserialize_shouldThrowBadRequestException_whenJsonIsNotWellFormed() throws Exception {
String invalidJson = "{" + " \"amount\" : " + "}";
BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> deserializer.deserialize(jsonFactory.createParser(invalidJson), ctx));
assertThat(badRequestException, aBadRequestExceptionWithError("P0697", "Unable to parse JSON"));
}
use of uk.gov.pay.api.exception.BadRequestException in project pay-publicapi by alphagov.
the class CreatePaymentRefundRequestDeserializerTest method deserialize_shouldThrowValidationException_whenAmountIsNotInteger.
@Test
public void deserialize_shouldThrowValidationException_whenAmountIsNotInteger() throws Exception {
String json = "{" + " \"amount\" : \"\"" + "}";
BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> deserializer.deserialize(jsonFactory.createParser(json), ctx));
assertThat(badRequestException, aBadRequestExceptionWithError("P0602", "Invalid attribute value: amount. Must be a valid numeric format"));
}
use of uk.gov.pay.api.exception.BadRequestException in project pay-publicapi by alphagov.
the class CreatePaymentRefundRequestDeserializerTest method deserialize_shouldThrowValidationException_asAmountIsMissing_whenAmountIsNullValue.
@Test
public void deserialize_shouldThrowValidationException_asAmountIsMissing_whenAmountIsNullValue() throws Exception {
String json = "{" + " \"amount\" : null" + "}";
BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> deserializer.deserialize(jsonFactory.createParser(json), ctx));
assertThat(badRequestException, aBadRequestExceptionWithError("P0601", "Missing mandatory attribute: amount"));
}
use of uk.gov.pay.api.exception.BadRequestException in project pay-publicapi by alphagov.
the class TransactionSearchServiceTest method shouldThrowBadRequestException.
@Test
public void shouldThrowBadRequestException() {
TransactionSearchParams searchParams = mock(TransactionSearchParams.class);
when(searchParams.getQueryMap()).thenReturn(Map.of("not_supported", "hello"));
BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> transactionSearchService.doSearch(new Account("1", TokenPaymentType.CARD, "a-token-link"), searchParams));
assertThat(badRequestException, aBadRequestExceptionWithError("P0401", "Invalid parameters: not_supported. See Public API documentation for the correct data formats"));
}
Aggregations