Search in sources :

Example 1 with PrefilledAddress

use of uk.gov.pay.connector.common.model.domain.PrefilledAddress in project pay-connector by alphagov.

the class ChargeServiceCreateTest method shouldCreateAChargeWithNoCountryWhenPrefilledAddressCountryIsMoreThanTwoCharacters.

@Test
public void shouldCreateAChargeWithNoCountryWhenPrefilledAddressCountryIsMoreThanTwoCharacters() {
    doAnswer(invocation -> fromUri(SERVICE_HOST)).when(this.mockedUriInfo).getBaseUriBuilder();
    when(mockedLinksConfig.getFrontendUrl()).thenReturn("http://frontend.test");
    when(mockedProviders.byName(any(PaymentGatewayName.class))).thenReturn(mockedPaymentProvider);
    when(mockedPaymentProvider.getExternalChargeRefundAvailability(any(Charge.class), any(List.class))).thenReturn(EXTERNAL_AVAILABLE);
    when(mockedGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(gatewayAccount));
    when(mockGatewayAccountCredentialsService.getCurrentOrActiveCredential(gatewayAccount)).thenReturn(gatewayAccountCredentialsEntity);
    var cardHolderDetails = new PrefilledCardHolderDetails();
    cardHolderDetails.setCardHolderName("Joe Bogs");
    var address = new PrefilledAddress("Line1", "Line2", "AB1 CD2", "London", "county", "123");
    cardHolderDetails.setAddress(address);
    ChargeCreateRequest request = requestBuilder.withPrefilledCardHolderDetails(cardHolderDetails).build();
    service.create(request, GATEWAY_ACCOUNT_ID, mockedUriInfo);
    verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture());
    ChargeEntity createdChargeEntity = chargeEntityArgumentCaptor.getValue();
    assertThat(createdChargeEntity.getCardDetails(), is(notNullValue()));
    assertThat(createdChargeEntity.getCardDetails().getBillingAddress().isPresent(), is(true));
    assertThat(createdChargeEntity.getCardDetails().getCardHolderName(), is("Joe Bogs"));
    AddressEntity addressEntity = createdChargeEntity.getCardDetails().getBillingAddress().get();
    assertThat(addressEntity.getLine1(), is("Line1"));
    assertThat(addressEntity.getLine2(), is("Line2"));
    assertThat(addressEntity.getPostcode(), is("AB1 CD2"));
    assertThat(addressEntity.getCity(), is("London"));
    assertThat(addressEntity.getCounty(), is("county"));
    assertThat(addressEntity.getCountry(), is(nullValue()));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) ChargeCreateRequest(uk.gov.pay.connector.charge.model.ChargeCreateRequest) TelephoneChargeCreateRequest(uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest) PrefilledAddress(uk.gov.pay.connector.common.model.domain.PrefilledAddress) Charge(uk.gov.pay.connector.charge.model.domain.Charge) List(java.util.List) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) PrefilledCardHolderDetails(uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails) Test(org.junit.Test)

Example 2 with PrefilledAddress

use of uk.gov.pay.connector.common.model.domain.PrefilledAddress in project pay-connector by alphagov.

the class ChargeService method createCardDetailsEntity.

private CardDetailsEntity createCardDetailsEntity(PrefilledCardHolderDetails prefilledCardHolderDetails) {
    CardDetailsEntity cardDetailsEntity = new CardDetailsEntity();
    prefilledCardHolderDetails.getCardHolderName().ifPresent(cardDetailsEntity::setCardHolderName);
    prefilledCardHolderDetails.getAddress().map(PrefilledAddress::toAddress).map(AddressEntity::new).ifPresent(cardDetailsEntity::setBillingAddress);
    return cardDetailsEntity;
}
Also used : PrefilledAddress(uk.gov.pay.connector.common.model.domain.PrefilledAddress) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity)

Example 3 with PrefilledAddress

use of uk.gov.pay.connector.common.model.domain.PrefilledAddress in project pay-connector by alphagov.

the class ChargeServiceCreateTest method shouldCreateAChargeWithAllPrefilledCardHolderDetails.

