Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service request for fees payments #57

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/uk/gov/hmcts/reform/payments/client/PaymentsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import uk.gov.hmcts.reform.payments.client.health.InternalHealth;
import uk.gov.hmcts.reform.payments.client.models.PaymentDto;
import uk.gov.hmcts.reform.payments.request.CardPaymentRequest;
import uk.gov.hmcts.reform.payments.request.CardPaymentServiceRequestDTO;
import uk.gov.hmcts.reform.payments.request.CreateServiceRequestDTO;
import uk.gov.hmcts.reform.payments.request.CreditAccountPaymentRequest;
import uk.gov.hmcts.reform.payments.request.PBAServiceRequestDTO;
import uk.gov.hmcts.reform.payments.response.CardPaymentServiceRequestResponse;
import uk.gov.hmcts.reform.payments.response.PBAServiceRequestResponse;
import uk.gov.hmcts.reform.payments.response.PaymentServiceResponse;

Expand Down Expand Up @@ -51,6 +53,13 @@ void cancelCardPayment(
@RequestHeader("ServiceAuthorization") String serviceAuthorization
);

@GetMapping(value = "/payments/{payment-reference}")
PaymentDto getGovPayCardPaymentStatus(
@PathVariable("payment-reference") String paymentReference,
@RequestHeader("Authorization") String authorization,
@RequestHeader("ServiceAuthorization") String serviceAuthorization
);

