use of uk.gov.pay.api.model.RefundResponse in project pay-publicapi by alphagov.
the class GetPaymentRefundServiceTest method testGetPayment.
@Test
@PactVerification({ "connector" })
@Pacts(pacts = { "publicapi-connector-get-payment-refund" })
public void testGetPayment() {
Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "a-token-link");
RefundResponse refund = getPaymentService.getConnectorPaymentRefund(account, CHARGE_ID, REFUND_ID);
assertThat(refund.getRefundId(), is(REFUND_ID));
assertThat(refund.getStatus(), is("success"));
assertThat(refund.getAmount(), is(100L));
assertThat(refund.getCreatedDate(), is("2018-09-22T10:14:16.067Z"));
assertThat(refund.getLinks().getPayment().getHref(), is("http://publicapi.test.localhost/v1/payments/123456789"));
assertThat(refund.getLinks().getSelf().getHref(), is("http://publicapi.test.localhost/v1/payments/123456789/refunds/r_123abc456def"));
}
use of uk.gov.pay.api.model.RefundResponse in project pay-publicapi by alphagov.
the class GetPaymentRefundServiceTest method testGetLedgerPaymentRefund.
@Test
@PactVerification({ "ledger" })
@Pacts(pacts = { "publicapi-ledger-get-payment-refund" })
public void testGetLedgerPaymentRefund() {
Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "a-token-link");
RefundResponse refund = getPaymentService.getLedgerPaymentRefund(account, CHARGE_ID, REFUND_ID);
assertThat(refund.getRefundId(), is(REFUND_ID));
assertThat(refund.getStatus(), is("success"));
assertThat(refund.getAmount(), is(100L));
assertThat(refund.getCreatedDate(), is("2018-09-22T10:14:16.067Z"));
assertThat(refund.getLinks().getPayment().getHref(), is("http://publicapi.test.localhost/v1/payments/123456789"));
assertThat(refund.getLinks().getSelf().getHref(), is("http://publicapi.test.localhost/v1/payments/123456789/refunds/r_123abc456def"));
}
use of uk.gov.pay.api.model.RefundResponse 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"));
}
use of uk.gov.pay.api.model.RefundResponse 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"));
}
use of uk.gov.pay.api.model.RefundResponse in project pay-publicapi by alphagov.
the class PaymentRefundsResource method submitRefund.
@POST
@Timed
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@Operation(security = { @SecurityRequirement(name = "BearerAuth") }, operationId = "Submit a refund for a payment", summary = "Submit a refund for a payment", description = "Return issued refund information. " + "The Authorisation token needs to be specified in the 'authorization' header as 'authorization: Bearer YOUR_API_KEY_HERE'", responses = { @ApiResponse(responseCode = "200", description = "successful operation", content = @Content(schema = @Schema(implementation = RefundResult.class))), @ApiResponse(responseCode = "202", description = "ACCEPTED"), @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 = "412", description = "Refund amount available mismatch"), @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 Response submitRefund(@Parameter(hidden = true) @Auth Account account, @PathParam("paymentId") String paymentId, @Parameter(required = true, description = "requestPayload") CreatePaymentRefundRequest requestPayload) {
var strategy = new GetOnePaymentStrategy("", account, paymentId, getPaymentService);
logger.info("Create a refund for payment request - paymentId={}", paymentId);
Integer refundAmountAvailable = requestPayload.getRefundAmountAvailable().orElseGet(() -> Optional.of((CardPayment) strategy.validateAndExecute().getPayment()).map(p -> p.getRefundSummary().map(RefundSummary::getAmountAvailable).orElse(0L)).map(Long::intValue).orElse(0));
ImmutableMap<String, Object> payloadMap = ImmutableMap.of("amount", requestPayload.getAmount(), "refund_amount_available", refundAmountAvailable);
String connectorPayload = new GsonBuilder().create().toJson(payloadMap);
Response connectorResponse = client.target(getConnectorUrl(format("/v1/api/accounts/%s/charges/%s/refunds", account.getAccountId(), paymentId))).request().post(json(connectorPayload));
if (connectorResponse.getStatus() == ACCEPTED.getStatusCode()) {
RefundFromConnector refundFromConnector = connectorResponse.readEntity(RefundFromConnector.class);
logger.debug("created refund returned - [ {} ]", refundFromConnector);
RefundResponse refundResponse = RefundResponse.valueOf(refundFromConnector, paymentId, baseUrl);
return Response.accepted(refundResponse).build();
}
throw new CreateRefundException(connectorResponse);
}
Aggregations