Search in sources :

Example 1 with ChargeQueryGatewayRequest

use of uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest 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 ChargeQueryGatewayRequest

use of uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest 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 ChargeQueryGatewayRequest

use of uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest 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 4 with ChargeQueryGatewayRequest

use of uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest in project pay-connector by alphagov.

the class EpdqPaymentProviderIT method shouldSuccessfullyQueryChargeStatus.

@Test
public void shouldSuccessfullyQueryChargeStatus() throws Exception {
    mockPaymentProviderResponse(200, successQueryAuthorisedResponse());
    ChargeEntity chargeEntity = buildChargeEntity();
    ChargeQueryGatewayRequest request = ChargeQueryGatewayRequest.valueOf(Charge.from(chargeEntity), chargeEntity.getGatewayAccount(), chargeEntity.getGatewayAccountCredentialsEntity());
    ChargeQueryResponse response = provider.queryPaymentStatus(request);
    assertThat(response.getMappedStatus(), is(Optional.of(AUTHORISATION_SUCCESS)));
    assertThat(response.foundCharge(), is(true));
}
Also used : ChargeQueryGatewayRequest(uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest) ChargeQueryResponse(uk.gov.pay.connector.gateway.ChargeQueryResponse) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Test(org.junit.Test)

Example 5 with ChargeQueryGatewayRequest

use of uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest in project pay-connector by alphagov.

the class EpdqPaymentProviderIT method shouldReturnQueryResponseWhenChargeNotFound.

@Test
public void shouldReturnQueryResponseWhenChargeNotFound() throws Exception {
    mockPaymentProviderResponse(200, errorQueryResponse());
    ChargeEntity chargeEntity = buildChargeEntity();
    ChargeQueryGatewayRequest request = ChargeQueryGatewayRequest.valueOf(Charge.from(chargeEntity), chargeEntity.getGatewayAccount(), chargeEntity.getGatewayAccountCredentialsEntity());
    ChargeQueryResponse response = provider.queryPaymentStatus(request);
    assertThat(response.getMappedStatus(), is(Optional.empty()));
    assertThat(response.foundCharge(), is(false));
}
Also used : ChargeQueryGatewayRequest(uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest) ChargeQueryResponse(uk.gov.pay.connector.gateway.ChargeQueryResponse) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Test(org.junit.Test)

Aggregations

ChargeQueryGatewayRequest (uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest)7 ChargeQueryResponse (uk.gov.pay.connector.gateway.ChargeQueryResponse)7 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)5 Test (org.junit.Test)4 URI (java.net.URI)3 GatewayOrder (uk.gov.pay.connector.gateway.GatewayOrder)3 CardAuthorisationGatewayRequest (uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest)3 String.format (java.lang.String.format)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Charge (uk.gov.pay.connector.charge.model.domain.Charge)2 ChargeStatus (uk.gov.pay.connector.charge.model.domain.ChargeStatus)2 ExternalChargeRefundAvailability (uk.gov.pay.connector.common.model.api.ExternalChargeRefundAvailability)2 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)2 GatewayClient (uk.gov.pay.connector.gateway.GatewayClient)2