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());
}
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()));
});
}
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;
}
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());
}
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);
}
}
Aggregations