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 3 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,7 @@
package uk.gov.hmcts.reform.civil.handler.callback.camunda.fee;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.math.BigDecimal;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -11,6 +12,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 +38,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 +62,15 @@ private CallbackResponse getAdditionalFeeValue(CallbackParams callbackParams) {

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

BigDecimal applicationFee = caseData.getGeneralAppPBADetails().getFee().getCalculatedAmountInPence();
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
10 changes: 10 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 lombok.Builder;
import lombok.Data;
import uk.gov.hmcts.reform.ccd.model.OrganisationPolicy;
Expand Down Expand Up @@ -321,6 +323,9 @@ public class CaseData implements MappableObject {
private final HelpWithFeesDetails additionalHwfDetails;
private final HelpWithFeesMoreInformation helpWithFeesMoreInformationGa;
private final HelpWithFeesMoreInformation helpWithFeesMoreInformationAdditional;
private final YesOrNo generalAppAskForCosts;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private final BigDecimal applicationFeeAmountInPence;

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

@JsonIgnore
public boolean isAdditionalFeeRequested() {
return getApplicationFeeAmountInPence() != null;
}

public boolean hasNoOngoingBusinessProcess() {
return businessProcess == null
|| businessProcess.getStatus() == null
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 @@ -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,38 @@ 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().paymentDetails(PaymentDetails.builder()
.customerReference("RC-1604-0739-2145-4711")
.build()).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