Search in sources :

Example 1 with Address

use of uk.gov.pay.api.model.Address in project pay-publicapi by alphagov.

the class ConnectorMockClient method respondOk_whenCreateCharge.

public void respondOk_whenCreateCharge(String gatewayAccountId, CreateChargeRequestParams requestParams) {
    var responseFromConnector = aCreateOrGetChargeResponseFromConnector().withAmount(requestParams.getAmount()).withChargeId("chargeId").withState(new PaymentState("created", false, null, null)).withReturnUrl(requestParams.getReturnUrl()).withDescription(requestParams.getDescription()).withReference(requestParams.getReference()).withPaymentProvider("Sandbox").withGatewayTransactionId("gatewayTransactionId").withCreatedDate(SDF.format(new Date())).withLanguage(SupportedLanguage.ENGLISH).withDelayedCapture(false).withCardDetails(new CardDetails("1234", "123456", "Mr. Payment", "12/19", null, "Mastercard", "debit")).withLink(validGetLink(chargeLocation(gatewayAccountId, "chargeId"), "self")).withLink(validGetLink(nextUrl("chargeTokenId"), "next_url")).withLink(validPostLink(nextUrlPost(), "next_url_post", "application/x-www-form-urlencoded", getChargeIdTokenMap("chargeTokenId")));
    if (!requestParams.getMetadata().isEmpty())
        responseFromConnector.withMetadata(requestParams.getMetadata());
    if (requestParams.getEmail() != null) {
        responseFromConnector.withEmail(requestParams.getEmail());
    }
    if (requestParams.getCardholderName().isPresent() || requestParams.getAddressLine1().isPresent() || requestParams.getAddressLine2().isPresent() || requestParams.getAddressPostcode().isPresent() || requestParams.getAddressCity().isPresent() || requestParams.getAddressCountry().isPresent()) {
        Address billingAddress = new Address(requestParams.getAddressLine1().orElse(null), requestParams.getAddressLine2().orElse(null), requestParams.getAddressPostcode().orElse(null), requestParams.getAddressCity().orElse(null), requestParams.getAddressCountry().orElse(null));
        CardDetails cardDetails = new CardDetails(null, null, requestParams.getCardholderName().orElse(null), null, billingAddress, null, null);
        responseFromConnector.withCardDetails(cardDetails);
    }
    mockCreateCharge(gatewayAccountId, aResponse().withStatus(CREATED_201).withHeader(CONTENT_TYPE, APPLICATION_JSON).withHeader(LOCATION, chargeLocation(gatewayAccountId, "chargeId")).withBody(buildChargeResponse(responseFromConnector.build())));
}
Also used : Address(uk.gov.pay.api.model.Address) PaymentState(uk.gov.pay.api.model.PaymentState) CardDetails(uk.gov.pay.api.model.CardDetails) Date(java.util.Date)

Example 2 with Address

use of uk.gov.pay.api.model.Address in project pay-publicapi by alphagov.

the class CreatePaymentServiceTest method testCreatePayment.

