Search in sources :

Example 1 with CardDetailsEntity

use of uk.gov.pay.connector.charge.model.CardDetailsEntity in project pay-connector by alphagov.

the class ChargeDaoCardDetailsIT method persist_shouldStoreNullCardTypeDetails.

@Test
public void persist_shouldStoreNullCardTypeDetails() {
    GatewayAccountEntity testAccount = new GatewayAccountEntity(GatewayAccountType.TEST);
    testAccount.setExternalId(randomUuid());
    gatewayAccountDao.persist(testAccount);
    GatewayAccountCredentialsEntity credentialsEntity = aGatewayAccountCredentialsEntity().withCredentials(Map.of("username", "theUsername", "password", "thePassword", "merchant_id", "theMerchantCode")).withGatewayAccountEntity(testAccount).withPaymentProvider(SANDBOX.getName()).withState(ACTIVE).withExternalId(randomUuid()).build();
    gatewayAccountCredentialsDao.persist(credentialsEntity);
    Address billingAddress = AddressFixture.anAddress().build();
    ChargeEntity chargeEntity = ChargeEntityFixture.aValidChargeEntity().withGatewayAccountCredentialsEntity(credentialsEntity).build();
    CardDetailsEntity cardDetailsEntity = new CardDetailsEntity(FirstDigitsCardNumber.of("123456"), LastDigitsCardNumber.of("1258"), "Mr. Pay Mc Payment", CardExpiryDate.valueOf("03/09"), "VISA", null, new AddressEntity(billingAddress));
    chargeEntity.setCardDetails(cardDetailsEntity);
    chargeDao.persist(chargeEntity);
    Map<String, Object> cardDetailsSaved = databaseTestHelper.getChargeCardDetails(chargeEntity.getId());
    assertThat(cardDetailsSaved, hasEntry("card_type", null));
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Address(uk.gov.pay.connector.common.model.domain.Address) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity) Test(org.junit.Test)

Example 2 with CardDetailsEntity

use of uk.gov.pay.connector.charge.model.CardDetailsEntity in project pay-connector by alphagov.

the class ChargeDaoCardDetailsIT method findById_shouldFindCardDetails.

@Test
public void findById_shouldFindCardDetails() {
    long chargeId = nextLong();
    DatabaseFixtures.TestCardDetails testCardDetails = createCardDetailsForChargeWithId(chargeId);
    Optional<ChargeEntity> chargeDaoOptional = chargeDao.findById(chargeId);
    assertThat(chargeDaoOptional.isPresent(), is(true));
    CardDetailsEntity cardDetailsEntity = chargeDaoOptional.get().getCardDetails();
    assertThat(cardDetailsEntity.getCardHolderName(), is(testCardDetails.getCardHolderName()));
    assertThat(cardDetailsEntity.getLastDigitsCardNumber(), is(testCardDetails.getLastDigitsCardNumber()));
    assertThat(cardDetailsEntity.getFirstDigitsCardNumber(), is(testCardDetails.getFirstDigitsCardNumber()));
    assertThat(cardDetailsEntity.getExpiryDate(), is(testCardDetails.getExpiryDate()));
    assertThat(cardDetailsEntity.getBillingAddress().isPresent(), is(true));
    assertThat(cardDetailsEntity.getBillingAddress().get().getLine1(), is(testCardDetails.getBillingAddress().getLine1()));
    assertThat(cardDetailsEntity.getBillingAddress().get().getLine2(), is(testCardDetails.getBillingAddress().getLine2()));
    assertThat(cardDetailsEntity.getBillingAddress().get().getPostcode(), is(testCardDetails.getBillingAddress().getPostcode()));
    assertThat(cardDetailsEntity.getBillingAddress().get().getCity(), is(testCardDetails.getBillingAddress().getCity()));
    assertThat(cardDetailsEntity.getBillingAddress().get().getCounty(), is(testCardDetails.getBillingAddress().getCounty()));
    assertThat(cardDetailsEntity.getBillingAddress().get().getCountry(), is(testCardDetails.getBillingAddress().getCountry()));
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity) Test(org.junit.Test)

Example 3 with CardDetailsEntity

use of uk.gov.pay.connector.charge.model.CardDetailsEntity in project pay-connector by alphagov.

the class ChargeDaoCardDetailsIT method persist_shouldStoreCardDetails.

@Test
public void persist_shouldStoreCardDetails() {
    GatewayAccountEntity testAccount = new GatewayAccountEntity(GatewayAccountType.TEST);
    testAccount.setExternalId(randomUuid());
    gatewayAccountDao.persist(testAccount);
    GatewayAccountCredentialsEntity credentialsEntity = aGatewayAccountCredentialsEntity().withCredentials(Map.of()).withGatewayAccountEntity(testAccount).withPaymentProvider(SANDBOX.getName()).withState(ACTIVE).build();
    credentialsEntity.setExternalId(randomUuid());
    gatewayAccountCredentialsDao.persist(credentialsEntity);
    Address billingAddress = AddressFixture.anAddress().build();
    ChargeEntity chargeEntity = ChargeEntityFixture.aValidChargeEntity().withGatewayAccountCredentialsEntity(credentialsEntity).build();
    CardDetailsEntity cardDetailsEntity = new CardDetailsEntity(FirstDigitsCardNumber.of("123456"), LastDigitsCardNumber.of("1258"), "Mr. Pay Mc Payment", CardExpiryDate.valueOf("03/09"), "VISA", CardType.DEBIT, new AddressEntity(billingAddress));
    chargeEntity.setCardDetails(cardDetailsEntity);
    chargeDao.persist(chargeEntity);
    Map<String, Object> cardDetailsSaved = databaseTestHelper.getChargeCardDetails(chargeEntity.getId());
    assertThat(cardDetailsSaved, hasEntry("card_type", "DEBIT"));
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Address(uk.gov.pay.connector.common.model.domain.Address) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity) Test(org.junit.Test)

