Search in sources :

Example 21 with ChargeEntity

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

the class WorldpayPaymentProviderTest method shouldFailRequestAuthorisationIfCredentialsAreNotCorrect.

@Test
public void shouldFailRequestAuthorisationIfCredentialsAreNotCorrect() {
    WorldpayPaymentProvider paymentProvider = getValidWorldpayPaymentProvider();
    Long gatewayAccountId = 112233L;
    var credentials = Map.of("merchant_id", "non-existent-id", "username", "non-existent-username", "password", "non-existent-password");
    GatewayAccountEntity gatewayAccountEntity = new GatewayAccountEntity(TEST);
    gatewayAccountEntity.setGatewayAccountCredentials(List.of(aGatewayAccountCredentialsEntity().withCredentials(credentials).withGatewayAccountEntity(gatewayAccountEntity).withPaymentProvider(WORLDPAY.getName()).withState(ACTIVE).build()));
    gatewayAccountEntity.setId(gatewayAccountId);
    ChargeEntity charge = aValidChargeEntity().withGatewayAccountEntity(gatewayAccountEntity).build();
    AuthCardDetails authCardDetails = anAuthCardDetails().build();
    CardAuthorisationGatewayRequest request = new CardAuthorisationGatewayRequest(charge, authCardDetails);
    assertFalse(paymentProvider.authorise(request).getBaseResponse().isPresent());
}
Also used : WorldpayPaymentProvider(uk.gov.pay.connector.gateway.worldpay.WorldpayPaymentProvider) ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) AuthCardDetailsFixture.anAuthCardDetails(uk.gov.pay.connector.model.domain.AuthCardDetailsFixture.anAuthCardDetails) AuthCardDetails(uk.gov.pay.connector.gateway.model.AuthCardDetails) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Example 22 with ChargeEntity

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

the class WorldpayPaymentProviderTest method shouldBeAbleToSendAuthorisationRequestForMerchantUsing3dsWithPayerEmail.

@Test
public void shouldBeAbleToSendAuthorisationRequestForMerchantUsing3dsWithPayerEmail() {
    WorldpayPaymentProvider paymentProvider = getValidWorldpayPaymentProvider();
    validGatewayAccount.setRequires3ds(true);
    validGatewayAccount.setSendPayerEmailToGateway(true);
    ChargeEntity charge = aValidChargeEntity().withTransactionId(randomUUID().toString()).withEmail("payer@email.test").withGatewayAccountEntity(validGatewayAccount).build();
    AuthCardDetails authCardDetails = anAuthCardDetails().withCardHolder(MAGIC_CARDHOLDER_NAME_THAT_MAKES_WORLDPAY_TEST_REQUIRE_3DS).build();
    CardAuthorisationGatewayRequest request = new CardAuthorisationGatewayRequest(charge, authCardDetails);
    GatewayResponse<WorldpayOrderStatusResponse> response = paymentProvider.authorise(request);
    assertTrue(response.getBaseResponse().isPresent());
    assertTrue(response.getSessionIdentifier().isPresent());
    response.getBaseResponse().ifPresent(res -> {
        assertThat(res.getGatewayParamsFor3ds().isPresent(), is(true));
        assertThat(res.getGatewayParamsFor3ds().get().toAuth3dsRequiredEntity().getPaRequest(), is(notNullValue()));
        assertThat(res.getGatewayParamsFor3ds().get().toAuth3dsRequiredEntity().getIssuerUrl(), is(notNullValue()));
    });
}
Also used : WorldpayPaymentProvider(uk.gov.pay.connector.gateway.worldpay.WorldpayPaymentProvider) ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) AuthCardDetailsFixture.anAuthCardDetails(uk.gov.pay.connector.model.domain.AuthCardDetailsFixture.anAuthCardDetails) AuthCardDetails(uk.gov.pay.connector.gateway.model.AuthCardDetails) WorldpayOrderStatusResponse(uk.gov.pay.connector.gateway.worldpay.WorldpayOrderStatusResponse) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Example 23 with ChargeEntity

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

the class ChargeService method updateChargeAndEmitEventPostAuthorisation.

ChargeEntity updateChargeAndEmitEventPostAuthorisation(String chargeExternalId, ChargeStatus status, AuthCardDetails authCardDetails, String transactionId, Auth3dsRequiredEntity auth3dsRequiredDetails, ProviderSessionIdentifier sessionIdentifier, WalletType walletType, String emailAddress) {
    updateChargePostAuthorisation(chargeExternalId, status, authCardDetails, transactionId, auth3dsRequiredDetails, sessionIdentifier, walletType, emailAddress);
    ChargeEntity chargeEntity = findChargeByExternalId(chargeExternalId);
    eventService.emitAndRecordEvent(PaymentDetailsEntered.from(chargeEntity));
    return chargeEntity;
}
Also used : TelephoneChargeEntityBuilder.aTelephoneChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity.TelephoneChargeEntityBuilder.aTelephoneChargeEntity) WebChargeEntityBuilder.aWebChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity.WebChargeEntityBuilder.aWebChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity)

