Search in sources :

Example 1 with ChargeQueryResponse

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));
}
Also used : ChargeQueryGatewayRequest(uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest) ChargeQueryResponse(uk.gov.pay.connector.gateway.ChargeQueryResponse) Test(org.junit.Test)

Example 2 with ChargeQueryResponse

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));
}
Also used : ChargeQueryGatewayRequest(uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest) ChargeQueryResponse(uk.gov.pay.connector.gateway.ChargeQueryResponse) BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Example 3 with ChargeQueryResponse

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());
}
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 4 with ChargeQueryResponse

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)));
}
Also used : EpdqPayloadDefinitionForCancelOrder(uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForCancelOrder) CREDENTIALS_SHA_IN_PASSPHRASE(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_SHA_IN_PASSPHRASE) LoggerFactory(org.slf4j.LoggerFactory) AUTHORISE(uk.gov.pay.connector.gateway.GatewayOperation.AUTHORISE) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) CREDENTIALS_MERCHANT_ID(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_MERCHANT_ID) PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) Map(java.util.Map) ChargeQueryGatewayRequest(uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest) EpdqCancelResponse(uk.gov.pay.connector.gateway.epdq.model.response.EpdqCancelResponse) URI(java.net.URI) RefundGatewayRequest(uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest) EPDQ(uk.gov.pay.connector.gateway.PaymentGatewayName.EPDQ) BaseResponse(uk.gov.pay.connector.gateway.model.response.BaseResponse) Gateway3DSAuthorisationResponse(uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse) ERROR(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse.AuthoriseStatus.ERROR) ChargeQueryResponse(uk.gov.pay.connector.gateway.ChargeQueryResponse) String.format(java.lang.String.format) List(java.util.List) EpdqQueryResponse(uk.gov.pay.connector.gateway.epdq.model.response.EpdqQueryResponse) BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) CANCEL(uk.gov.pay.connector.gateway.GatewayOperation.CANCEL) WebApplicationException(javax.ws.rs.WebApplicationException) Optional(java.util.Optional) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) EpdqAuthorisationResponse(uk.gov.pay.connector.gateway.epdq.model.response.EpdqAuthorisationResponse) CAPTURE(uk.gov.pay.connector.gateway.GatewayOperation.CAPTURE) GatewayResponseUnmarshaller.unmarshallResponse(uk.gov.pay.connector.gateway.GatewayResponseUnmarshaller.unmarshallResponse) GatewayRefundResponse(uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse) EpdqPayloadDefinitionForQueryOrder(uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForQueryOrder) GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) Inject(javax.inject.Inject) Charge(uk.gov.pay.connector.charge.model.domain.Charge) Auth3dsResponseGatewayRequest(uk.gov.pay.connector.gateway.model.request.Auth3dsResponseGatewayRequest) CaptureGatewayRequest(uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest) GenericGatewayException(uk.gov.pay.connector.gateway.GatewayException.GenericGatewayException) ExternalChargeRefundAvailability(uk.gov.pay.connector.common.model.api.ExternalChargeRefundAvailability) WalletAuthorisationGatewayRequest(uk.gov.pay.connector.wallets.WalletAuthorisationGatewayRequest) CREDENTIALS_PASSWORD(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_PASSWORD) Environment(io.dropwizard.setup.Environment) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) ExternalRefundAvailabilityCalculator(uk.gov.pay.connector.gateway.util.ExternalRefundAvailabilityCalculator) EpdqPayloadDefinitionForNew3dsOrder(uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForNew3dsOrder) AuthUtil.getGatewayAccountCredentialsAsAuthHeader(uk.gov.pay.connector.gateway.util.AuthUtil.getGatewayAccountCredentialsAsAuthHeader) BaseCancelResponse(uk.gov.pay.connector.gateway.model.response.BaseCancelResponse) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) REFUND(uk.gov.pay.connector.gateway.GatewayOperation.REFUND) ConnectorConfiguration(uk.gov.pay.connector.app.ConnectorConfiguration) EpdqExternalRefundAvailabilityCalculator(uk.gov.pay.connector.gateway.util.EpdqExternalRefundAvailabilityCalculator) CREDENTIALS_USERNAME(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_USERNAME) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Auth3dsResultOutcome(uk.gov.pay.connector.gateway.model.Auth3dsResult.Auth3dsResultOutcome) GatewayErrorException(uk.gov.pay.connector.gateway.GatewayException.GatewayErrorException) Refund(uk.gov.pay.connector.refund.model.domain.Refund) CancelGatewayRequest(uk.gov.pay.connector.gateway.model.request.CancelGatewayRequest) GatewayResponse(uk.gov.pay.connector.gateway.model.response.GatewayResponse) GatewayClientFactory(uk.gov.pay.connector.gateway.GatewayClientFactory) EpdqPayloadDefinitionForNew3ds2Order(uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForNew3ds2Order) Clock(java.time.Clock) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) GatewayException(uk.gov.pay.connector.gateway.GatewayException) AuthCardDetails(uk.gov.pay.connector.gateway.model.AuthCardDetails) EpdqPayloadDefinitionForNewOrder(uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForNewOrder) ChargeQueryResponse(uk.gov.pay.connector.gateway.ChargeQueryResponse) EpdqQueryResponse(uk.gov.pay.connector.gateway.epdq.model.response.EpdqQueryResponse) GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) WebApplicationException(javax.ws.rs.WebApplicationException) URI(java.net.URI)

Example 5 with ChargeQueryResponse

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);
}
Also used : ChargeQueryResponse(uk.gov.pay.connector.gateway.ChargeQueryResponse) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Test(org.junit.jupiter.api.Test)

Aggregations

ChargeQueryResponse (uk.gov.pay.connector.gateway.ChargeQueryResponse)25 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)16 Test (org.junit.Test)11 Test (org.junit.jupiter.api.Test)11 ChargeQueryGatewayRequest (uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest)11 Charge (uk.gov.pay.connector.charge.model.domain.Charge)7 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)5 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)5 ChargeEntityFixture.defaultGatewayAccountCredentialsEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.defaultGatewayAccountCredentialsEntity)4 ChargeEntityFixture.defaultGatewayAccountEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.defaultGatewayAccountEntity)4 GatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity)4 URI (java.net.URI)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 ChargeStatus (uk.gov.pay.connector.charge.model.domain.ChargeStatus)3 GatewayException (uk.gov.pay.connector.gateway.GatewayException)3 GatewayOrder (uk.gov.pay.connector.gateway.GatewayOrder)3 GatewayResponse (uk.gov.pay.connector.gateway.model.response.GatewayResponse)3 String.format (java.lang.String.format)2 List (java.util.List)2 Map (java.util.Map)2