use of uk.gov.pay.connector.gateway.ChargeQueryResponse in project pay-connector by alphagov.
the class EpdqPaymentProviderTest method shouldReturnQueryResponseWhenChargeNotFound.
@Test
public void shouldReturnQueryResponseWhenChargeNotFound() throws Exception {
setUpAndCheckThatEpdqIsUp();
ChargeQueryGatewayRequest chargeQueryGatewayRequest = ChargeQueryGatewayRequest.valueOf(Charge.from(chargeEntity), chargeEntity.getGatewayAccount(), chargeEntity.getGatewayAccountCredentialsEntity());
ChargeQueryResponse chargeQueryResponse = paymentProvider.queryPaymentStatus(chargeQueryGatewayRequest);
assertThat(chargeQueryResponse.getMappedStatus(), is(Optional.empty()));
assertThat(chargeQueryResponse.foundCharge(), is(false));
}
use of uk.gov.pay.connector.gateway.ChargeQueryResponse in project pay-connector by alphagov.
the class EpdqPaymentProviderTest method shouldQueryPaymentStatusSuccessfully.
@Test
public void shouldQueryPaymentStatusSuccessfully() throws Exception {
setUpAndCheckThatEpdqIsUp();
var request = new CardAuthorisationGatewayRequest(chargeEntity, authCardDetailsFixture().build());
GatewayResponse<BaseAuthoriseResponse> response = paymentProvider.authorise(request);
assertThat(response.isSuccessful(), is(true));
ChargeQueryGatewayRequest chargeQueryGatewayRequest = ChargeQueryGatewayRequest.valueOf(Charge.from(chargeEntity), chargeEntity.getGatewayAccount(), chargeEntity.getGatewayAccountCredentialsEntity());
ChargeQueryResponse chargeQueryResponse = paymentProvider.queryPaymentStatus(chargeQueryGatewayRequest);
assertThat(chargeQueryResponse.getMappedStatus(), is(Optional.of(ChargeStatus.AUTHORISATION_SUCCESS)));
assertThat(chargeQueryResponse.foundCharge(), is(true));
}
use of uk.gov.pay.connector.gateway.ChargeQueryResponse 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.gateway.ChargeQueryResponse in project pay-connector by alphagov.
the class EpdqPaymentProvider method queryPaymentStatus.
public ChargeQueryResponse queryPaymentStatus(ChargeQueryGatewayRequest chargeQueryGatewayRequest) throws GatewayException {
URI url = URI.create(String.format("%s/%s", gatewayUrlMap.get(chargeQueryGatewayRequest.getGatewayAccount().getType()), ROUTE_FOR_QUERY_ORDER));
GatewayClient.Response response = authoriseClient.postRequestFor(url, EPDQ, chargeQueryGatewayRequest.getGatewayAccount().getType(), buildQueryOrderRequestFor(chargeQueryGatewayRequest), getGatewayAccountCredentialsAsAuthHeader(chargeQueryGatewayRequest.getGatewayCredentials()));
GatewayResponse<EpdqQueryResponse> epdqGatewayResponse = getUninterpretedEpdqGatewayResponse(response, EpdqQueryResponse.class);
return epdqGatewayResponse.getBaseResponse().map(epdqQueryResponse -> {
ChargeStatus mappedStatus = EpdqStatusMapper.map(epdqQueryResponse.getStatus());
return new ChargeQueryResponse(mappedStatus, epdqQueryResponse);
}).orElseThrow(() -> new WebApplicationException(String.format("Unable to query charge %s - an error occurred: %s", chargeQueryGatewayRequest.getChargeExternalId(), epdqGatewayResponse)));
}
use of uk.gov.pay.connector.gateway.ChargeQueryResponse in project pay-connector by alphagov.
the class DiscrepancyServiceTest method aChargeShouldNotBeCancellable_whenPayStatusIsSuccess.
@Test
void aChargeShouldNotBeCancellable_whenPayStatusIsSuccess() throws GatewayException {
ChargeEntity charge = ChargeEntityFixture.aValidChargeEntity().withCreatedDate(Instant.now().minus(Duration.ofDays(3))).withStatus(CAPTURED).build();
ChargeQueryResponse chargeQueryResponse = new ChargeQueryResponse(AUTHORISATION_SUCCESS, mockGatewayResponse);
assertChargeIsNotCancelled(charge, chargeQueryResponse);
}
Aggregations