Search in sources :

Example 1 with ChargeEntityFixture.aValidChargeEntity

use of uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity in project pay-connector by alphagov.

the class ChargeEntityTest method shouldAllowAValidStatusTransition.

@Test
public void shouldAllowAValidStatusTransition() {
    ChargeEntity chargeCreated = ChargeEntityFixture.aValidChargeEntity().withStatus(CREATED).build();
    chargeCreated.setStatus(ENTERING_CARD_DETAILS);
    assertThat(chargeCreated.getStatus(), is(ENTERING_CARD_DETAILS.toString()));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Test(org.junit.Test)

Example 2 with ChargeEntityFixture.aValidChargeEntity

use of uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity in project pay-connector by alphagov.

the class ChargeEntityTest method shouldReturnAmountMinusFeeForSuccessfulPayment.

@Test
public void shouldReturnAmountMinusFeeForSuccessfulPayment() {
    ChargeEntity chargeCreated = ChargeEntityFixture.aValidChargeEntity().withAmount(1000L).withFee(Fee.of(FeeType.TRANSACTION, 100L)).withFee(Fee.of(FeeType.RADAR, 10L)).withFee(Fee.of(FeeType.THREE_D_S, 20L)).withStatus(CAPTURED).build();
    Optional<Long> netAmount = chargeCreated.getNetAmount();
    assertThat(netAmount.isPresent(), is(true));
    assertThat(netAmount.get(), is(870L));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Test(org.junit.Test)

Example 3 with ChargeEntityFixture.aValidChargeEntity

use of uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity in project pay-connector by alphagov.

the class ChargeEntityTest method shouldReturnEmptyOptionalWhenThereAreNoFees.

@Test
public void shouldReturnEmptyOptionalWhenThereAreNoFees() {
    ChargeEntity chargeCreated = ChargeEntityFixture.aValidChargeEntity().withAmount(1000L).withStatus(CAPTURED).build();
    Optional<Long> netAmount = chargeCreated.getNetAmount();
    assertThat(netAmount.isPresent(), is(false));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Test(org.junit.Test)

Example 4 with ChargeEntityFixture.aValidChargeEntity

use of uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity in project pay-connector by alphagov.

the class ChargeEntityTest method shouldRejectAnInvalidStatusTransition.

@Test(expected = InvalidStateTransitionException.class)
public void shouldRejectAnInvalidStatusTransition() {
    ChargeEntity chargeCreated = ChargeEntityFixture.aValidChargeEntity().withStatus(CREATED).build();
    chargeCreated.setStatus(CAPTURED);
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Test(org.junit.Test)

Example 5 with ChargeEntityFixture.aValidChargeEntity

use of uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity in project pay-connector by alphagov.

the class ChargeServiceTest method shouldUpdateStateOrProvinceForChargeWhenCountryIsUs.

@Test
public void shouldUpdateStateOrProvinceForChargeWhenCountryIsUs() {
    ChargeEntity chargeSpy = spy(ChargeEntityFixture.aValidChargeEntity().build());
    ChargeEventEntity chargeEvent = mock(ChargeEventEntity.class);
    AuthCardDetails authCardDetails = new AuthCardDetails();
    Address address = new Address();
    address.setCountry("US");
    address.setPostcode("20500");
    authCardDetails.setAddress(address);
    authCardDetails.setCardNo("1234567890");
    when(chargeEvent.getStatus()).thenReturn(ENTERING_CARD_DETAILS);
    when(chargeEvent.getUpdated()).thenReturn(now());
    when(mockedChargeEventDao.persistChargeEventOf(chargeSpy, null)).thenReturn(chargeEvent);
    when(mockedChargeDao.findByExternalId(chargeSpy.getExternalId())).thenReturn(Optional.of(chargeSpy));
    when(mockNorthAmericanRegionMapper.getNorthAmericanRegionForCountry(any(Address.class))).thenAnswer((Answer<Optional<? extends NorthAmericaRegion>>) invocationOnMock -> Optional.of(UsState.WASHINGTON_DC));
    when(chargeSpy.getEvents()).thenReturn(List.of(chargeEvent));
    service.updateChargeAndEmitEventPostAuthorisation(chargeSpy.getExternalId(), ENTERING_CARD_DETAILS, authCardDetails, null, null, null, null, null);
    assertThat(chargeSpy.getCardDetails().getBillingAddress().get().getStateOrProvince(), is("DC"));
}
Also used : UsState(uk.gov.pay.connector.northamericaregion.UsState) TaskQueueService(uk.gov.pay.connector.queue.tasks.TaskQueueService) UriBuilder.fromUri(javax.ws.rs.core.UriBuilder.fromUri) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ZonedDateTime(java.time.ZonedDateTime) TokenDao(uk.gov.pay.connector.token.dao.TokenDao) CREATED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.CREATED) ProviderSessionIdentifier(uk.gov.pay.connector.gateway.model.ProviderSessionIdentifier) Collections.singletonList(java.util.Collections.singletonList) PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) PaymentProviders(uk.gov.pay.connector.gateway.PaymentProviders) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Is.is(org.hamcrest.core.Is.is) JUnitParamsRunner(junitparams.JUnitParamsRunner) UserEmailCollected(uk.gov.pay.connector.events.model.charge.UserEmailCollected) EXTERNAL_AVAILABLE(uk.gov.pay.connector.common.model.api.ExternalChargeRefundAvailability.EXTERNAL_AVAILABLE) ConflictRuntimeException(uk.gov.pay.connector.common.exception.ConflictRuntimeException) TEST(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST) AUTHORISATION_3DS(uk.gov.pay.connector.paymentprocessor.model.OperationType.AUTHORISATION_3DS) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) InvalidForceStateTransitionException(uk.gov.pay.connector.common.exception.InvalidForceStateTransitionException) StatusCorrectedToAuthorisationRejectedToMatchGatewayStatus(uk.gov.pay.connector.events.model.charge.StatusCorrectedToAuthorisationRejectedToMatchGatewayStatus) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) UriInfo(javax.ws.rs.core.UriInfo) Mockito.mock(org.mockito.Mockito.mock) TokenEntity(uk.gov.pay.connector.token.model.domain.TokenEntity) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) AUTHORISATION_REJECTED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.AUTHORISATION_REJECTED) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) ChargeEventEntityBuilder.aChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity.ChargeEventEntityBuilder.aChargeEventEntity) Answer(org.mockito.stubbing.Answer) Charge(uk.gov.pay.connector.charge.model.domain.Charge) CAPTURED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.CAPTURED) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GatewayAccountDao(uk.gov.pay.connector.gatewayaccount.dao.GatewayAccountDao) Mockito.anyString(org.mockito.Mockito.anyString) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) ChargeResponse.aChargeResponseBuilder(uk.gov.pay.connector.charge.model.ChargeResponse.aChargeResponseBuilder) ChargeDao(uk.gov.pay.connector.charge.dao.ChargeDao) AUTHORISATION_3DS_REQUIRED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.AUTHORISATION_3DS_REQUIRED) Test(org.junit.Test) ChargeEventDao(uk.gov.pay.connector.chargeevent.dao.ChargeEventDao) GatewayAccountCredentialState(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialState) ConnectorConfiguration(uk.gov.pay.connector.app.ConnectorConfiguration) Mockito.never(org.mockito.Mockito.never) LedgerService(uk.gov.pay.connector.client.ledger.service.LedgerService) MockitoRule(org.mockito.junit.MockitoRule) AuthCardDetails(uk.gov.pay.connector.gateway.model.AuthCardDetails) After(org.junit.After) StateTransitionService(uk.gov.pay.connector.queue.statetransition.StateTransitionService) ChargeEntityFixture(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture) Gateway3dsInfoObtained(uk.gov.pay.connector.events.model.charge.Gateway3dsInfoObtained) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) ExternalChargeState(uk.gov.pay.connector.common.model.api.ExternalChargeState) NorthAmericaRegion(uk.gov.pay.connector.northamericaregion.NorthAmericaRegion) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) CaptureProcessConfig(uk.gov.pay.connector.app.CaptureProcessConfig) GatewayAccountCredentialsService(uk.gov.pay.connector.gatewayaccountcredentials.service.GatewayAccountCredentialsService) List(java.util.List) Auth3dsRequiredEntity(uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity) StatusCorrectedToCapturedToMatchGatewayStatus(uk.gov.pay.connector.events.model.charge.StatusCorrectedToCapturedToMatchGatewayStatus) GatewayAccountCredentialsEntityFixture(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture) ChargeResponseBuilder(uk.gov.pay.connector.charge.model.ChargeResponse.ChargeResponseBuilder) UTC(java.time.ZoneOffset.UTC) RefundService(uk.gov.pay.connector.refund.service.RefundService) Optional(java.util.Optional) Parameters(junitparams.Parameters) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) EventService(uk.gov.pay.connector.events.EventService) CardExpiryDate(uk.gov.service.payments.commons.model.CardExpiryDate) NorthAmericanRegionMapper(uk.gov.pay.connector.northamericaregion.NorthAmericanRegionMapper) Captor(org.mockito.Captor) AUTHORISATION_ERROR(uk.gov.pay.connector.charge.model.domain.ChargeStatus.AUTHORISATION_ERROR) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) ArgumentCaptor(org.mockito.ArgumentCaptor) ExternalTransactionState(uk.gov.pay.connector.common.model.api.ExternalTransactionState) CardTypeDao(uk.gov.pay.connector.cardtype.dao.CardTypeDao) MockitoJUnit(org.mockito.junit.MockitoJUnit) Address(uk.gov.pay.connector.common.model.domain.Address) ExpectedException(org.junit.rules.ExpectedException) ENTERING_CARD_DETAILS(uk.gov.pay.connector.charge.model.domain.ChargeStatus.ENTERING_CARD_DETAILS) PatchRequestBuilder(uk.gov.pay.connector.common.service.PatchRequestBuilder) LinksConfig(uk.gov.pay.connector.app.LinksConfig) AUTHORISATION_3DS_READY(uk.gov.pay.connector.charge.model.domain.ChargeStatus.AUTHORISATION_3DS_READY) Mockito.when(org.mockito.Mockito.when) TelephoneChargeCreateRequest(uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest) Mockito.verify(org.mockito.Mockito.verify) ChargeCreateRequestBuilder(uk.gov.pay.connector.charge.model.ChargeCreateRequestBuilder) Rule(org.junit.Rule) ZonedDateTime.now(java.time.ZonedDateTime.now) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) StatusCorrectedToAuthorisationErrorToMatchGatewayStatus(uk.gov.pay.connector.events.model.charge.StatusCorrectedToAuthorisationErrorToMatchGatewayStatus) PaymentDetailsEntered(uk.gov.pay.connector.events.model.charge.PaymentDetailsEntered) AUTHORISATION_SUCCESS(uk.gov.pay.connector.charge.model.domain.ChargeStatus.AUTHORISATION_SUCCESS) ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Address(uk.gov.pay.connector.common.model.domain.Address) Optional(java.util.Optional) AuthCardDetails(uk.gov.pay.connector.gateway.model.AuthCardDetails) NorthAmericaRegion(uk.gov.pay.connector.northamericaregion.NorthAmericaRegion) ChargeEventEntityBuilder.aChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity.ChargeEventEntityBuilder.aChargeEventEntity) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)19 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)19 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)9 ChargeEventEntityBuilder.aChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity.ChargeEventEntityBuilder.aChargeEventEntity)9 ZonedDateTime (java.time.ZonedDateTime)3 Parameters (junitparams.Parameters)3 Mockito.anyString (org.mockito.Mockito.anyString)3 AuthCardDetails (uk.gov.pay.connector.gateway.model.AuthCardDetails)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 UTC (java.time.ZoneOffset.UTC)2 ZonedDateTime.now (java.time.ZonedDateTime.now)2 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 UriBuilder.fromUri (javax.ws.rs.core.UriBuilder.fromUri)2 UriInfo (javax.ws.rs.core.UriInfo)2