@Test
@PactVerification({ "connector" })
@Pacts(pacts = { "publicapi-connector-create-payment" })
public void testCreatePayment() {
    Map<String, Object> metadata = Map.of("ledger_code", 123, "fund_code", "ISIN122038", "cancellable", false);
    var requestPayload = CreateCardPaymentRequestBuilder.builder().amount(100).returnUrl("https://somewhere.gov.uk/rainbow/1").reference("a reference").description("a description").metadata(new ExternalMetadata(metadata)).delayedCapture(Boolean.TRUE).moto(Boolean.TRUE).language(SupportedLanguage.WELSH).email("joe.bogs@example.org").cardholderName("J. Bogs").addressLine1("address line 1").addressLine2("address line 2").city("address city").postcode("AB1 CD2").country("GB").build();
    PaymentWithAllLinks paymentResponse = createPaymentService.create(account, requestPayload);
    CardPayment payment = (CardPayment) paymentResponse.getPayment();
    assertThat(payment.getPaymentId(), is("ch_ab2341da231434l"));
    assertThat(payment.getAmount(), is(100L));
    assertThat(payment.getReference(), is("a reference"));
    assertThat(payment.getDescription(), is("a description"));
    assertThat(payment.getState(), is(new PaymentState("created", false)));
    assertThat(payment.getReturnUrl().get(), is("https://somewhere.gov.uk/rainbow/1"));
    assertThat(payment.getPaymentProvider(), is("Sandbox"));
    assertThat(payment.getCreatedDate(), is("2016-01-01T12:00:00Z"));
    assertThat(paymentResponse.getLinks().getSelf(), is(new Link("http://publicapi.test.localhost/v1/payments/ch_ab2341da231434l", "GET")));
    assertThat(paymentResponse.getLinks().getNextUrl(), is(new Link("http://frontend_connector/charge/token_1234567asdf", "GET")));
    PostLink expectedLink = new PostLink("http://frontend_connector/charge/", "POST", "application/x-www-form-urlencoded", Collections.singletonMap("chargeTokenId", "token_1234567asdf"));
    assertThat(paymentResponse.getLinks().getNextUrlPost(), is(expectedLink));
    assertThat(payment.getMetadata().getMetadata(), is(metadata));
    assertThat(payment.getDelayedCapture(), is(true));
    assertThat(payment.getLanguage(), is(SupportedLanguage.WELSH));
    assertThat(payment.getEmail().isPresent(), is(true));
    assertThat(payment.getEmail().get(), is("joe.bogs@example.org"));
    assertThat(payment.getCardDetails().isPresent(), is(true));
    assertThat(payment.getCardDetails().get().getCardHolderName(), is("J. Bogs"));
    assertThat(payment.getCardDetails().get().getBillingAddress().isPresent(), is(true));
    Address billingAddress = payment.getCardDetails().get().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"));
}
Also used : CardPayment(uk.gov.pay.api.model.CardPayment) Address(uk.gov.pay.api.model.Address) PaymentWithAllLinks(uk.gov.pay.api.model.links.PaymentWithAllLinks) PaymentState(uk.gov.pay.api.model.PaymentState) ExternalMetadata(uk.gov.service.payments.commons.model.charge.ExternalMetadata) Link(uk.gov.pay.api.model.links.Link) PostLink(uk.gov.pay.api.model.links.PostLink) PostLink(uk.gov.pay.api.model.links.PostLink) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 3 with Address

use of uk.gov.pay.api.model.Address 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"));
}
Also used : CreateCardPaymentRequest(uk.gov.pay.api.model.CreateCardPaymentRequest) Address(uk.gov.pay.api.model.Address) JsonNode(com.fasterxml.jackson.databind.JsonNode) PrefilledCardholderDetails(uk.gov.pay.api.model.PrefilledCardholderDetails) Test(org.junit.jupiter.api.Test)

Example 4 with Address

use of uk.gov.pay.api.model.Address 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"));
}
Also used : CreateCardPaymentRequest(uk.gov.pay.api.model.CreateCardPaymentRequest) Address(uk.gov.pay.api.model.Address) PrefilledCardholderDetails(uk.gov.pay.api.model.PrefilledCardholderDetails) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Address

use of uk.gov.pay.api.model.Address in project pay-publicapi by alphagov.

the class TransactionSearchServiceTest method testSearchTransaction.

