Search in sources :

Example 1 with RefundsResponse

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

the class PaymentRefundsResource method getRefunds.

@GET
@Timed
@Produces(APPLICATION_JSON)
@Operation(security = { @SecurityRequirement(name = "BearerAuth") }, operationId = "Get all refunds for a payment", summary = "Get all refunds for a payment", description = "Return refunds for a 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 = RefundForSearchResult.class))), @ApiResponse(responseCode = "401", description = "Credentials are required to access this resource"), @ApiResponse(responseCode = "404", description = "Not found", content = @Content(schema = @Schema(implementation = RequestError.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 = RequestError.class))) })
public RefundsResponse getRefunds(@Parameter(hidden = true) @Auth Account account, @PathParam("paymentId") String paymentId, @Parameter(hidden = true) @HeaderParam("X-Ledger") String strategyName) {
    logger.info("Get refunds for payment request - paymentId={} using strategy={}", paymentId, strategyName);
    GetPaymentRefundsStrategy strategy = new GetPaymentRefundsStrategy(strategyName, account, paymentId, getPaymentRefundsService);
    RefundsResponse refundsResponse = strategy.validateAndExecute();
    logger.debug("refund returned - [ {} ]", refundsResponse);
    return refundsResponse;
}
Also used : RefundsResponse(uk.gov.pay.api.model.RefundsResponse) 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 RefundsResponse

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

the class GetPaymentRefundsServiceTest method shouldReturnRefundsForPaymentCorrectlyFromLedger.

@Test
@PactVerification("ledger")
@Pacts(pacts = { "publicapi-ledger-get-payment-refunds" })
public void shouldReturnRefundsForPaymentCorrectlyFromLedger() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "a-token-link");
    RefundsResponse response = getPaymentRefundsService.getLedgerTransactionTransactions(account, "ch_123abc456xyz");
    assertThat(response.getPaymentId(), is("ch_123abc456xyz"));
    assertThat(response.getLinks().getSelf().getHref(), is("http://publicapi.test.localhost/v1/payments/ch_123abc456xyz/refunds"));
    assertThat(response.getLinks().getPayment().getHref(), is("http://publicapi.test.localhost/v1/payments/ch_123abc456xyz"));
    List<RefundResponse> refunds = response.getEmbedded().getRefunds();
    assertThat(refunds.size(), is(2));
    assertThat(refunds.get(0).getRefundId(), is("refund-transaction-id1"));
    assertThat(refunds.get(0).getStatus(), is("submitted"));
    assertThat(refunds.get(0).getAmount(), is(100L));
    assertThat(refunds.get(0).getCreatedDate(), is("2018-09-22T10:14:16.067Z"));
    assertThat(refunds.get(0).getLinks().getPayment().getHref(), is("http://publicapi.test.localhost/v1/payments/ch_123abc456xyz"));
    assertThat(refunds.get(0).getLinks().getSelf().getHref(), is("http://publicapi.test.localhost/v1/payments/ch_123abc456xyz/refunds/refund-transaction-id1"));
    assertThat(refunds.get(1).getRefundId(), is("refund-transaction-id2"));
    assertThat(refunds.get(1).getStatus(), is("error"));
    assertThat(refunds.get(1).getAmount(), is(200L));
    assertThat(refunds.get(1).getCreatedDate(), is("2018-09-22T10:16:16.067Z"));
    assertThat(refunds.get(1).getLinks().getPayment().getHref(), is("http://publicapi.test.localhost/v1/payments/ch_123abc456xyz"));
    assertThat(refunds.get(1).getLinks().getSelf().getHref(), is("http://publicapi.test.localhost/v1/payments/ch_123abc456xyz/refunds/refund-transaction-id2"));
}
Also used : Account(uk.gov.pay.api.auth.Account) RefundResponse(uk.gov.pay.api.model.RefundResponse) RefundsResponse(uk.gov.pay.api.model.RefundsResponse) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 3 with RefundsResponse

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

the class GetPaymentRefundsServiceTest method shouldReturnRefundsForPaymentCorrectlyFromConnector.

@Test
@PactVerification("connector")
@Pacts(pacts = { "publicapi-connector-get-payment-refunds" })
public void shouldReturnRefundsForPaymentCorrectlyFromConnector() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "a-token-link");
    RefundsResponse response = getPaymentRefundsService.getConnectorPaymentRefunds(account, "charge8133029783750222");
    assertThat(response.getPaymentId(), is("charge8133029783750222"));
    assertThat(response.getLinks().getSelf().getHref(), is("http://publicapi.test.localhost/v1/payments/charge8133029783750222/refunds"));
    assertThat(response.getLinks().getPayment().getHref(), is("http://publicapi.test.localhost/v1/payments/charge8133029783750222"));
    List<RefundResponse> refunds = response.getEmbedded().getRefunds();
    assertThat(refunds.size(), is(2));
    assertThat(refunds.get(0).getRefundId(), is("di0qnu9ucdo7aslhatci6h90jk"));
    assertThat(refunds.get(0).getStatus(), is("success"));
    assertThat(refunds.get(0).getAmount(), is(1L));
    assertThat(refunds.get(0).getCreatedDate(), is("2016-01-25T13:23:55.000Z"));
    assertThat(refunds.get(0).getLinks().getPayment().getHref(), is("http://publicapi.test.localhost/v1/payments/charge8133029783750222"));
    assertThat(refunds.get(0).getLinks().getSelf().getHref(), is("http://publicapi.test.localhost/v1/payments/charge8133029783750222/refunds/di0qnu9ucdo7aslhatci6h90jk"));
    assertThat(refunds.get(1).getRefundId(), is("m16ufgc3t23l766ljhv9eicsn5"));
    assertThat(refunds.get(1).getStatus(), is("error"));
    assertThat(refunds.get(1).getAmount(), is(1L));
    assertThat(refunds.get(1).getCreatedDate(), is("2016-01-25T16:23:55.000Z"));
    assertThat(refunds.get(1).getLinks().getPayment().getHref(), is("http://publicapi.test.localhost/v1/payments/charge8133029783750222"));
    assertThat(refunds.get(1).getLinks().getSelf().getHref(), is("http://publicapi.test.localhost/v1/payments/charge8133029783750222/refunds/m16ufgc3t23l766ljhv9eicsn5"));
}
Also used : Account(uk.gov.pay.api.auth.Account) RefundResponse(uk.gov.pay.api.model.RefundResponse) RefundsResponse(uk.gov.pay.api.model.RefundsResponse) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Aggregations

RefundsResponse (uk.gov.pay.api.model.RefundsResponse)3 PactVerification (au.com.dius.pact.consumer.PactVerification)2 Test (org.junit.Test)2 Account (uk.gov.pay.api.auth.Account)2 RefundResponse (uk.gov.pay.api.model.RefundResponse)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 Produces (javax.ws.rs.Produces)1