Search in sources :

Example 1 with TEST

use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST in project pay-connector by alphagov.

the class WorldpayRefundHandlerTest method test_refund_request_contains_reference.

@Test
void test_refund_request_contains_reference() throws Exception {
    RefundEntity refundEntity = RefundEntityFixture.aValidRefundEntity().build();
    GatewayAccountCredentialsEntity credentialsEntity = aGatewayAccountCredentialsEntity().withCredentials(Map.of(CREDENTIALS_MERCHANT_ID, "MERCHANTCODE", CREDENTIALS_USERNAME, "worldpay-password", CREDENTIALS_PASSWORD, "password")).withGatewayAccountEntity(gatewayAccountEntity).withPaymentProvider(WORLDPAY.getName()).withState(ACTIVE).build();
    ChargeEntity chargeEntity = chargeEntityFixture.withTransactionId("transaction-id").withGatewayAccountCredentialsEntity(credentialsEntity).withPaymentProvider(WORLDPAY.getName()).build();
    gatewayAccountEntity.setGatewayAccountCredentials(List.of(credentialsEntity));
    when(refundGatewayClient.postRequestFor(any(URI.class), eq(WORLDPAY), eq("test"), any(GatewayOrder.class), anyMap())).thenThrow(new GatewayException.GatewayErrorException("Unexpected HTTP status code 400 from gateway"));
    worldpayRefundHandler.refund(RefundGatewayRequest.valueOf(Charge.from(chargeEntity), refundEntity, gatewayAccountEntity, credentialsEntity));
    String expectedRefundRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE paymentService PUBLIC \"-//WorldPay//DTD WorldPay PaymentService v1//EN\"\n" + "        \"http://dtd.worldpay.com/paymentService_v1.dtd\">\n" + "<paymentService version=\"1.4\" merchantCode=\"MERCHANTCODE\">\n" + "    <modify>\n" + "        <orderModification orderCode=\"transaction-id\">\n" + "            <refund reference=\"" + refundEntity.getExternalId() + "\">\n" + "                <amount currencyCode=\"GBP\" exponent=\"2\" value=\"500\"/>\n" + "            </refund>\n" + "        </orderModification>\n" + "    </modify>\n" + "</paymentService>\n" + "";
    verify(refundGatewayClient).postRequestFor(eq(WORLDPAY_URL), eq(WORLDPAY), eq("test"), argThat(argument -> argument.getPayload().equals(expectedRefundRequest) && argument.getOrderRequestType().equals(OrderRequestType.REFUND)), anyMap());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) CREDENTIALS_MERCHANT_ID(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_MERCHANT_ID) GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) Charge(uk.gov.pay.connector.charge.model.domain.Charge) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) GatewayAccountEntityFixture.aGatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity) ChargeEntityFixture(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture) URI(java.net.URI) CREDENTIALS_PASSWORD(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_PASSWORD) OrderRequestType(uk.gov.pay.connector.gateway.model.OrderRequestType) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) RefundGatewayRequest(uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TEST(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) Mockito.when(org.mockito.Mockito.when) ACTIVE(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialState.ACTIVE) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) CREDENTIALS_USERNAME(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_USERNAME) List(java.util.List) WORLDPAY(uk.gov.pay.connector.gateway.PaymentGatewayName.WORLDPAY) RefundEntityFixture(uk.gov.pay.connector.model.domain.RefundEntityFixture) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) GatewayException(uk.gov.pay.connector.gateway.GatewayException) ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) GatewayException(uk.gov.pay.connector.gateway.GatewayException) URI(java.net.URI) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) Test(org.junit.jupiter.api.Test)

Example 2 with TEST

use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST 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)

Example 3 with TEST

use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST in project pay-connector by alphagov.

the class WorldpayPaymentProviderTest method should_retry_without_exemption_flag_when_authorising_with_exemption_flag_results_in_soft_decline.

