generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
875 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
.../uk/gov/hmcts/reform/civil/handler/callback/user/FeePaymentOutcomeHWFCallBackHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package uk.gov.hmcts.reform.civil.handler.callback.user; | ||
|
||
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; | ||
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; | ||
import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID; | ||
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; | ||
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 uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; | ||
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; | ||
import uk.gov.hmcts.reform.civil.callback.Callback; | ||
import uk.gov.hmcts.reform.civil.callback.CallbackParams; | ||
import uk.gov.hmcts.reform.civil.callback.CaseEvent; | ||
import uk.gov.hmcts.reform.civil.enums.YesOrNo; | ||
import uk.gov.hmcts.reform.civil.model.BusinessProcess; | ||
import uk.gov.hmcts.reform.civil.model.CaseData; | ||
import uk.gov.hmcts.reform.civil.service.PaymentRequestUpdateCallbackService; | ||
import uk.gov.hmcts.reform.civil.utils.HwFFeeTypeService; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.collect.ImmutableMap; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
public class FeePaymentOutcomeHWFCallBackHandler extends HWFCallbackHandlerBase { | ||
|
||
public static final String WRONG_REMISSION_TYPE_SELECTED = "Incorrect remission type selected"; | ||
public static final String CASE_STATE_INVALID = "Case is in invalid state"; | ||
public static final String PROCESS_FEE_PAYMENT_FAILED = "Process fee payment failed"; | ||
private static final List<CaseEvent> EVENTS = List.of(CaseEvent.FEE_PAYMENT_OUTCOME_GA); | ||
|
||
public FeePaymentOutcomeHWFCallBackHandler(ObjectMapper objectMapper, | ||
PaymentRequestUpdateCallbackService paymentRequestUpdateCallbackService) { | ||
super(objectMapper, EVENTS, paymentRequestUpdateCallbackService); | ||
} | ||
|
||
@Override | ||
protected Map<String, Callback> callbacks() { | ||
return new ImmutableMap.Builder<String, Callback>() | ||
.put(callbackKey(ABOUT_TO_START), this::setData) | ||
.put(callbackKey(ABOUT_TO_SUBMIT), this::submitFeePaymentOutcome) | ||
.put(callbackKey(MID, "remission-type"), this::validateSelectedRemissionType) | ||
.put(callbackKey(SUBMITTED), this::emptySubmittedCallbackResponse) | ||
.build(); | ||
} | ||
|
||
private CallbackResponse validateSelectedRemissionType(CallbackParams callbackParams) { | ||
CaseData caseData = callbackParams.getCaseData(); | ||
var errors = new ArrayList<String>(); | ||
|
||
if ((caseData.isHWFTypeApplication() | ||
&& caseData.getFeePaymentOutcomeDetails().getHwfFullRemissionGrantedForGa() == YesOrNo.YES | ||
&& Objects.nonNull(caseData.getGaHwfDetails()) | ||
&& Objects.nonNull(caseData.getGaHwfDetails().getOutstandingFeeInPounds()) | ||
&& !Objects.equals(caseData.getGaHwfDetails().getOutstandingFeeInPounds(), BigDecimal.ZERO)) | ||
|| (caseData.isHWFTypeAdditional() | ||
&& caseData.getFeePaymentOutcomeDetails().getHwfFullRemissionGrantedForAdditional() == YesOrNo.YES | ||
&& Objects.nonNull(caseData.getAdditionalHwfDetails()) | ||
&& Objects.nonNull(caseData.getAdditionalHwfDetails().getOutstandingFeeInPounds()) | ||
&& !Objects.equals(caseData.getAdditionalHwfDetails().getOutstandingFeeInPounds(), BigDecimal.ZERO))) { | ||
errors.add(WRONG_REMISSION_TYPE_SELECTED); | ||
} | ||
return AboutToStartOrSubmitCallbackResponse.builder() | ||
.errors(errors) | ||
.build(); | ||
} | ||
|
||
private CallbackResponse submitFeePaymentOutcome(CallbackParams callbackParams) { | ||
CaseData caseData = callbackParams.getCaseData(); | ||
CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); | ||
|
||
if (caseData.isHWFTypeApplication()) { | ||
LocalDate issueDate = LocalDate.now(); | ||
caseDataBuilder.issueDate(issueDate).build(); | ||
} | ||
caseData = caseDataBuilder.build(); | ||
caseData = HwFFeeTypeService.updateHwfReferenceNumber(caseData); | ||
|
||
List<String> errors = new ArrayList<>(); | ||
|
||
assert paymentRequestUpdateCallbackService != null; | ||
CaseData processedCaseData = paymentRequestUpdateCallbackService.processHwf(caseData); | ||
if (Objects.isNull(processedCaseData)) { | ||
errors.add(PROCESS_FEE_PAYMENT_FAILED); | ||
} else { | ||
if (processedCaseData.isHWFTypeApplication()) { | ||
caseData = processedCaseData.toBuilder() | ||
.businessProcess(BusinessProcess.ready(INITIATE_GENERAL_APPLICATION_AFTER_PAYMENT)).build(); | ||
} else if (processedCaseData.isHWFTypeAdditional()) { | ||
caseData = processedCaseData.toBuilder() | ||
.businessProcess(BusinessProcess.ready(MODIFY_STATE_AFTER_ADDITIONAL_FEE_PAID)).build(); | ||
} else { | ||
errors.add(CASE_STATE_INVALID); | ||
} | ||
} | ||
|
||
return AboutToStartOrSubmitCallbackResponse.builder() | ||
.data(caseData.toMap(objectMapper)) | ||
.errors(errors) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/HWFCallbackHandlerBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package uk.gov.hmcts.reform.civil.handler.callback.user; | ||
|
||
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; | ||
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; | ||
import uk.gov.hmcts.reform.civil.callback.CallbackHandler; | ||
import uk.gov.hmcts.reform.civil.callback.CallbackParams; | ||
import uk.gov.hmcts.reform.civil.callback.CaseEvent; | ||
import uk.gov.hmcts.reform.civil.model.CaseData; | ||
import uk.gov.hmcts.reform.civil.service.PaymentRequestUpdateCallbackService; | ||
import uk.gov.hmcts.reform.civil.utils.HwFFeeTypeService; | ||
|
||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
abstract class HWFCallbackHandlerBase extends CallbackHandler { | ||
|
||
protected final ObjectMapper objectMapper; | ||
protected final List<CaseEvent> events; | ||
protected final PaymentRequestUpdateCallbackService paymentRequestUpdateCallbackService; | ||
|
||
public HWFCallbackHandlerBase(ObjectMapper objectMapper, | ||
List<CaseEvent> events, | ||
PaymentRequestUpdateCallbackService paymentRequestUpdateCallbackService) { | ||
this.objectMapper = objectMapper; | ||
this.events = events; | ||
this.paymentRequestUpdateCallbackService = paymentRequestUpdateCallbackService; | ||
} | ||
|
||
public HWFCallbackHandlerBase(ObjectMapper objectMapper, | ||
List<CaseEvent> events) { | ||
this.objectMapper = objectMapper; | ||
this.events = events; | ||
this.paymentRequestUpdateCallbackService = null; | ||
} | ||
|
||
@Override | ||
public List<CaseEvent> handledEvents() { | ||
return events; | ||
} | ||
|
||
protected CallbackResponse setData(CallbackParams callbackParams) { | ||
CaseData caseData = callbackParams.getCaseData(); | ||
CaseData.CaseDataBuilder caseDataBuilder = HwFFeeTypeService.updateFeeType(caseData); | ||
return AboutToStartOrSubmitCallbackResponse.builder() | ||
.data(caseDataBuilder.build().toMap(objectMapper)) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.