Example 24 with ChargeEntity

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

the class EpdqAuthorisationErrorGatewayCleanupService method sweepAndCleanupAuthorisationErrors.

public Map<String, Integer> sweepAndCleanupAuthorisationErrors(int limit) {
    List<ChargeEntity> chargesToCleanUp = chargeDao.findWithPaymentProviderAndStatusIn(EPDQ.getName(), List.of(AUTHORISATION_ERROR, AUTHORISATION_TIMEOUT, AUTHORISATION_UNEXPECTED_ERROR), limit);
    logger.info("Found {} epdq charges to clean up.", chargesToCleanUp.size());
    AtomicInteger successes = new AtomicInteger();
    AtomicInteger failures = new AtomicInteger();
    chargesToCleanUp.forEach(chargeEntity -> {
        try {
            ChargeQueryResponse chargeQueryResponse = queryService.getChargeGatewayStatus(chargeEntity);
            boolean success = cleanUpChargeWithGateway(chargeEntity, chargeQueryResponse);
            if (success) {
                successes.getAndIncrement();
            } else {
                failures.getAndIncrement();
            }
        } catch (WebApplicationException | GatewayException | IllegalArgumentException e) {
            logger.info("Error when querying charge status with gateway: " + e.getMessage(), chargeEntity.getStructuredLoggingArgs());
            failures.getAndIncrement();
        }
    });
    logger.info("Epdq charges cleaned up successfully: {}; epdq charges cleaned up failed: {}", successes.intValue(), failures.intValue());
    return ImmutableMap.of(CLEANUP_SUCCESS, successes.intValue(), CLEANUP_FAILED, failures.intValue());
}
Also used : ChargeQueryResponse(uk.gov.pay.connector.gateway.ChargeQueryResponse) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) WebApplicationException(javax.ws.rs.WebApplicationException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GatewayException(uk.gov.pay.connector.gateway.GatewayException)

Example 25 with ChargeEntity

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

the class StripeNotificationService method processPaymentIntentNotification.

private void processPaymentIntentNotification(StripeNotification notification) {
    try {
        StripePaymentIntent paymentIntent = toPaymentIntent(notification.getObject());
        if (isBlank(paymentIntent.getId())) {
            logger.warn("{} payment intent notification [{}] failed verification because it has no transaction ID", PAYMENT_GATEWAY_NAME, notification);
            return;
        }
        Optional<ChargeEntity> maybeCharge = chargeService.findByProviderAndTransactionId(PAYMENT_GATEWAY_NAME, paymentIntent.getId());
        if (maybeCharge.isEmpty()) {
            logger.info("{} notification for payment intent [{}] could not be verified (associated charge entity not found)", PAYMENT_GATEWAY_NAME, paymentIntent.getId());
            return;
        }
        ChargeEntity charge = maybeCharge.get();
        if (PAYMENT_INTENT_AMOUNT_CAPTURABLE_UPDATED.getType().equals(notification.getType()) && !paymentIntent.getAmountCapturable().equals(charge.getAmount())) {
            logger.error("{} notification for payment intent [{}] does not have amount capturable equal to original charge {}", PAYMENT_GATEWAY_NAME, paymentIntent.getId(), charge.getExternalId());
            return;
        }
        if (isChargeIn3DSRequiredOrReadyState(ChargeStatus.fromString(charge.getStatus()))) {
            executePost3DSAuthorisation(charge, notification.getType(), paymentIntent);
        }
    } catch (StripeParseException e) {
        logger.error("{} notification parsing for payment intent object failed: {}", PAYMENT_GATEWAY_NAME, e);
    }
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) StripePaymentIntent(uk.gov.pay.connector.gateway.stripe.json.StripePaymentIntent)

Aggregations

ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)320 Test (org.junit.Test)208 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)163 Test (org.junit.jupiter.api.Test)50 Charge (uk.gov.pay.connector.charge.model.domain.Charge)40 List (java.util.List)27 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)26 URI (java.net.URI)25 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)25 GatewayOrder (uk.gov.pay.connector.gateway.GatewayOrder)21 CardAuthorisationGatewayRequest (uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest)21 TelephoneChargeCreateRequest (uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest)20 PaymentGatewayName (uk.gov.pay.connector.gateway.PaymentGatewayName)20 RefundEntity (uk.gov.pay.connector.refund.model.domain.RefundEntity)20 Mockito.anyString (org.mockito.Mockito.anyString)19 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)18 Parameters (junitparams.Parameters)16 AuthCardDetails (uk.gov.pay.connector.gateway.model.AuthCardDetails)16 ChargeQueryResponse (uk.gov.pay.connector.gateway.ChargeQueryResponse)15 Optional (java.util.Optional)14