@Test
void should_retry_without_exemption_flag_when_authorising_with_exemption_flag_results_in_soft_decline() throws Exception {
    gatewayAccountEntity.setRequires3ds(true);
    gatewayAccountEntity.setIntegrationVersion3ds(1);
    gatewayAccountEntity.setWorldpay3dsFlexCredentialsEntity(aWorldpay3dsFlexCredentialsEntity().withExemptionEngine(true).build());
    chargeEntityFixture.withGatewayAccountEntity(gatewayAccountEntity);
    chargeEntityFixture.withStatus(ChargeStatus.AUTHORISATION_READY);
    String gatewayTransactionId = randomUUID().toString();
    chargeEntityFixture.withGatewayTransactionId(gatewayTransactionId);
    ChargeEntity chargeEntity = chargeEntityFixture.build();
    var cardAuthRequest = new CardAuthorisationGatewayRequest(chargeEntity, anAuthCardDetails().build());
    when(worldpayAuthoriseHandler.authoriseWithExemption(cardAuthRequest)).thenReturn(getGatewayResponse(WORLDPAY_EXEMPTION_REQUEST_SOFT_DECLINE_RESULT_REJECTED_RESPONSE));
    var secondResponse = getGatewayResponse(WORLDPAY_AUTHORISATION_SUCCESS_RESPONSE);
    when(worldpayAuthoriseHandler.authoriseWithoutExemption(cardAuthRequest)).thenReturn(secondResponse);
    GatewayResponse<WorldpayOrderStatusResponse> response = worldpayPaymentProvider.authorise(cardAuthRequest);
    assertTrue(response.getBaseResponse().isPresent());
    assertEquals(secondResponse.getBaseResponse().get(), response.getBaseResponse().get());
    assertNotEquals(cardAuthRequest.getCharge().getGatewayTransactionId(), gatewayTransactionId);
    ArgumentCaptor<LoggingEvent> loggingEventArgumentCaptor = ArgumentCaptor.forClass(LoggingEvent.class);
    verify(mockAppender, times(2)).doAppend(loggingEventArgumentCaptor.capture());
    List<LoggingEvent> logs = loggingEventArgumentCaptor.getAllValues();
    assertTrue(logs.stream().anyMatch(loggingEvent -> {
        String log = format("Authorisation with billing address and with 3DS data and without device data " + "collection result for %s", chargeEntity.getExternalId());
        return loggingEvent.getMessage().contains(log);
    }));
    assertTrue(logs.stream().anyMatch(loggingEvent -> {
        String log = "Worldpay authorisation response (orderCode: transaction-id, lastEvent: REFUSED, " + "exemptionResponse result: REJECTED, exemptionResponse reason: HIGH_RISK)";
        return loggingEvent.getMessage().contains(log);
    }));
    assertTrue(logs.stream().anyMatch(loggingEvent -> loggingEvent.getMessage().contains("AUTHORISATION READY -> AUTHORISATION READY")));
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) BeforeEach(org.junit.jupiter.api.BeforeEach) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) XMLUnmarshaller.unmarshall(uk.gov.pay.connector.gateway.util.XMLUnmarshaller.unmarshall) TestTemplateResourceLoader.load(uk.gov.pay.connector.util.TestTemplateResourceLoader.load) WorldpayWalletAuthorisationHandler(uk.gov.pay.connector.gateway.worldpay.wallets.WorldpayWalletAuthorisationHandler) WORLDPAY_AUTHORISED_INQUIRY_RESPONSE(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_AUTHORISED_INQUIRY_RESPONSE) LoggerFactory(org.slf4j.LoggerFactory) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) GatewayResponseBuilder.responseBuilder(uk.gov.pay.connector.gateway.model.response.GatewayResponse.GatewayResponseBuilder.responseBuilder) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) CREDENTIALS_MERCHANT_ID(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_MERCHANT_ID) WORLDPAY_EXEMPTION_REQUEST_SOFT_DECLINE_RESULT_REJECTED_RESPONSE(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_EXEMPTION_REQUEST_SOFT_DECLINE_RESULT_REJECTED_RESPONSE) ProviderSessionIdentifier(uk.gov.pay.connector.gateway.model.ProviderSessionIdentifier) WORLDPAY_EXEMPTION_REQUEST_REJECTED_AUTHORISED_RESPONSE(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_EXEMPTION_REQUEST_REJECTED_AUTHORISED_RESPONSE) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) HttpCookie(java.net.HttpCookie) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AuthUtil(uk.gov.pay.connector.gateway.util.AuthUtil) EXEMPTION_OUT_OF_SCOPE(uk.gov.pay.connector.paymentprocessor.model.Exemption3ds.EXEMPTION_OUT_OF_SCOPE) AuthorisationRequestSummaryStructuredLogging(uk.gov.pay.connector.gateway.util.AuthorisationRequestSummaryStructuredLogging) AuthCardDetailsFixture.anAuthCardDetails(uk.gov.pay.connector.model.domain.AuthCardDetailsFixture.anAuthCardDetails) WORLDPAY_EXEMPTION_REQUEST_SOFT_DECLINE_RESULT_OUT_OF_SCOPE_RESPONSE(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_EXEMPTION_REQUEST_SOFT_DECLINE_RESULT_OUT_OF_SCOPE_RESPONSE) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) ChargeQueryGatewayRequest(uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest) GatewayAccountEntityFixture.aGatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity) ChargeEntityFixture(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture) URI(java.net.URI) Exemption3ds(uk.gov.pay.connector.paymentprocessor.model.Exemption3ds) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TEST(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST) EXEMPTION_REJECTED(uk.gov.pay.connector.paymentprocessor.model.Exemption3ds.EXEMPTION_REJECTED) WORLDPAY_MACHINE_COOKIE_NAME(uk.gov.pay.connector.gateway.worldpay.WorldpayPaymentProvider.WORLDPAY_MACHINE_COOKIE_NAME) Gateway3DSAuthorisationResponse(uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse) ChargeQueryResponse(uk.gov.pay.connector.gateway.ChargeQueryResponse) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) ACTIVE(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialState.ACTIVE) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) List(java.util.List) Logger(ch.qos.logback.classic.Logger) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AuthorisationRequestSummaryStringifier(uk.gov.pay.connector.gateway.util.AuthorisationRequestSummaryStringifier) Optional(java.util.Optional) EXEMPTION_HONOURED(uk.gov.pay.connector.paymentprocessor.model.Exemption3ds.EXEMPTION_HONOURED) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) Event(uk.gov.pay.connector.events.model.Event) WORLDPAY_VALID_3DS_RESPONSE_AUTH_WORLDPAY_REQUEST(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_VALID_3DS_RESPONSE_AUTH_WORLDPAY_REQUEST) Auth3dsResult(uk.gov.pay.connector.gateway.model.Auth3dsResult) AuthorisationService(uk.gov.pay.connector.paymentprocessor.service.AuthorisationService) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) WORLDPAY_EXEMPTION_REQUEST_HONOURED_RESPONSE(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_EXEMPTION_REQUEST_HONOURED_RESPONSE) WORLDPAY_AUTHORISATION_SUCCESS_RESPONSE(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_AUTHORISATION_SUCCESS_RESPONSE) EventService(uk.gov.pay.connector.events.EventService) Mock(org.mockito.Mock) XMLAssert.assertXMLEqual(org.custommonkey.xmlunit.XMLAssert.assertXMLEqual) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) CardExecutorService(uk.gov.pay.connector.paymentprocessor.service.CardExecutorService) GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) Charge(uk.gov.pay.connector.charge.model.domain.Charge) Gateway3dsExemptionResultObtainedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.Gateway3dsExemptionResultObtainedEventDetails) Auth3dsResponseGatewayRequest(uk.gov.pay.connector.gateway.model.request.Auth3dsResponseGatewayRequest) ArgumentCaptor(org.mockito.ArgumentCaptor) AuthorisationLogger(uk.gov.pay.connector.logging.AuthorisationLogger) Appender(ch.qos.logback.core.Appender) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CREDENTIALS_PASSWORD(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_PASSWORD) Worldpay3dsFlexCredentialsEntityBuilder.aWorldpay3dsFlexCredentialsEntity(uk.gov.pay.connector.gatewayaccount.model.Worldpay3dsFlexCredentialsEntity.Worldpay3dsFlexCredentialsEntityBuilder.aWorldpay3dsFlexCredentialsEntity) GatewayError.gatewayConnectionError(uk.gov.pay.connector.gateway.model.GatewayError.gatewayConnectionError) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) Environment(io.dropwizard.setup.Environment) WORLDPAY_EXEMPTION_REQUEST_DECLINE_RESPONSE(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_EXEMPTION_REQUEST_DECLINE_RESPONSE) ChargeDao(uk.gov.pay.connector.charge.dao.ChargeDao) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) WORLDPAY_3DS_FLEX_RESPONSE(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_3DS_FLEX_RESPONSE) Mockito.verify(org.mockito.Mockito.verify) CREDENTIALS_USERNAME(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_USERNAME) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Level(ch.qos.logback.classic.Level) UUID.randomUUID(java.util.UUID.randomUUID) Mockito.never(org.mockito.Mockito.never) EXEMPTION_NOT_REQUESTED(uk.gov.pay.connector.paymentprocessor.model.Exemption3ds.EXEMPTION_NOT_REQUESTED) WORLDPAY(uk.gov.pay.connector.gateway.PaymentGatewayName.WORLDPAY) GatewayResponse(uk.gov.pay.connector.gateway.model.response.GatewayResponse) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) WORLDPAY_3DS_RESPONSE(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_3DS_RESPONSE) GatewayException(uk.gov.pay.connector.gateway.GatewayException) WORLDPAY_VALID_3DS_FLEX_RESPONSE_AUTH_WORLDPAY_REQUEST(uk.gov.pay.connector.util.TestTemplateResourceLoader.WORLDPAY_VALID_3DS_FLEX_RESPONSE_AUTH_WORLDPAY_REQUEST) ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.jupiter.api.Test)

Example 4 with TEST

use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST in project pay-connector by alphagov.

the class ChargeServiceTest method updateChargeAndEmitEventPostAuthorisation_shouldEmitEventWhenCountryIsInUnitedStates.

@Test
public void updateChargeAndEmitEventPostAuthorisation_shouldEmitEventWhenCountryIsInUnitedStates() {
    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);
    verify(mockEventService).emitAndRecordEvent(PaymentDetailsEntered.from(chargeSpy));
}
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

List (java.util.List)4 Map (java.util.Map)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 Mock (org.mockito.Mock)4 Mockito.verify (org.mockito.Mockito.verify)4 Mockito.when (org.mockito.Mockito.when)4 Charge (uk.gov.pay.connector.charge.model.domain.Charge)4 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)4 ChargeEntityFixture (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture)4 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)4 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)4 TEST (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST)4 Optional (java.util.Optional)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Is.is (org.hamcrest.core.Is.is)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 URI (java.net.URI)2 UTC (java.time.ZoneOffset.UTC)2