Search in sources :

Example 1 with PaymentWithAllLinks

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

the class PaymentsResource method getPayment.

@GET
@Timed
@Path("/v1/payments/{paymentId}")
@Produces(APPLICATION_JSON)
@Operation(security = { @SecurityRequirement(name = "BearerAuth") }, operationId = "Get a payment", summary = "Find payment by ID", description = "Return information about the 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 = GetPaymentResult.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 Response getPayment(@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 request - paymentId={}", paymentId);
    var strategy = new GetOnePaymentStrategy(strategyName, account, paymentId, getPaymentService);
    PaymentWithAllLinks payment = strategy.validateAndExecute();
    logger.info("Payment returned - [ {} ]", payment);
    return Response.ok(payment).build();
}
Also used : PaymentWithAllLinks(uk.gov.pay.api.model.links.PaymentWithAllLinks) 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 PaymentWithAllLinks

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

the class PaymentsResource method createNewPayment.

@POST
@Timed
@Path("/v1/payments")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Operation(security = { @SecurityRequirement(name = "BearerAuth") }, operationId = "Create a payment", summary = "Create new payment", description = "Create a new payment for the account associated to the Authorisation token. " + "The Authorisation token needs to be specified in the 'authorization' header " + "as 'authorization: Bearer YOUR_API_KEY_HERE'", responses = { @ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(implementation = CreatePaymentResult.class))), @ApiResponse(responseCode = "400", description = "Bad request", content = @Content(schema = @Schema(implementation = PaymentError.class))), @ApiResponse(responseCode = "401", description = "Credentials are required to access this resource"), @ApiResponse(responseCode = "422", description = "Invalid attribute value: description. Must be less than or equal to 255 characters length", 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 Response createNewPayment(@Parameter(hidden = true) @Auth Account account, @Parameter(required = true, description = "requestPayload") @Valid CreateCardPaymentRequest createCardPaymentRequest) {
    logger.info("Payment create request parsed to {}", createCardPaymentRequest);
    PaymentWithAllLinks createdPayment = createPaymentService.create(account, createCardPaymentRequest);
    Response response = Response.created(publicApiUriGenerator.getPaymentURI(createdPayment.getPayment().getPaymentId())).entity(createdPayment).build();
    logger.info("Payment returned (created): [ {} ]", createdPayment);
    return response;
}
Also used : ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) ApiErrorResponse(uk.gov.pay.api.resources.error.ApiErrorResponse) PaymentEventsResponse(uk.gov.pay.api.model.PaymentEventsResponse) Response(javax.ws.rs.core.Response) PaymentWithAllLinks(uk.gov.pay.api.model.links.PaymentWithAllLinks) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) Operation(io.swagger.v3.oas.annotations.Operation)

Example 3 with PaymentWithAllLinks

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

the class GetPaymentServiceLedgerTest method testGetPaymentWithSettledDate.

@Test
@PactVerification({ "ledger" })
@Pacts(pacts = { "publicapi-ledger-get-payment-with-settled-date" })
public void testGetPaymentWithSettledDate() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, tokenLink);
    PaymentWithAllLinks paymentResponse = getPaymentService.getPayment(account, "ch_123abc456settlement");
    CardPayment payment = (CardPayment) paymentResponse.getPayment();
    assertThat(payment.getSettlementSummary().isPresent(), is(true));
    assertThat(payment.getSettlementSummary().get().getSettledDate(), is("2020-09-19"));
}
Also used : Account(uk.gov.pay.api.auth.Account) CardPayment(uk.gov.pay.api.model.CardPayment) PaymentWithAllLinks(uk.gov.pay.api.model.links.PaymentWithAllLinks) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 4 with PaymentWithAllLinks

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

the class GetPaymentServiceLedgerTest method providerIdIsAvailableWhenPaymentIsSubmitted_Ledger.

@Test
@PactVerification({ "ledger" })
@Pacts(pacts = { "publicapi-ledger-get-payment-with-gateway-transaction-id" })
public void providerIdIsAvailableWhenPaymentIsSubmitted_Ledger() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, tokenLink);
    PaymentWithAllLinks paymentResponse = getPaymentService.getPayment(account, CHARGE_ID_NON_EXISTENT_IN_CONNECTOR);
    CardPayment payment = (CardPayment) paymentResponse.getPayment();
    assertThat(payment.getProviderId(), is("gateway-tx-123456"));
}
Also used : Account(uk.gov.pay.api.auth.Account) CardPayment(uk.gov.pay.api.model.CardPayment) PaymentWithAllLinks(uk.gov.pay.api.model.links.PaymentWithAllLinks) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 5 with PaymentWithAllLinks

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

the class GetPaymentServiceLedgerTest method testGetPaymentWithFeeAndNetAmountFromLedger.

@Test
@PactVerification({ "ledger" })
@Pacts(pacts = { "publicapi-ledger-get-payment-with-fee-and-net-amount" })
public void testGetPaymentWithFeeAndNetAmountFromLedger() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, tokenLink);
    PaymentWithAllLinks paymentResponse = getPaymentService.getPayment(account, CHARGE_ID_NON_EXISTENT_IN_CONNECTOR);
    CardPayment payment = (CardPayment) paymentResponse.getPayment();
    assertThat(payment.getPaymentId(), is(CHARGE_ID_NON_EXISTENT_IN_CONNECTOR));
    assertThat(payment.getPaymentProvider(), is("sandbox"));
    assertThat(payment.getAmount(), is(100L));
    assertThat(payment.getFee().get(), is(5L));
    assertThat(payment.getNetAmount().get(), is(95L));
}
Also used : Account(uk.gov.pay.api.auth.Account) CardPayment(uk.gov.pay.api.model.CardPayment) PaymentWithAllLinks(uk.gov.pay.api.model.links.PaymentWithAllLinks) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Aggregations

PaymentWithAllLinks (uk.gov.pay.api.model.links.PaymentWithAllLinks)16 PactVerification (au.com.dius.pact.consumer.PactVerification)12 Test (org.junit.Test)12 Account (uk.gov.pay.api.auth.Account)12 CardPayment (uk.gov.pay.api.model.CardPayment)12 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)12 PaymentState (uk.gov.pay.api.model.PaymentState)4 PostLink (uk.gov.pay.api.model.links.PostLink)3 Timed (com.codahale.metrics.annotation.Timed)2 Operation (io.swagger.v3.oas.annotations.Operation)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 Test (org.junit.jupiter.api.Test)2 Link (uk.gov.pay.api.model.links.Link)2 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)1 URI (java.net.URI)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1