Search in sources :

Example 1 with PaymentEventsResponse

use of uk.gov.pay.api.model.PaymentEventsResponse in project pay-publicapi by alphagov.

the class PaymentsResource method getPaymentEvents.

@GET
@Timed
@Path("/v1/payments/{paymentId}/events")
@Produces(APPLICATION_JSON)
@Operation(security = { @SecurityRequirement(name = "BearerAuth") }, operationId = "Get events for a payment", summary = "Return payment events by ID", description = "Return payment events information about a certain payment " + "The Authorisation token needs to be specified in the 'authorization' header " + "as 'authorization: Bearer YOUR_API_KEY_HERE'", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentEventsResponse.class))), @ApiResponse(responseCode = "401", description = "Credentials are required to access this resource"), @ApiResponse(responseCode = "404", description = "Not found", content = @Content(schema = @Schema(implementation = PaymentError.class))), @ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema(implementation = ApiErrorResponse.class))), @ApiResponse(responseCode = "500", description = "Downstream system error", content = @Content(schema = @Schema(implementation = PaymentError.class))) })
public PaymentEventsResponse getPaymentEvents(@Parameter(hidden = true) @Auth Account account, @PathParam("paymentId") @Parameter(name = "paymentId", description = "Payment identifier", example = "hu20sqlact5260q2nanm0q8u93") String paymentId, @Parameter(hidden = true) @HeaderParam("X-Ledger") String strategyName) {
    logger.info("Payment events request - payment_id={}", paymentId);
    var strategy = new GetPaymentEventsStrategy(strategyName, account, paymentId, getPaymentEventsService);
    PaymentEventsResponse paymentEventsResponse = strategy.validateAndExecute();
    logger.info("Payment events returned - [ {} ]", paymentEventsResponse);
    return paymentEventsResponse;
}
Also used : PaymentEventsResponse(uk.gov.pay.api.model.PaymentEventsResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with PaymentEventsResponse

use of uk.gov.pay.api.model.PaymentEventsResponse in project pay-publicapi by alphagov.

the class GetPaymentEventsServiceTest method shouldReturnPaymentEventsWhenCallingLedger.

@Test
@PactVerification("ledger")
@Pacts(pacts = { "publicapi-ledger-get-payment-events" })
public void shouldReturnPaymentEventsWhenCallingLedger() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "a-token-link");
    PaymentEventsResponse paymentEventsResponse = getPaymentEventsService.getPaymentEventsFromLedger(account, "abc123");
    assertThat(paymentEventsResponse.getPaymentId(), is("abc123"));
    assertThat(paymentEventsResponse.getLinks().getSelf().getHref(), is("http://publicapi.test.localhost/v1/payments/abc123/events"));
    assertThat(paymentEventsResponse.getEvents().size(), is(2));
    assertThat(paymentEventsResponse.getEvents().get(0).getPaymentId(), is("abc123"));
    assertThat(paymentEventsResponse.getEvents().get(0).getPaymentLink().getPaymentLink().getHref(), is("http://publicapi.test.localhost/v1/payments/abc123"));
    assertThat(paymentEventsResponse.getEvents().get(0).getState().getStatus(), is("created"));
    assertThat(paymentEventsResponse.getEvents().get(0).getState().isFinished(), is(false));
    assertThat(paymentEventsResponse.getEvents().get(0).getUpdated(), is("2019-08-06T10:34:43.487123Z"));
    assertThat(paymentEventsResponse.getEvents().get(1).getPaymentId(), is("abc123"));
    assertThat(paymentEventsResponse.getEvents().get(1).getPaymentLink().getPaymentLink().getHref(), is("http://publicapi.test.localhost/v1/payments/abc123"));
    assertThat(paymentEventsResponse.getEvents().get(1).getState().getStatus(), is("failed"));
    assertThat(paymentEventsResponse.getEvents().get(1).getState().isFinished(), is(true));
    assertThat(paymentEventsResponse.getEvents().get(1).getState().getCode(), is("P0010"));
    assertThat(paymentEventsResponse.getEvents().get(1).getState().getMessage(), is("Payment method rejected"));
    assertThat(paymentEventsResponse.getEvents().get(1).getUpdated(), is("2019-08-06T10:34:48.123456Z"));
}
Also used : PaymentEventsResponse(uk.gov.pay.api.model.PaymentEventsResponse) Account(uk.gov.pay.api.auth.Account) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 3 with PaymentEventsResponse

use of uk.gov.pay.api.model.PaymentEventsResponse in project pay-publicapi by alphagov.

the class GetPaymentEventsServiceTest method shouldReturnPaymentEventsWhenCallingConnector.

@Test
@PactVerification("connector")
@Pacts(pacts = { "publicapi-connector-get-payment-events" })
public void shouldReturnPaymentEventsWhenCallingConnector() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "a-token-link");
    PaymentEventsResponse paymentEventsResponse = getPaymentEventsService.getPaymentEventsFromConnector(account, "abc123");
    assertThat(paymentEventsResponse.getPaymentId(), is("abc123"));
    assertThat(paymentEventsResponse.getLinks().getSelf().getHref(), is("http://publicapi.test.localhost/v1/payments/abc123/events"));
    assertThat(paymentEventsResponse.getEvents().size(), is(2));
    assertThat(paymentEventsResponse.getEvents().get(0).getPaymentId(), is("abc123"));
    assertThat(paymentEventsResponse.getEvents().get(0).getPaymentLink().getPaymentLink().getHref(), is("http://publicapi.test.localhost/v1/payments/abc123"));
    assertThat(paymentEventsResponse.getEvents().get(0).getState().getStatus(), is("created"));
    assertThat(paymentEventsResponse.getEvents().get(0).getState().isFinished(), is(false));
    assertThat(paymentEventsResponse.getEvents().get(0).getUpdated(), is("2019-08-06T10:34:43.487Z"));
    assertThat(paymentEventsResponse.getEvents().get(1).getPaymentId(), is("abc123"));
    assertThat(paymentEventsResponse.getEvents().get(1).getPaymentLink().getPaymentLink().getHref(), is("http://publicapi.test.localhost/v1/payments/abc123"));
    assertThat(paymentEventsResponse.getEvents().get(1).getState().getStatus(), is("failed"));
    assertThat(paymentEventsResponse.getEvents().get(1).getState().isFinished(), is(true));
    assertThat(paymentEventsResponse.getEvents().get(1).getState().getCode(), is("P0010"));
    assertThat(paymentEventsResponse.getEvents().get(1).getState().getMessage(), is("Payment method rejected"));
    assertThat(paymentEventsResponse.getEvents().get(1).getUpdated(), is("2019-08-06T10:34:48.487Z"));
}
Also used : PaymentEventsResponse(uk.gov.pay.api.model.PaymentEventsResponse) Account(uk.gov.pay.api.auth.Account) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Aggregations

PaymentEventsResponse (uk.gov.pay.api.model.PaymentEventsResponse)3 PactVerification (au.com.dius.pact.consumer.PactVerification)2 Test (org.junit.Test)2 Account (uk.gov.pay.api.auth.Account)2 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)2 Timed (com.codahale.metrics.annotation.Timed)1 Operation (io.swagger.v3.oas.annotations.Operation)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1