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

CIV-14064 Handle additional fee #1390

Merged
merged 7 commits into from
Jul 24, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package uk.gov.hmcts.reform.civil.handler.callback.camunda.fee;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.math.BigDecimal;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -11,6 +13,9 @@
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.config.GeneralAppFeesConfiguration;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.launchdarkly.FeatureToggleService;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.Fee;
import uk.gov.hmcts.reform.civil.model.genapplication.GAPbaDetails;
import uk.gov.hmcts.reform.civil.service.GeneralAppFeesService;
Expand All @@ -34,6 +39,7 @@ public class AdditionalFeeValueCallbackHandler extends CallbackHandler {
private final GeneralAppFeesConfiguration feesConfiguration;
private final JudicialDecisionHelper judicialDecisionHelper;
private final ObjectMapper objectMapper;
private final FeatureToggleService featureToggleService;

@Override
public String camundaActivityId() {
Expand All @@ -57,12 +63,18 @@ private CallbackResponse getAdditionalFeeValue(CallbackParams callbackParams) {

if (judicialDecisionHelper.isApplicationUncloakedWithAdditionalFee(caseData)) {
Fee feeForGA = feeService.getFeeForGA(feesConfiguration.getApplicationUncloakAdditionalFee(), null, null);

BigDecimal applicationFee = Optional.ofNullable(caseData.getGeneralAppPBADetails())
.map(details -> details.getFee())
.map(fee -> fee.getCalculatedAmountInPence())
.orElse(null);
GAPbaDetails generalAppPBADetails = caseData.getGeneralAppPBADetails()
.toBuilder().fee(feeForGA).build();

caseData = caseData.toBuilder().generalAppPBADetails(generalAppPBADetails).build();

CaseData.CaseDataBuilder builder = caseData.toBuilder();
builder.generalAppPBADetails(generalAppPBADetails);
if (featureToggleService.isGaForLipsEnabled() && caseData.getIsGaApplicantLip() == YesOrNo.YES) {
builder.applicationFeeAmountInPence(applicationFee);
}
caseData = builder.build();
}
return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseData.toMap(objectMapper))
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package uk.gov.hmcts.reform.civil.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -324,6 +326,8 @@ public class CaseData implements MappableObject {
private final HelpWithFeesMoreInformation helpWithFeesMoreInformationGa;
private final HelpWithFeesMoreInformation helpWithFeesMoreInformationAdditional;
private final YesOrNo generalAppAskForCosts;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private final BigDecimal applicationFeeAmountInPence;
@JsonUnwrapped
private FeePaymentOutcomeDetails feePaymentOutcomeDetails;

Expand All @@ -337,6 +341,11 @@ public boolean isHWFTypeAdditional() {
return getHwfFeeType() == FeeType.ADDITIONAL;
}

@JsonIgnore
public boolean isAdditionalFeeRequested() {
return getGeneralAppPBADetails() != null && getGeneralAppPBADetails().getAdditionalPaymentServiceRef() != null;
}

public boolean hasNoOngoingBusinessProcess() {
return businessProcess == null
|| businessProcess.getStatus() == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public CardPaymentStatusResponse createGovPaymentRequest(String caseReference, S
.build();
CardPaymentServiceRequestResponse govPayCardPaymentRequest = paymentStatusService
.createGovPayCardPaymentRequest(
generalAppPbaDetails.getServiceReqReference(),
caseData.isAdditionalFeeRequested()
? generalAppPbaDetails.getAdditionalPaymentServiceRef()
: generalAppPbaDetails.getServiceReqReference(),
authorization,
requestDto
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.civil.config.PaymentsConfiguration;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.genapplication.GAPbaDetails;
import uk.gov.hmcts.reform.payments.client.InvalidPaymentRequestException;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void validateRequest(CaseData caseData) {
error = "Fees are not set correctly.";
}
if (caseData.getGeneralAppApplnSolicitor() == null
|| isBlank(caseData.getGeneralAppApplnSolicitor().getOrganisationIdentifier())) {
|| (caseData.getIsGaApplicantLip() != YesOrNo.YES && isBlank(caseData.getGeneralAppApplnSolicitor().getOrganisationIdentifier()))) {
error = "Applicant's organization details not received.";
}
if (!isBlank(error)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.ccd.client.model.Event;
import uk.gov.hmcts.reform.ccd.client.model.StartEventResponse;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.enums.PaymentStatus;
import uk.gov.hmcts.reform.civil.exceptions.CaseDataUpdateException;
import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter;
Expand All @@ -20,8 +21,6 @@

import java.util.Map;

import static uk.gov.hmcts.reform.civil.callback.CaseEvent.INITIATE_GENERAL_APPLICATION_AFTER_PAYMENT;

@Slf4j
@Service
@RequiredArgsConstructor
Expand All @@ -46,10 +45,12 @@ public void updatePaymentStatus(String caseReference, CardPaymentStatusResponse
}

private void createEvent(CaseData caseData, String caseReference) {

CaseEvent caseEvent = caseData.isAdditionalFeeRequested()
? CaseEvent.MODIFY_STATE_AFTER_ADDITIONAL_FEE_PAID
: CaseEvent.INITIATE_GENERAL_APPLICATION_AFTER_PAYMENT;
StartEventResponse startEventResponse = coreCaseDataService.startUpdate(
caseReference,
INITIATE_GENERAL_APPLICATION_AFTER_PAYMENT
caseEvent
);

CaseDataContent caseDataContent = buildCaseDataContent(
Expand Down Expand Up @@ -86,8 +87,11 @@ private CaseData updateCaseDataWithStateAndPaymentDetails(CardPaymentStatusRespo
.errorCode(cardPaymentStatusResponse.getErrorCode())
.errorMessage(cardPaymentStatusResponse.getErrorDescription())
.build();

pbaDetails = pbaDetailsBuilder.paymentDetails(paymentDetails).build();
if (caseData.isAdditionalFeeRequested()) {
pbaDetails = pbaDetailsBuilder.additionalPaymentDetails(paymentDetails).build();
} else {
pbaDetails = pbaDetailsBuilder.paymentDetails(paymentDetails).build();
}
return caseData.toBuilder()
.generalAppPBADetails(pbaDetails)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest;
import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter;
import uk.gov.hmcts.reform.civil.launchdarkly.FeatureToggleService;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.Fee;
import uk.gov.hmcts.reform.civil.model.genapplication.GAApplicationType;
Expand Down Expand Up @@ -59,6 +60,8 @@ class AdditionalFeeValueCallbackHandlerTest extends BaseCallbackHandlerTest {
private ObjectMapper objectMapper;
@MockBean
JudicialDecisionHelper judicialDecisionHelper;
@MockBean
FeatureToggleService featureToggleService;

@BeforeEach
void setup() {
Expand Down Expand Up @@ -146,6 +149,34 @@ void shouldNotGetAdditionalFeeValue_WhenApplicationIsNotUncloaked() {
verify(generalAppFeesService, never()).getFeeForGA(any(), any(), any());
}

@Test
void shouldSetAppplicationFeeAmount_WhenApplicationUncloaked() {
when(featureToggleService.isGaForLipsEnabled()).thenReturn(true);
when(generalAppFeesService.getFeeForGA(any(), any(), any()))
.thenReturn(Fee.builder().calculatedAmountInPence(
TEST_FEE_AMOUNT_POUNDS_167).code(TEST_FEE_CODE).version(VERSION).build());

var caseData = CaseDataBuilder.builder()
.judicialDecisionWithUncloakRequestForInformationApplication(
REQUEST_MORE_INFORMATION, YesOrNo.NO, YesOrNo.NO)
.build();
caseData = caseData.toBuilder()
.isGaApplicantLip(YesOrNo.YES)
.build();

when(judicialDecisionHelper
.isApplicationUncloakedWithAdditionalFee(caseData)).thenReturn(true);
when(judicialDecisionHelper
.containsTypesNeedNoAdditionalFee(caseData)).thenReturn(false);

BigDecimal expectedApplicationFeeAmount = caseData.getGeneralAppPBADetails().getFee().getCalculatedAmountInPence();
params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);

CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class);
assertThat(responseCaseData.getApplicationFeeAmountInPence()).isEqualTo(expectedApplicationFeeAmount);
}

@Test
void shouldThrowError_whenRunTimeExceptionHappens() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ class FeesPaymentServiceTest {
private UpdatePaymentStatusService updatePaymentStatusService;

private ObjectMapper objectMapper = new ObjectMapper();
private CaseData caseData;

@BeforeEach
void before() {
CaseData caseData = CaseData.builder().ccdCaseReference(2801090368574910L)
caseData = CaseData.builder().ccdCaseReference(2801090368574910L)
.generalAppPBADetails(GAPbaDetails.builder().serviceReqReference("2023-1701090705688")
.fee(Fee.builder().calculatedAmountInPence(new BigDecimal("23200")).build())
.build())
.parentCaseReference("1701090368574910")
.build();

when(caseDetailsConverter.toCaseData(any())).thenReturn(caseData);
}

Expand All @@ -113,6 +113,28 @@ void shouldCreateGovPayPaymentUrlForServiceRequestPayment() {

}

@Test
@SneakyThrows
void shouldCreateGovPayPaymentUrlForServiceRequestAdditionalPayment() {
caseData = caseData.toBuilder().generalAppPBADetails(caseData.getGeneralAppPBADetails().toBuilder()
.additionalPaymentServiceRef("2023-1701090705600").build()).build();
when(caseDetailsConverter.toCaseData(any())).thenReturn(caseData);
CardPaymentServiceRequestResponse response = buildServiceRequestResponse();

when(paymentsClient.createGovPayCardPaymentRequest(
"2023-1701090705600",
BEARER_TOKEN,
CARD_PAYMENT_SERVICE_REQUEST
)).thenReturn(response);

CardPaymentStatusResponse govPaymentRequest = feesPaymentService.createGovPaymentRequest(
"2801090368574910",
BEARER_TOKEN
);
assertThat(govPaymentRequest).isEqualTo(CardPaymentStatusResponse.from(response));

}

@Test
@SneakyThrows
void shouldNotCreateGovPayPaymentUrlForMissingPbaDetails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.civil.config.PaymentsConfiguration;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.Fee;
import uk.gov.hmcts.reform.civil.model.genapplication.GAPbaDetails;
Expand Down Expand Up @@ -196,6 +197,23 @@ void validateRequestShouldThrowAnError_whenApplicantSolicitorOrgDetailsAreNotSet
assertThat(exception.getMessage()).isEqualTo("Applicant's organization details not received.");
}

@Test
void validateRequestShouldNotThrowAnError_whenApplicantSolicitorOrgDetailsAreNotSetForLiPApplicant() {
CaseData caseData = CaseData.builder()
.isGaApplicantLip(YesOrNo.YES)
.generalAppPBADetails(GAPbaDetails.builder()
.fee(Fee.builder()
.calculatedAmountInPence(BigDecimal.TEN)
.version("version")
.code("code").build()).build())
.generalAppApplnSolicitor(GASolicitorDetailsGAspec.builder().build())
.build();

paymentsService.validateRequest(caseData);

assertThat(caseData).isNotNull();
}

@Test
void shouldCreateCreditAccountPayment_whenValidCaseDetails() {
CaseData caseData = CaseDataBuilder.builder().buildMakePaymentsCaseData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand All @@ -26,6 +27,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.INITIATE_GENERAL_APPLICATION_AFTER_PAYMENT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MODIFY_STATE_AFTER_ADDITIONAL_FEE_PAID;
import static uk.gov.hmcts.reform.civil.enums.CaseState.CASE_PROGRESSION;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -75,6 +77,39 @@ public void shouldSubmitCitizenApplicationFeePaymentEvent() {

}

@Test
public void shouldSubmitCitizenAdditionalFeePaymentEvent() {

CaseData caseData = CaseData.builder()
.ccdState(CASE_PROGRESSION)
.businessProcess(BusinessProcess.builder()
.status(BusinessProcessStatus.READY)
.camundaEvent(BUSINESS_PROCESS)
.build())
.generalAppPBADetails(GAPbaDetails.builder().additionalPaymentDetails(PaymentDetails.builder()
.customerReference("RC-1604-0739-2145-4711")
.build())
.additionalPaymentServiceRef("2023-1701090705600").build())
.applicationFeeAmountInPence(new BigDecimal("10000"))
.build();
CaseDetails caseDetails = buildCaseDetails(caseData);

when(coreCaseDataService.getCase(CASE_ID)).thenReturn(caseDetails);
when(caseDetailsConverter.toCaseData(caseDetails)).thenReturn(caseData);
when(coreCaseDataService.startUpdate(any(), any())).thenReturn(startEventResponse(
caseDetails,
MODIFY_STATE_AFTER_ADDITIONAL_FEE_PAID
));
when(coreCaseDataService.submitUpdate(any(), any())).thenReturn(caseData);

updatePaymentStatusService.updatePaymentStatus(String.valueOf(CASE_ID), getCardPaymentStatusResponse());

verify(coreCaseDataService, times(1)).getCase(Long.valueOf(CASE_ID));
verify(coreCaseDataService).startUpdate(String.valueOf(CASE_ID), MODIFY_STATE_AFTER_ADDITIONAL_FEE_PAID);
verify(coreCaseDataService).submitUpdate(any(), any());

}

private CaseDetails buildCaseDetails(CaseData caseData) {
return CaseDetails.builder()
.data(objectMapper.convertValue(
Expand Down
Loading