@Test
public void shouldCreateAChargeWithAllPrefilledCardHolderDetails() {
    doAnswer(invocation -> fromUri(SERVICE_HOST)).when(this.mockedUriInfo).getBaseUriBuilder();
    when(mockedLinksConfig.getFrontendUrl()).thenReturn("http://frontend.test");
    when(mockedProviders.byName(any(PaymentGatewayName.class))).thenReturn(mockedPaymentProvider);
    when(mockedPaymentProvider.getExternalChargeRefundAvailability(any(Charge.class), any(List.class))).thenReturn(EXTERNAL_AVAILABLE);
    when(mockedGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(gatewayAccount));
    when(mockGatewayAccountCredentialsService.getCurrentOrActiveCredential(gatewayAccount)).thenReturn(gatewayAccountCredentialsEntity);
    var cardHolderDetails = new PrefilledCardHolderDetails();
    cardHolderDetails.setCardHolderName("Joe Bogs");
    var address = new PrefilledAddress("Line1", "Line2", "AB1 CD2", "London", null, "GB");
    cardHolderDetails.setAddress(address);
    final ChargeCreateRequest request = requestBuilder.withPrefilledCardHolderDetails(cardHolderDetails).build();
    service.create(request, GATEWAY_ACCOUNT_ID, mockedUriInfo);
    verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture());
    ChargeEntity createdChargeEntity = chargeEntityArgumentCaptor.getValue();
    assertThat(createdChargeEntity.getCardDetails(), is(notNullValue()));
    assertThat(createdChargeEntity.getCardDetails().getBillingAddress().isPresent(), is(true));
    assertThat(createdChargeEntity.getCardDetails().getCardHolderName(), is("Joe Bogs"));
    AddressEntity addressEntity = createdChargeEntity.getCardDetails().getBillingAddress().get();
    assertThat(addressEntity.getCity(), is("London"));
    assertThat(addressEntity.getCountry(), is("GB"));
    assertThat(addressEntity.getLine1(), is("Line1"));
    assertThat(addressEntity.getLine2(), is("Line2"));
    assertThat(addressEntity.getPostcode(), is("AB1 CD2"));
    assertThat(addressEntity.getCounty(), is(nullValue()));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) ChargeCreateRequest(uk.gov.pay.connector.charge.model.ChargeCreateRequest) TelephoneChargeCreateRequest(uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest) PrefilledAddress(uk.gov.pay.connector.common.model.domain.PrefilledAddress) Charge(uk.gov.pay.connector.charge.model.domain.Charge) List(java.util.List) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) PrefilledCardHolderDetails(uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails) Test(org.junit.Test)

Example 4 with PrefilledAddress

use of uk.gov.pay.connector.common.model.domain.PrefilledAddress in project pay-connector by alphagov.

the class ChargeServiceCreateTest method shouldCreateAChargeWithPrefilledCardHolderDetailsAndSomeAddressMissing.

@Test
public void shouldCreateAChargeWithPrefilledCardHolderDetailsAndSomeAddressMissing() {
    doAnswer(invocation -> fromUri(SERVICE_HOST)).when(this.mockedUriInfo).getBaseUriBuilder();
    when(mockedLinksConfig.getFrontendUrl()).thenReturn("http://frontend.test");
    when(mockedProviders.byName(any(PaymentGatewayName.class))).thenReturn(mockedPaymentProvider);
    when(mockedPaymentProvider.getExternalChargeRefundAvailability(any(Charge.class), any(List.class))).thenReturn(EXTERNAL_AVAILABLE);
    when(mockedGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(gatewayAccount));
    when(mockGatewayAccountCredentialsService.getCurrentOrActiveCredential(gatewayAccount)).thenReturn(gatewayAccountCredentialsEntity);
    var cardHolderDetails = new PrefilledCardHolderDetails();
    cardHolderDetails.setCardHolderName("Joe Bogs");
    var address = new PrefilledAddress("Line1", null, "AB1 CD2", "London", null, null);
    cardHolderDetails.setAddress(address);
    ChargeCreateRequest request = requestBuilder.withPrefilledCardHolderDetails(cardHolderDetails).build();
    service.create(request, GATEWAY_ACCOUNT_ID, mockedUriInfo);
    verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture());
    ChargeEntity createdChargeEntity = chargeEntityArgumentCaptor.getValue();
    assertThat(createdChargeEntity.getCardDetails(), is(notNullValue()));
    assertThat(createdChargeEntity.getCardDetails().getBillingAddress().isPresent(), is(true));
    assertThat(createdChargeEntity.getCardDetails().getCardHolderName(), is("Joe Bogs"));
    AddressEntity addressEntity = createdChargeEntity.getCardDetails().getBillingAddress().get();
    assertThat(addressEntity.getLine1(), is("Line1"));
    assertThat(addressEntity.getLine2(), is(nullValue()));
    assertThat(addressEntity.getPostcode(), is("AB1 CD2"));
    assertThat(addressEntity.getCity(), is("London"));
    assertThat(addressEntity.getCounty(), is(nullValue()));
    assertThat(addressEntity.getCountry(), is(nullValue()));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) ChargeCreateRequest(uk.gov.pay.connector.charge.model.ChargeCreateRequest) TelephoneChargeCreateRequest(uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest) PrefilledAddress(uk.gov.pay.connector.common.model.domain.PrefilledAddress) Charge(uk.gov.pay.connector.charge.model.domain.Charge) List(java.util.List) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) PrefilledCardHolderDetails(uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails) Test(org.junit.Test)

