Skip to content

Commit 70284b3

Browse files
author
dharmendra kumar
committed
Add tests for new apis
1 parent eccd244 commit 70284b3

9 files changed

Lines changed: 150 additions & 143 deletions

File tree

src/main/java/uk/gov/hmcts/reform/payments/client/PaymentsApi.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import uk.gov.hmcts.reform.payments.request.PBAServiceRequestDTO;
1717
import uk.gov.hmcts.reform.payments.response.CardPaymentServiceRequestResponse;
1818
import uk.gov.hmcts.reform.payments.response.PBAServiceRequestResponse;
19-
import uk.gov.hmcts.reform.payments.response.PaymentGroupResponse;
2019
import uk.gov.hmcts.reform.payments.response.PaymentServiceResponse;
2120

2221
@FeignClient(name = "payments-api", url = "${payments.api.url}", configuration = PaymentClientConfiguration.class)
@@ -55,7 +54,7 @@ void cancelCardPayment(
5554
);
5655

5756
@GetMapping(value = "/payments/{payment-reference}")
58-
PaymentDto getCardPaymentStatus(
57+
PaymentDto getGovPayCardPaymentStatus(
5958
@PathVariable("payment-reference") String paymentReference,
6059
@RequestHeader("Authorization") String authorization,
6160
@RequestHeader("ServiceAuthorization") String serviceAuthorization
@@ -77,18 +76,10 @@ PBAServiceRequestResponse createPbaPayment(
7776
);
7877

7978
@PostMapping(value = "/service-request/{service-request-reference}/card-payments", consumes = "application/json")
80-
CardPaymentServiceRequestResponse createCardPaymentServiceRequest(
79+
CardPaymentServiceRequestResponse createGovPayCardPaymentRequest(
8180
@PathVariable("service-request-reference") String serviceReqReference,
8281
@RequestHeader("Authorization") String authorization,
8382
@RequestHeader("ServiceAuthorization") String serviceAuthorization,
8483
@RequestBody CardPaymentServiceRequestDTO paymentRequest
8584
);
86-
87-
@GetMapping(value = "cases/{ccd-case-number}/paymentgroups")
88-
PaymentGroupResponse getCasePaymentGroups(
89-
@PathVariable("ccd-case-number") String ccdCaseNumber,
90-
@RequestHeader("Authorization") String authorization,
91-
@RequestHeader("ServiceAuthorization") String serviceAuthorization
92-
);
93-
9485
}

src/main/java/uk/gov/hmcts/reform/payments/client/PaymentsClient.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import uk.gov.hmcts.reform.payments.request.PBAServiceRequestDTO;
1313
import uk.gov.hmcts.reform.payments.response.CardPaymentServiceRequestResponse;
1414
import uk.gov.hmcts.reform.payments.response.PBAServiceRequestResponse;
15-
import uk.gov.hmcts.reform.payments.response.PaymentGroupResponse;
1615
import uk.gov.hmcts.reform.payments.response.PaymentServiceResponse;
1716

1817
@Service
@@ -80,19 +79,15 @@ public PBAServiceRequestResponse createPbaPayment(String serviceReqReference, St
8079
);
8180
}
8281

83-
public PaymentGroupResponse getCasePaymentGroups(String ccdCaseNumber, String authorisation) {
84-
return paymentsApi.getCasePaymentGroups(ccdCaseNumber, authorisation, authTokenGenerator.generate());
85-
}
86-
87-
public CardPaymentServiceRequestResponse createCardPaymentServiceRequest(
82+
public CardPaymentServiceRequestResponse createGovPayCardPaymentRequest(
8883
String serviceReqReference,
8984
String authorization,
9085
CardPaymentServiceRequestDTO paymentRequest) {
91-
return paymentsApi.createCardPaymentServiceRequest(
86+
return paymentsApi.createGovPayCardPaymentRequest(
9287
serviceReqReference, authorization, authTokenGenerator.generate(), paymentRequest);
9388
}
9489

95-
public PaymentDto getCardPaymentStatus(String paymentReference, String authorization) {
96-
return paymentsApi.getCardPaymentStatus(paymentReference, authorization, authTokenGenerator.generate());
90+
public PaymentDto getGovPayCardPaymentStatus(String paymentReference, String authorization) {
91+
return paymentsApi.getGovPayCardPaymentStatus(paymentReference, authorization, authTokenGenerator.generate());
9792
}
9893
}

src/main/java/uk/gov/hmcts/reform/payments/client/models/PaymentGroupDto.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/uk/gov/hmcts/reform/payments/client/models/RemissionDto.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/main/java/uk/gov/hmcts/reform/payments/response/PaymentGroupResponse.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/test/java/uk/gov/hmcts/reform/payments/client/PaymentsClientTest.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
import uk.gov.hmcts.reform.payments.client.models.CasePaymentRequestDto;
1212
import uk.gov.hmcts.reform.payments.client.models.FeeDto;
1313
import uk.gov.hmcts.reform.payments.request.CardPaymentRequest;
14+
import uk.gov.hmcts.reform.payments.request.CardPaymentServiceRequestDTO;
1415
import uk.gov.hmcts.reform.payments.request.CreateServiceRequestDTO;
1516
import uk.gov.hmcts.reform.payments.request.CreditAccountPaymentRequest;
1617
import uk.gov.hmcts.reform.payments.request.PBAServiceRequestDTO;
1718

1819
import java.math.BigDecimal;
1920

20-
import static java.math.BigDecimal.ROUND_UNNECESSARY;
2121
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2222
import static org.mockito.ArgumentMatchers.anyString;
2323
import static org.mockito.Mockito.doThrow;
@@ -27,7 +27,7 @@
2727
@ExtendWith(MockitoExtension.class)
2828
class PaymentsClientTest {
2929

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

3232
private static final String CCD_CASE_NUMBER = "UNKNOWN";
3333
private static final BigDecimal FEE_AMOUNT = TEN_2_DP;
@@ -65,6 +65,14 @@ class PaymentsClientTest {
6565
.siteId("site ID")
6666
.build();
6767

68+
private static final CardPaymentServiceRequestDTO CARD_PAYMENT_SERVICE_REQUEST =
69+
CardPaymentServiceRequestDTO.builder()
70+
.returnUrl("return-url")
71+
.language("English")
72+
.amount(new BigDecimal("232.00"))
73+
.currency("GBP")
74+
.build();
75+
6876
private static final CreateServiceRequestDTO SERVICE_REQUEST = CreateServiceRequestDTO.builder()
6977
.callBackUrl("callbackurl")
7078
.casePaymentRequest(CasePaymentRequestDto.builder().action("action").responsibleParty("party").build())
@@ -129,6 +137,22 @@ void createServiceRequestShouldPropagateExceptions() {
129137
.hasMessage("expected exception for create payment");
130138
}
131139

140+
@Test
141+
void createGovPayCardPaymentRequest() {
142+
client.createGovPayCardPaymentRequest("service-request-id",
143+
"authorisation", CARD_PAYMENT_SERVICE_REQUEST);
144+
verify(paymentsApi)
145+
.createGovPayCardPaymentRequest("service-request-id",
146+
"authorisation", "auth token", CARD_PAYMENT_SERVICE_REQUEST);
147+
}
148+
149+
@Test
150+
void getGovPayCardPaymentStatus() {
151+
client.getGovPayCardPaymentStatus("payment-reference", "authorisation");
152+
verify(paymentsApi)
153+
.getGovPayCardPaymentStatus("payment-reference", "authorisation", "auth token");
154+
}
155+
132156
@Test
133157
void createCreditAccountPaymentShouldInvokePaymentsApi() {
134158
client.createCreditAccountPayment("authorisation", CREDIT_ACCOUNT_PAYMENT);

src/test/java/uk/gov/hmcts/reform/payments/client/PaymentsClientWiremockTest.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import uk.gov.hmcts.reform.payments.client.models.FeeDto;
1616
import uk.gov.hmcts.reform.payments.client.models.PaymentDto;
1717
import uk.gov.hmcts.reform.payments.request.CardPaymentRequest;
18+
import uk.gov.hmcts.reform.payments.request.CardPaymentServiceRequestDTO;
1819
import uk.gov.hmcts.reform.payments.request.CreditAccountPaymentRequest;
20+
import uk.gov.hmcts.reform.payments.response.CardPaymentServiceRequestResponse;
1921

2022
import java.math.BigDecimal;
2123
import java.util.Map;
@@ -116,6 +118,28 @@ void testCreateCardPayment() {
116118
);
117119
}
118120

121+
@Test
122+
void testCreateGovPayCardPaymentRequest() {
123+
CardPaymentServiceRequestResponse payment = paymentsClient.createGovPayCardPaymentRequest(
124+
"2023-1701090705688",
125+
"Authorisation",
126+
CardPaymentServiceRequestDTO.builder()
127+
.returnUrl("return-url")
128+
.language("English")
129+
.amount(new BigDecimal("232.00"))
130+
.currency("GBP")
131+
.build()
132+
);
133+
assertNotNull(payment);
134+
assertAll(
135+
() -> assertEquals("RC-1701-0909-0602-0418", payment.getPaymentReference()),
136+
() -> assertEquals("lbh2ogknloh9p3b4lchngdfg63", payment.getExternalReference()),
137+
() -> assertEquals("Initiated", payment.getStatus()),
138+
() -> assertEquals("https://card.payments.service.gov.uk/secure/7b0716b2-40c4-413e-b62e-72c599c91960",
139+
payment.getNextUrl())
140+
);
141+
}
142+
119143
@Test
120144
void testRetrieveCardPayment() {
121145
PaymentDto payment = paymentsClient.retrieveCardPayment("Authorisation", "RC-1566-2093-5462-0545");
@@ -139,6 +163,45 @@ void testRetrieveCardPayment() {
139163
);
140164
}
141165

166+
@Test
167+
void testRetrieveCardPaymentStatus() {
168+
PaymentDto payment = paymentsClient.getGovPayCardPaymentStatus("RC-1701-0909-0602-0418", "Authorisation");
169+
assertNotNull(payment);
170+
assertAll(
171+
() -> assertEquals("RC-1701-0909-0602-0418", payment.getPaymentReference()),
172+
() -> assertEquals(new BigDecimal("232.00"), payment.getAmount()),
173+
() -> assertEquals("GBP", payment.getCurrency()),
174+
() -> assertEquals("online", payment.getChannel()),
175+
() -> assertEquals("card", payment.getMethod()),
176+
() -> assertEquals("gov pay", payment.getExternalProvider()),
177+
() -> assertEquals("Success", payment.getStatus()),
178+
() -> assertEquals("lbh2ogknloh9p3b4lchngdfg63", payment.getExternalReference()),
179+
() -> assertEquals("2023-1701090705688", payment.getPaymentGroupReference()),
180+
() -> assertNotNull(payment.getFees()),
181+
() -> assertAll(
182+
() -> assertEquals(
183+
"FEE0336",
184+
payment.getFees()[0].getCode()
185+
),
186+
() -> assertEquals(
187+
new BigDecimal("232.00"),
188+
payment.getFees()[0].getCalculatedAmount()
189+
)
190+
),
191+
() -> assertNotNull(payment.getStatusHistories()),
192+
() -> assertAll(
193+
() -> assertEquals(
194+
"Initiated",
195+
payment.getStatusHistories()[0].getStatus()
196+
),
197+
() -> assertEquals(
198+
"Success",
199+
payment.getStatusHistories()[1].getStatus()
200+
)
201+
)
202+
);
203+
}
204+
142205
@Test
143206
void testCancelCardPayment() {
144207
// test passes if no exceptions are thrown
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"id" : "f4db6fd2-dea4-4a3a-80df-643b2cf1344d",
3+
"name" : "card-payments_rc-1701-0909-0602-0418",
4+
"request" : {
5+
"url" : "/payments/RC-1701-0909-0602-0418",
6+
"method" : "GET"
7+
},
8+
"response" : {
9+
"status" : 200,
10+
"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}",
11+
"headers" : {
12+
"X-Content-Type-Options" : "nosniff",
13+
"X-XSS-Protection" : "1; mode=block",
14+
"Cache-Control" : "no-cache, no-store, max-age=0, must-revalidate",
15+
"Pragma" : "no-cache",
16+
"Expires" : "0",
17+
"X-Frame-Options" : "DENY",
18+
"Content-Type" : "application/json;charset=UTF-8",
19+
"Date" : "Mon, 19 Aug 2019 10:09:15 GMT"
20+
}
21+
},
22+
"uuid" : "f4db6fd2-dea4-4a3a-80df-643b2cf1344d",
23+
"persistent" : true
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"id": "603a01d7-0c0b-494d-ba4c-0d7165238522",
3+
"name": "gov-pay-card-payments",
4+
"request": {
5+
"url": "/service-request/2023-1701090705688/card-payments",
6+
"method": "POST",
7+
"bodyPatterns": [
8+
{
9+
"equalToJson": "{\n \"return-url\" : \"return-url\",\n \"language\" : \"English\",\n \"currency\" : \"GBP\",\n \"amount\" : 232.00\n}",
10+
"ignoreArrayOrder": true,
11+
"ignoreExtraElements": true
12+
}
13+
]
14+
},
15+
"response": {
16+
"status": 201,
17+
"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}",
18+
"headers": {
19+
"X-Content-Type-Options": "nosniff",
20+
"X-XSS-Protection": "1; mode=block",
21+
"Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
22+
"Pragma": "no-cache",
23+
"Expires": "0",
24+
"X-Frame-Options": "DENY",
25+
"Content-Type": "application/json;charset=UTF-8",
26+
"Date": "Mon, 19 Aug 2019 09:46:54 GMT"
27+
}
28+
},
29+
"uuid": "603a01d7-0c0b-494d-ba4c-0d7165238522",
30+
"persistent": true
31+
}

0 commit comments

Comments
 (0)