@Test
@PactVerification({ "ledger" })
@Pacts(pacts = { "publicapi-ledger-search-transaction" })
public void testSearchTransaction() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "a-token-link");
    TransactionSearchParams searchParams = new TransactionSearchParams();
    TransactionSearchResults searchResults = transactionSearchService.doSearch(account, searchParams);
    PaymentForSearchResult payment = searchResults.getResults().get(0);
    assertThat(payment.getAmount(), is(1000L));
    assertThat(payment.getState(), is(new PaymentState("created", false)));
    assertThat(payment.getDescription(), is("Test description"));
    assertThat(payment.getReference(), is("aReference"));
    assertThat(payment.getLanguage(), is(SupportedLanguage.ENGLISH));
    assertThat(payment.getPaymentId(), is(CHARGE_ID));
    assertThat(payment.getReturnUrl().get(), is("https://example.org"));
    assertThat(payment.getEmail().get(), is("someone@example.org"));
    assertThat(payment.getPaymentProvider(), is("sandbox"));
    assertThat(payment.getCreatedDate(), is("2018-09-22T10:13:16.067Z"));
    assertThat(payment.getDelayedCapture(), is(false));
    assertThat(payment.getCardDetails().get().getCardHolderName(), is("J. Smith"));
    assertThat(payment.getCardDetails().get().getCardBrand(), is(""));
    Address address = payment.getCardDetails().get().getBillingAddress().get();
    assertThat(address.getLine1(), is("line1"));
    assertThat(address.getLine2(), is("line2"));
    assertThat(address.getPostcode(), is("AB1 2CD"));
    assertThat(address.getCity(), is("London"));
    assertThat(address.getCountry(), is("GB"));
    assertThat(payment.getLinks().getSelf().getHref(), containsString("v1/payments/" + CHARGE_ID));
    assertThat(payment.getLinks().getSelf().getMethod(), is("GET"));
    assertThat(payment.getLinks().getRefunds().getHref(), containsString("v1/payments/" + CHARGE_ID + "/refunds"));
    assertThat(payment.getLinks().getRefunds().getMethod(), is("GET"));
    assertThat(searchResults.getCount(), is(1));
    assertThat(searchResults.getTotal(), is(1));
    assertThat(searchResults.getPage(), is(1));
    assertThat(searchResults.getLinks().getSelf().getHref(), containsString("/v1/transactions?display_size=500&page=1"));
    assertThat(searchResults.getLinks().getFirstPage().getHref(), containsString("/v1/transactions?display_size=500&page=1"));
    assertThat(searchResults.getLinks().getLastPage().getHref(), containsString("/v1/transactions?display_size=500&page=1"));
}
Also used : Account(uk.gov.pay.api.auth.Account) TransactionSearchParams(uk.gov.pay.api.ledger.model.TransactionSearchParams) Address(uk.gov.pay.api.model.Address) PaymentForSearchResult(uk.gov.pay.api.model.search.card.PaymentForSearchResult) PaymentState(uk.gov.pay.api.model.PaymentState) TransactionSearchResults(uk.gov.pay.api.ledger.model.TransactionSearchResults) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Aggregations

Address (uk.gov.pay.api.model.Address)9 Test (org.junit.jupiter.api.Test)5 CreateCardPaymentRequest (uk.gov.pay.api.model.CreateCardPaymentRequest)5 Test (org.junit.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 PaymentState (uk.gov.pay.api.model.PaymentState)3 PrefilledCardholderDetails (uk.gov.pay.api.model.PrefilledCardholderDetails)3 PactVerification (au.com.dius.pact.consumer.PactVerification)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 CardDetails (uk.gov.pay.api.model.CardDetails)2 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)2 Date (java.util.Date)1 Matchers.emptyString (org.hamcrest.Matchers.emptyString)1 Account (uk.gov.pay.api.auth.Account)1 PaymentNavigationLinksFixture (uk.gov.pay.api.it.fixtures.PaymentNavigationLinksFixture)1 TransactionSearchParams (uk.gov.pay.api.ledger.model.TransactionSearchParams)1 TransactionSearchResults (uk.gov.pay.api.ledger.model.TransactionSearchResults)1 AuthorisationSummary (uk.gov.pay.api.model.AuthorisationSummary)1 CardPayment (uk.gov.pay.api.model.CardPayment)1 ThreeDSecure (uk.gov.pay.api.model.ThreeDSecure)1