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