use of uk.gov.pay.api.model.CreateCardPaymentRequest in project pay-publicapi by alphagov.
the class RequestJsonParserTest method parsePaymentRequest_withReturnUrlAndLanguageAndDelayedCaptureAndMoto_shouldParseSuccessfully.
@Test
public void parsePaymentRequest_withReturnUrlAndLanguageAndDelayedCaptureAndMoto_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" + " \"language\": \"en\",\n" + " \"delayed_capture\": true,\n" + " \"moto\": true\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.getLanguage(), is(Optional.of(SupportedLanguage.ENGLISH)));
assertThat(createPaymentRequest.getDelayedCapture(), is(Optional.of(true)));
assertThat(createPaymentRequest.getMoto(), is(Optional.of(true)));
}
use of uk.gov.pay.api.model.CreateCardPaymentRequest in project pay-publicapi by alphagov.
the class RequestJsonParserTest method parsePaymentRequest_shouldSetSourceToDefaultIfNotInPayload.
@Test
public void parsePaymentRequest_shouldSetSourceToDefaultIfNotInPayload() throws Exception {
// language=JSON
String payload = "{\n" + " \"amount\": 27432,\n" + " \"reference\": \"Some reference\",\n" + " \"description\": \"Some description\",\n" + " \"return_url\": \"https://somewhere.gov.uk/rainbow/1\",\n" + " \"language\": \"en\"\n" + "}";
JsonNode jsonNode = objectMapper.readTree(payload);
CreateCardPaymentRequest paymentRequest = parsePaymentRequest(jsonNode);
assertThat(paymentRequest.getInternal().get().getSource().get(), is(CARD_API));
}
use of uk.gov.pay.api.model.CreateCardPaymentRequest in project pay-publicapi by alphagov.
the class RequestJsonParserTest method parsePaymentRequest_withAllPrefilledCardholderDetails_shouldParseSuccessfully.
@Test
public 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.CreateCardPaymentRequest in project pay-publicapi by alphagov.
the class CreateCardPaymentRequestDeserializerTest method shouldDeserializeARequestAndSetSourceCorrectly.
@Test
public void shouldDeserializeARequestAndSetSourceCorrectly() 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" + "\"internal\": {\n" + "\"source\": \"CARD_PAYMENT_LINK\"\n" + "}" + "}";
CreateCardPaymentRequest paymentRequest = deserializer.deserialize(jsonFactory.createParser(payload), ctx);
assertThat(paymentRequest.getInternal().get().getSource().get(), is(CARD_PAYMENT_LINK));
}
use of uk.gov.pay.api.model.CreateCardPaymentRequest in project pay-publicapi by alphagov.
the class CreateCardPaymentRequestDeserializerTest method shouldDeserializeARequestWithPrefilledCardholderDetailsSuccessfully.
@Test
public 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"));
}
Aggregations