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