@PostMapping(value = "/service-request", consumes = "application/json")
PaymentServiceResponse createServiceRequest(
@RequestHeader("Authorization") String authorization,
Expand All @@ -65,4 +74,12 @@ PBAServiceRequestResponse createPbaPayment(
@RequestHeader("ServiceAuthorization") String serviceAuthorization,
@RequestBody PBAServiceRequestDTO paymentRequest
);

@PostMapping(value = "/service-request/{service-request-reference}/card-payments", consumes = "application/json")
CardPaymentServiceRequestResponse createGovPayCardPaymentRequest(
@PathVariable("service-request-reference") String serviceReqReference,
@RequestHeader("Authorization") String authorization,
@RequestHeader("ServiceAuthorization") String serviceAuthorization,
@RequestBody CardPaymentServiceRequestDTO paymentRequest
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;
import uk.gov.hmcts.reform.payments.client.models.PaymentDto;
import uk.gov.hmcts.reform.payments.request.CardPaymentRequest;
import uk.gov.hmcts.reform.payments.request.CardPaymentServiceRequestDTO;
import uk.gov.hmcts.reform.payments.request.CreateServiceRequestDTO;
import uk.gov.hmcts.reform.payments.request.CreditAccountPaymentRequest;
import uk.gov.hmcts.reform.payments.request.PBAServiceRequestDTO;
import uk.gov.hmcts.reform.payments.response.CardPaymentServiceRequestResponse;
import uk.gov.hmcts.reform.payments.response.PBAServiceRequestResponse;
import uk.gov.hmcts.reform.payments.response.PaymentServiceResponse;

Expand Down Expand Up @@ -76,4 +78,16 @@ public PBAServiceRequestResponse createPbaPayment(String serviceReqReference, St
paymentRequest
);
}

public CardPaymentServiceRequestResponse createGovPayCardPaymentRequest(
String serviceReqReference,
String authorization,
CardPaymentServiceRequestDTO paymentRequest) {
return paymentsApi.createGovPayCardPaymentRequest(
serviceReqReference, authorization, authTokenGenerator.generate(), paymentRequest);
}

public PaymentDto getGovPayCardPaymentStatus(String paymentReference, String authorization) {
return paymentsApi.getGovPayCardPaymentStatus(paymentReference, authorization, authTokenGenerator.generate());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package uk.gov.hmcts.reform.payments.request;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.math.BigDecimal;

@Data
@Builder
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class CardPaymentServiceRequestDTO {

@JsonProperty("language")
private String language;
@JsonProperty("amount")
private BigDecimal amount;
@Builder.Default
@JsonProperty("currency")
private String currency = "GBP";
@JsonProperty("return-url")
private String returnUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package uk.gov.hmcts.reform.payments.response;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.OffsetDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class CardPaymentServiceRequestResponse {

@JsonProperty("external_reference")
private String externalReference;

@JsonProperty("payment_reference")
private String paymentReference;

@JsonProperty("status")
private String status;

@JsonProperty("next_url")
private String nextUrl;

@JsonProperty("date_created")
private OffsetDateTime dateCreated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import uk.gov.hmcts.reform.payments.client.models.CasePaymentRequestDto;
import uk.gov.hmcts.reform.payments.client.models.FeeDto;
import uk.gov.hmcts.reform.payments.request.CardPaymentRequest;
import uk.gov.hmcts.reform.payments.request.CardPaymentServiceRequestDTO;
import uk.gov.hmcts.reform.payments.request.CreateServiceRequestDTO;
import uk.gov.hmcts.reform.payments.request.CreditAccountPaymentRequest;
import uk.gov.hmcts.reform.payments.request.PBAServiceRequestDTO;

import java.math.BigDecimal;

import static java.math.BigDecimal.ROUND_UNNECESSARY;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
Expand All @@ -27,7 +27,7 @@
@ExtendWith(MockitoExtension.class)
class PaymentsClientTest {

private static final BigDecimal TEN_2_DP = BigDecimal.TEN.setScale(2, ROUND_UNNECESSARY);
private static final BigDecimal TEN_2_DP = new BigDecimal("10.00");

private static final String CCD_CASE_NUMBER = "UNKNOWN";
private static final BigDecimal FEE_AMOUNT = TEN_2_DP;
Expand Down Expand Up @@ -65,6 +65,14 @@ class PaymentsClientTest {
.siteId("site ID")
.build();

private static final CardPaymentServiceRequestDTO CARD_PAYMENT_SERVICE_REQUEST =
CardPaymentServiceRequestDTO.builder()
.returnUrl("return-url")
.language("English")
.amount(new BigDecimal("232.00"))
.currency("GBP")
.build();

private static final CreateServiceRequestDTO SERVICE_REQUEST = CreateServiceRequestDTO.builder()
.callBackUrl("callbackurl")
.casePaymentRequest(CasePaymentRequestDto.builder().action("action").responsibleParty("party").build())
Expand Down Expand Up @@ -129,6 +137,22 @@ void createServiceRequestShouldPropagateExceptions() {
.hasMessage("expected exception for create payment");
}

@Test
void createGovPayCardPaymentRequest() {
client.createGovPayCardPaymentRequest("service-request-id",
"authorisation", CARD_PAYMENT_SERVICE_REQUEST);
verify(paymentsApi)
.createGovPayCardPaymentRequest("service-request-id",
"authorisation", "auth token", CARD_PAYMENT_SERVICE_REQUEST);
}

@Test
void getGovPayCardPaymentStatus() {
client.getGovPayCardPaymentStatus("payment-reference", "authorisation");
verify(paymentsApi)
.getGovPayCardPaymentStatus("payment-reference", "authorisation", "auth token");
}

@Test
void createCreditAccountPaymentShouldInvokePaymentsApi() {
client.createCreditAccountPayment("authorisation", CREDIT_ACCOUNT_PAYMENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import uk.gov.hmcts.reform.payments.client.models.FeeDto;
import uk.gov.hmcts.reform.payments.client.models.PaymentDto;
import uk.gov.hmcts.reform.payments.request.CardPaymentRequest;
import uk.gov.hmcts.reform.payments.request.CardPaymentServiceRequestDTO;
import uk.gov.hmcts.reform.payments.request.CreditAccountPaymentRequest;
import uk.gov.hmcts.reform.payments.response.CardPaymentServiceRequestResponse;

import java.math.BigDecimal;
import java.util.Map;
Expand Down Expand Up @@ -116,6 +118,28 @@ void testCreateCardPayment() {
);
}

@Test
void testCreateGovPayCardPaymentRequest() {
CardPaymentServiceRequestResponse payment = paymentsClient.createGovPayCardPaymentRequest(
"2023-1701090705688",
"Authorisation",
CardPaymentServiceRequestDTO.builder()
.returnUrl("return-url")
.language("English")
.amount(new BigDecimal("232.00"))
.currency("GBP")
.build()
);
assertNotNull(payment);
assertAll(
() -> assertEquals("RC-1701-0909-0602-0418", payment.getPaymentReference()),
() -> assertEquals("lbh2ogknloh9p3b4lchngdfg63", payment.getExternalReference()),
() -> assertEquals("Initiated", payment.getStatus()),
() -> assertEquals("https://card.payments.service.gov.uk/secure/7b0716b2-40c4-413e-b62e-72c599c91960",
payment.getNextUrl())
);
}

@Test
void testRetrieveCardPayment() {
PaymentDto payment = paymentsClient.retrieveCardPayment("Authorisation", "RC-1566-2093-5462-0545");
Expand All @@ -139,6 +163,45 @@ void testRetrieveCardPayment() {
);
}

@Test
void testRetrieveCardPaymentStatus() {
PaymentDto payment = paymentsClient.getGovPayCardPaymentStatus("RC-1701-0909-0602-0418", "Authorisation");
assertNotNull(payment);
assertAll(
() -> assertEquals("RC-1701-0909-0602-0418", payment.getPaymentReference()),
() -> assertEquals(new BigDecimal("232.00"), payment.getAmount()),
() -> assertEquals("GBP", payment.getCurrency()),
() -> assertEquals("online", payment.getChannel()),
() -> assertEquals("card", payment.getMethod()),
() -> assertEquals("gov pay", payment.getExternalProvider()),
() -> assertEquals("Success", payment.getStatus()),
() -> assertEquals("lbh2ogknloh9p3b4lchngdfg63", payment.getExternalReference()),
() -> assertEquals("2023-1701090705688", payment.getPaymentGroupReference()),
() -> assertNotNull(payment.getFees()),
() -> assertAll(
() -> assertEquals(
"FEE0336",
payment.getFees()[0].getCode()
),
() -> assertEquals(
new BigDecimal("232.00"),
payment.getFees()[0].getCalculatedAmount()
)
),
() -> assertNotNull(payment.getStatusHistories()),
() -> assertAll(
() -> assertEquals(
"Initiated",
payment.getStatusHistories()[0].getStatus()
),
() -> assertEquals(
"Success",
payment.getStatusHistories()[1].getStatus()
)
)
);
}

@Test
void testCancelCardPayment() {
// test passes if no exceptions are thrown
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"id" : "f4db6fd2-dea4-4a3a-80df-643b2cf1344d",
"name" : "card-payments_rc-1701-0909-0602-0418",
"request" : {
"url" : "/payments/RC-1701-0909-0602-0418",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\n \"amount\": 232.00,\n \"date_created\": \"2023-11-27T13:15:06.313+0000\",\n \"date_updated\": \"2023-11-27T13:19:28.761+0000\",\n \"currency\": \"GBP\",\n \"ccd_case_number\": \"1701090368574910\",\n \"case_reference\": \"123456\",\n \"payment_reference\": \"RC-1701-0909-0602-0418\",\n \"channel\": \"online\",\n \"method\": \"card\",\n \"external_provider\": \"gov pay\",\n \"status\": \"Success\",\n \"external_reference\": \"lbh2ogknloh9p3b4lchngdfg63\",\n \"site_id\": \"ABA5\",\n \"service_name\": \"Family Private Law\",\n \"payment_group_reference\": \"2023-1701090705688\",\n \"issue_refund_add_refund_add_remission\": false,\n \"issue_refund\": false,\n \"fees\": [\n {\n \"id\": 2729098,\n \"code\": \"FEE0336\",\n \"version\": \"2\",\n \"volume\": 1,\n \"calculated_amount\": 232.00,\n \"memo_line\": \"RECEIPT OF FEES - Family misc private\",\n \"natural_account_code\": \"4481102174\",\n \"ccd_case_number\": \"1701090368574910\",\n \"jurisdiction1\": \"family\",\n \"jurisdiction2\": \"family court\",\n \"date_created\": \"2023-11-27T13:11:45.623+00:00\",\n \"date_updated\": \"2023-11-27T13:19:28.765+00:00\",\n \"issue_refund_add_refund_add_remission\": false,\n \"add_remission\": false\n }\n ],\n \"status_histories\": [\n {\n \"status\": \"Initiated\",\n \"external_status\": \"created\",\n \"date_created\": \"2023-11-27T13:15:06.319+0000\"\n },\n {\n \"status\": \"Success\",\n \"external_status\": \"success\",\n \"date_created\": \"2023-11-27T13:19:28.759+0000\"\n }\n ],\n \"payment_allocation\": []\n}",
"headers" : {
"X-Content-Type-Options" : "nosniff",
"X-XSS-Protection" : "1; mode=block",
"Cache-Control" : "no-cache, no-store, max-age=0, must-revalidate",
"Pragma" : "no-cache",
"Expires" : "0",
"X-Frame-Options" : "DENY",
"Content-Type" : "application/json;charset=UTF-8",
"Date" : "Mon, 19 Aug 2019 10:09:15 GMT"
}
},
"uuid" : "f4db6fd2-dea4-4a3a-80df-643b2cf1344d",
"persistent" : true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "603a01d7-0c0b-494d-ba4c-0d7165238522",
"name": "gov-pay-card-payments",
"request": {
"url": "/service-request/2023-1701090705688/card-payments",
"method": "POST",
"bodyPatterns": [
{
"equalToJson": "{\n \"return-url\" : \"return-url\",\n \"language\" : \"English\",\n \"currency\" : \"GBP\",\n \"amount\" : 232.00\n}",
"ignoreArrayOrder": true,
"ignoreExtraElements": true
}
]
},
"response": {
"status": 201,
"body": "{\n \"payment_reference\": \"RC-1701-0909-0602-0418\",\n \"external_reference\": \"lbh2ogknloh9p3b4lchngdfg63\",\n \"status\": \"Initiated\",\n \"next_url\": \"https://card.payments.service.gov.uk/secure/7b0716b2-40c4-413e-b62e-72c599c91960\",\n \"date_created\": \"2023-11-27T13:15:06.313+00:00\"\n}",
"headers": {
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
"Pragma": "no-cache",
"Expires": "0",
"X-Frame-Options": "DENY",
"Content-Type": "application/json;charset=UTF-8",
"Date": "Mon, 19 Aug 2019 09:46:54 GMT"
}
},
"uuid": "603a01d7-0c0b-494d-ba4c-0d7165238522",
"persistent": true
}