Example 4 with CardDetailsEntity

use of uk.gov.pay.connector.charge.model.CardDetailsEntity in project pay-connector by alphagov.

the class CardServiceTest method createNewChargeWith.

protected ChargeEntity createNewChargeWith(Long chargeId, ChargeStatus status) {
    ChargeEntity entity = ChargeEntityFixture.aValidChargeEntity().withId(chargeId).withStatus(status).withEvents(List.of(aChargeEventEntity().withChargeEntity(new ChargeEntity()).withStatus(ChargeStatus.CREATED).withUpdated(ZonedDateTime.now().minusHours(3)).build(), aChargeEventEntity().withChargeEntity(new ChargeEntity()).withStatus(ChargeStatus.AUTHORISATION_SUCCESS).withUpdated(ZonedDateTime.now()).build(), aChargeEventEntity().withChargeEntity(new ChargeEntity()).withStatus(ChargeStatus.ENTERING_CARD_DETAILS).withUpdated(ZonedDateTime.now().minusHours(2)).build(), aChargeEventEntity().withChargeEntity(new ChargeEntity()).withStatus(ChargeStatus.AUTHORISATION_TIMEOUT).withUpdated(ZonedDateTime.now().minusHours(1)).build(), aChargeEventEntity().withChargeEntity(new ChargeEntity()).withStatus(ChargeStatus.AUTHORISATION_ERROR).withUpdated(ZonedDateTime.now().minusHours(1)).build(), aChargeEventEntity().withChargeEntity(new ChargeEntity()).withStatus(ChargeStatus.AUTHORISATION_3DS_REQUIRED).withUpdated(ZonedDateTime.now().minusHours(1)).build(), aChargeEventEntity().withChargeEntity(new ChargeEntity()).withStatus(ChargeStatus.AUTHORISATION_CANCELLED).withUpdated(ZonedDateTime.now().minusHours(1)).build(), aChargeEventEntity().withChargeEntity(new ChargeEntity()).withStatus(ChargeStatus.AUTHORISATION_REJECTED).withUpdated(ZonedDateTime.now().minusHours(1)).build(), aChargeEventEntity().withChargeEntity(new ChargeEntity()).withStatus(ChargeStatus.AUTHORISATION_UNEXPECTED_ERROR).withUpdated(ZonedDateTime.now().minusHours(1)).build())).build();
    entity.setCardDetails(new CardDetailsEntity());
    return entity;
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity)

Example 5 with CardDetailsEntity

use of uk.gov.pay.connector.charge.model.CardDetailsEntity in project pay-connector by alphagov.

the class HistoricalEventEmitterServiceTest method setUp.

@Before
public void setUp() {
    connectorConfiguration = new ConnectorConfiguration();
    historicalEventEmitterService = new HistoricalEventEmitterService(chargeDao, refundDao, chargeEventDao, emittedEventDao, stateTransitionService, eventService, chargeService, connectorConfiguration);
    CardDetailsEntity cardDetails = mock(CardDetailsEntity.class);
    when(cardDetails.getLastDigitsCardNumber()).thenReturn(LastDigitsCardNumber.of("1234"));
    chargeEntity = ChargeEntityFixture.aValidChargeEntity().withCardDetails(cardDetails).build();
    ChargeEventEntity chargeEventEntity = ChargeEventEntityFixture.aValidChargeEventEntity().withTimestamp(ZonedDateTime.ofInstant(chargeEntity.getCreatedDate(), ZoneOffset.UTC)).withCharge(chargeEntity).withChargeStatus(ChargeStatus.CREATED).build();
    chargeEntity.getEvents().add(chargeEventEntity);
}
Also used : ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) ConnectorConfiguration(uk.gov.pay.connector.app.ConnectorConfiguration) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity) Before(org.junit.Before)

Aggregations

CardDetailsEntity (uk.gov.pay.connector.charge.model.CardDetailsEntity)21 Test (org.junit.Test)11 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)9 CardBrandLabelEntity (uk.gov.pay.connector.cardtype.model.domain.CardBrandLabelEntity)4 AddressEntity (uk.gov.pay.connector.charge.model.AddressEntity)4 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)3 Address (uk.gov.pay.connector.common.model.domain.Address)3 AuthCardDetails (uk.gov.pay.connector.gateway.model.AuthCardDetails)3 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)3 GatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity)3 CardServiceTest (uk.gov.pay.connector.paymentprocessor.service.CardServiceTest)3 ChargeResponse (uk.gov.pay.connector.charge.model.ChargeResponse)2 GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity)2 Transactional (com.google.inject.persist.Transactional)1 UTC (java.time.ZoneOffset.UTC)1 ZonedDateTime (java.time.ZonedDateTime)1 List (java.util.List)1 Objects.nonNull (java.util.Objects.nonNull)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Collectors (java.util.stream.Collectors)1