Example 5 with PrefilledAddress

use of uk.gov.pay.connector.common.model.domain.PrefilledAddress in project pay-connector by alphagov.

the class ChargeServiceCreateTest method shouldCreateAChargeWhenPrefilledCardHolderDetailsCardholderNameAndSomeAddressNotPresent.

@Test
public void shouldCreateAChargeWhenPrefilledCardHolderDetailsCardholderNameAndSomeAddressNotPresent() {
    doAnswer(invocation -> fromUri(SERVICE_HOST)).when(this.mockedUriInfo).getBaseUriBuilder();
    when(mockedLinksConfig.getFrontendUrl()).thenReturn("http://frontend.test");
    when(mockedProviders.byName(any(PaymentGatewayName.class))).thenReturn(mockedPaymentProvider);
    when(mockedPaymentProvider.getExternalChargeRefundAvailability(any(Charge.class), any(List.class))).thenReturn(EXTERNAL_AVAILABLE);
    when(mockedGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(gatewayAccount));
    when(mockGatewayAccountCredentialsService.getCurrentOrActiveCredential(gatewayAccount)).thenReturn(gatewayAccountCredentialsEntity);
    var cardHolderDetails = new PrefilledCardHolderDetails();
    var address = new PrefilledAddress("Line1", null, "AB1 CD2", "London", null, null);
    cardHolderDetails.setAddress(address);
    ChargeCreateRequest request = requestBuilder.withPrefilledCardHolderDetails(cardHolderDetails).build();
    service.create(request, GATEWAY_ACCOUNT_ID, mockedUriInfo);
    verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture());
    ChargeEntity createdChargeEntity = chargeEntityArgumentCaptor.getValue();
    assertThat(createdChargeEntity.getCardDetails(), is(notNullValue()));
    assertThat(createdChargeEntity.getCardDetails().getBillingAddress().isPresent(), is(true));
    assertThat(createdChargeEntity.getCardDetails().getCardHolderName(), is(nullValue()));
    AddressEntity addressEntity = createdChargeEntity.getCardDetails().getBillingAddress().get();
    assertThat(addressEntity.getLine1(), is("Line1"));
    assertThat(addressEntity.getLine2(), is(nullValue()));
    assertThat(addressEntity.getPostcode(), is("AB1 CD2"));
    assertThat(addressEntity.getCity(), is("London"));
    assertThat(addressEntity.getCounty(), is(nullValue()));
    assertThat(addressEntity.getCountry(), is(nullValue()));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) ChargeCreateRequest(uk.gov.pay.connector.charge.model.ChargeCreateRequest) TelephoneChargeCreateRequest(uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest) PrefilledAddress(uk.gov.pay.connector.common.model.domain.PrefilledAddress) Charge(uk.gov.pay.connector.charge.model.domain.Charge) List(java.util.List) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) PrefilledCardHolderDetails(uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails) Test(org.junit.Test)

Aggregations

PrefilledAddress (uk.gov.pay.connector.common.model.domain.PrefilledAddress)5 List (java.util.List)4 Test (org.junit.Test)4 AddressEntity (uk.gov.pay.connector.charge.model.AddressEntity)4 ChargeCreateRequest (uk.gov.pay.connector.charge.model.ChargeCreateRequest)4 PrefilledCardHolderDetails (uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails)4 Charge (uk.gov.pay.connector.charge.model.domain.Charge)4 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)4 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)4 TelephoneChargeCreateRequest (uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest)4 PaymentGatewayName (uk.gov.pay.connector.gateway.PaymentGatewayName)4 CardDetailsEntity (uk.gov.pay.connector.charge.model.CardDetailsEntity)1