use of uk.gov.pay.api.model.PrefilledCardholderDetails in project pay-publicapi by alphagov.
the class RequestJsonParserTest method parsePaymentRequest_withAllPrefilledCardholderDetails_shouldParseSuccessfully.
@Test
void parsePaymentRequest_withAllPrefilledCardholderDetails_shouldParseSuccessfully() throws Exception {
// language=JSON
String payload = "{\n" + " \"amount\": 1000,\n" + " \"reference\": \"Some reference\",\n" + " \"description\": \"Some description\",\n" + " \"return_url\": \"https://somewhere.gov.uk/rainbow/1\",\n" + "\"email\": \"j.bogs@example.org\",\n" + "\"prefilled_cardholder_details\": {\n" + "\"cardholder_name\": \"J Bogs\",\n" + "\"billing_address\": {\n" + "\"line1\": \"address line 1\",\n" + "\"line2\": \"address line 2\",\n" + "\"city\": \"address city\",\n" + "\"postcode\": \"AB1 CD2\",\n" + "\"country\": \"GB\"\n" + "}" + "}" + "}";
JsonNode jsonNode = objectMapper.readTree(payload);
CreateCardPaymentRequest createPaymentRequest = parsePaymentRequest(jsonNode);
assertThat(createPaymentRequest, is(notNullValue()));
assertThat(createPaymentRequest.getAmount(), is(1000));
assertThat(createPaymentRequest.getReference(), is("Some reference"));
assertThat(createPaymentRequest.getDescription(), is("Some description"));
assertThat(createPaymentRequest.getReturnUrl(), is("https://somewhere.gov.uk/rainbow/1"));
assertThat(createPaymentRequest.getEmail(), is(Optional.of("j.bogs@example.org")));
assertThat(createPaymentRequest.getPrefilledCardholderDetails(), is(notNullValue()));
PrefilledCardholderDetails cardholderDetails = createPaymentRequest.getPrefilledCardholderDetails().get();
assertThat(cardholderDetails.getCardholderName().isPresent(), is(true));
assertThat(cardholderDetails.getCardholderName().get(), is("J Bogs"));
assertThat(cardholderDetails.getBillingAddress().isPresent(), is(true));
Address billingAddress = cardholderDetails.getBillingAddress().get();
assertThat(billingAddress.getLine1(), is("address line 1"));
assertThat(billingAddress.getLine2(), is("address line 2"));
assertThat(billingAddress.getCity(), is("address city"));
assertThat(billingAddress.getPostcode(), is("AB1 CD2"));
assertThat(billingAddress.getCountry(), is("GB"));
}
use of uk.gov.pay.api.model.PrefilledCardholderDetails in project pay-publicapi by alphagov.
the class CreateCardPaymentRequestDeserializerTest method shouldDeserializeARequestWithPrefilledCardholderDetailsSuccessfully.
@Test
void shouldDeserializeARequestWithPrefilledCardholderDetailsSuccessfully() throws Exception {
// language=JSON
String payload = "{\n" + " \"amount\": 1000,\n" + " \"reference\": \"Some reference\",\n" + " \"description\": \"Some description\",\n" + " \"return_url\": \"https://somewhere.gov.uk/rainbow/1\",\n" + "\"email\": \"j.bogs@example.org\",\n" + "\"prefilled_cardholder_details\": {\n" + "\"cardholder_name\": \"J Bogs\",\n" + "\"billing_address\": {\n" + "\"line1\": \"address line 1\",\n" + "\"line2\": null,\n" + "\"city\": \"address city\",\n" + "\"postcode\": \"AB1 CD2\",\n" + "\"country\": \"GB\"\n" + "}" + "}" + "}";
CreateCardPaymentRequest paymentRequest = deserializer.deserialize(jsonFactory.createParser(payload), ctx);
assertThat(paymentRequest.getAmount(), is(1000));
assertThat(paymentRequest.getReference(), is("Some reference"));
assertThat(paymentRequest.getDescription(), is("Some description"));
assertThat(paymentRequest.getReturnUrl(), is("https://somewhere.gov.uk/rainbow/1"));
assertThat(paymentRequest.getLanguage(), is(Optional.empty()));
assertThat(paymentRequest.getDelayedCapture(), is(Optional.empty()));
assertThat(paymentRequest.getEmail(), is(Optional.of("j.bogs@example.org")));
assertThat(paymentRequest.getPrefilledCardholderDetails().isPresent(), is(true));
PrefilledCardholderDetails prefilledCardholderDetails = paymentRequest.getPrefilledCardholderDetails().get();
assertThat(prefilledCardholderDetails.getCardholderName().isPresent(), is(true));
assertThat(prefilledCardholderDetails.getCardholderName().get(), is("J Bogs"));
assertThat(prefilledCardholderDetails.getBillingAddress().isPresent(), is(true));
Address billingAddress = prefilledCardholderDetails.getBillingAddress().get();
assertThat(billingAddress.getLine1(), is("address line 1"));
assertThat(billingAddress.getLine2(), is(nullValue()));
assertThat(billingAddress.getPostcode(), is("AB1 CD2"));
assertThat(billingAddress.getCity(), is("address city"));
assertThat(billingAddress.getCountry(), is("GB"));
}
use of uk.gov.pay.api.model.PrefilledCardholderDetails in project pay-publicapi by alphagov.
the class RequestJsonParserTest method parsePaymentRequest_withSomePrefilledCardholderDetails_shouldParseSuccessfully.
@Test
void parsePaymentRequest_withSomePrefilledCardholderDetails_shouldParseSuccessfully() throws Exception {
// language=JSON
String payload = "{\n" + " \"amount\": 1000,\n" + " \"reference\": \"Some reference\",\n" + " \"description\": \"Some description\",\n" + " \"return_url\": \"https://somewhere.gov.uk/rainbow/1\",\n" + "\"email\": null,\n" + "\"prefilled_cardholder_details\": {\n" + "\"cardholder_name\": null,\n" + "\"billing_address\": {\n" + "\"line1\": \"address line 1\",\n" + "\"line2\": null,\n" + "\"city\": \"address city\",\n" + "\"postcode\": \"AB1 CD2\",\n" + "\"country\": \"GB\"\n" + "}" + "}" + "}";
JsonNode jsonNode = objectMapper.readTree(payload);
CreateCardPaymentRequest createPaymentRequest = parsePaymentRequest(jsonNode);
assertThat(createPaymentRequest, is(notNullValue()));
assertThat(createPaymentRequest.getAmount(), is(1000));
assertThat(createPaymentRequest.getReference(), is("Some reference"));
assertThat(createPaymentRequest.getDescription(), is("Some description"));
assertThat(createPaymentRequest.getReturnUrl(), is("https://somewhere.gov.uk/rainbow/1"));
assertThat(createPaymentRequest.getEmail(), is(Optional.empty()));
assertThat(createPaymentRequest.getPrefilledCardholderDetails(), is(notNullValue()));
assertThat(createPaymentRequest.getPrefilledCardholderDetails().isPresent(), is(true));
PrefilledCardholderDetails cardholderDetails = createPaymentRequest.getPrefilledCardholderDetails().get();
assertThat(cardholderDetails.getCardholderName().isPresent(), is(false));
assertThat(cardholderDetails.getBillingAddress().isPresent(), is(true));
Address billingAddress = cardholderDetails.getBillingAddress().get();
assertThat(billingAddress.getLine1(), is("address line 1"));
assertThat(billingAddress.getLine2(), is(nullValue()));
assertThat(billingAddress.getCity(), is("address city"));
assertThat(billingAddress.getPostcode(), is("AB1 CD2"));
assertThat(billingAddress.getCountry(), is("GB"));
}
Aggregations