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

PAY-7103: Calculate the AMOUNT DUE and OVERPAYMENTS for ( Issue refun… #1670

Merged
merged 16 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
3d578a7
PAY-7103: Calculate the AMOUNT DUE and OVERPAYMENTS for ( Issue refun…
Thor-tech-of-metal Jun 14, 2024
8e74a95
PAY-7103: Calculate the AMOUNT DUE and OVERPAYMENTS for ( Issue refun…
Thor-tech-of-metal Jun 17, 2024
575a667
PAY-7103: Calculate the AMOUNT DUE and OVERPAYMENTS for ( Issue refun…
Thor-tech-of-metal Jun 17, 2024
7f5e21c
PAY-7103: Calculate the AMOUNT DUE and OVERPAYMENTS for ( Issue refun…
Thor-tech-of-metal Jun 17, 2024
52bf11e
PAY-7103: Calculate the AMOUNT DUE and OVERPAYMENTS for ( Issue refun…
Thor-tech-of-metal Jun 17, 2024
b0058d7
PAY-7103: Calculate the AMOUNT DUE and OVERPAYMENTS for ( Issue refun…
Thor-tech-of-metal Jul 4, 2024
5908e57
Triggering build
Thor-tech-of-metal Jul 4, 2024
d3dab04
PAY-7103: Calculate the AMOUNT DUE and OVERPAYMENTS for ( Issue refun…
Thor-tech-of-metal Jul 4, 2024
b82e7ff
PAY-7103: Calculate the AMOUNT DUE and OVERPAYMENTS for ( Issue refun…
Thor-tech-of-metal Jul 4, 2024
ef89d01
PAY-7200: Front end changes to Calculate the AMOUNT DUE and OVERPAYME…
Thor-tech-of-metal Jul 15, 2024
c4f7536
Updating Terraform Formatting
hmcts-jenkins-a-to-c[bot] Jul 15, 2024
f7934f6
Merge branch 'master' of github.com:hmcts/ccpay-payment-app into PAY-…
Thor-tech-of-metal Jul 15, 2024
1828516
Merge branch 'PAY-7103-NEW' of github.com:hmcts/ccpay-payment-app int…
Thor-tech-of-metal Jul 15, 2024
164ecc2
PAY-7200: Front end changes to Calculate the AMOUNT DUE and OVERPAYME…
Thor-tech-of-metal Jul 15, 2024
2954937
PAY-7200: Front end changes to Calculate the AMOUNT DUE and OVERPAYME…
Thor-tech-of-metal Aug 1, 2024
aedd72f
PAY-7200: Front end changes to Calculate the AMOUNT DUE and OVERPAYME…
Thor-tech-of-metal Aug 1, 2024
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
2 changes: 1 addition & 1 deletion api/src/contractTest/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ logging:
org.springframework.web: INFO
au.com.dius.pact: DEBUG
pattern:
console: "%d{yyyy-MMM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{15} - %msg%n"
console: "%d{yyyy-MMM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{15} - %msg%n"
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.util.MultiValueMap;
Expand All @@ -20,6 +22,7 @@
import uk.gov.hmcts.payment.api.dto.PaymentGroupDto;
import uk.gov.hmcts.payment.api.dto.PaymentGroupResponse;
import uk.gov.hmcts.payment.api.dto.PaymentSearchCriteria;
import uk.gov.hmcts.payment.api.dto.RefundListDtoResponse;
import uk.gov.hmcts.payment.api.dto.mapper.PaymentDtoMapper;
import uk.gov.hmcts.payment.api.dto.mapper.PaymentGroupDtoMapper;
import uk.gov.hmcts.payment.api.model.PaymentFeeLink;
Expand All @@ -41,6 +44,8 @@
@Validated
public class CaseController {

private static final Logger LOG = LoggerFactory.getLogger(CaseController.class);

private final PaymentService<PaymentFeeLink, String> paymentService;
private final PaymentGroupService<PaymentFeeLink, String> paymentGroupService;
private final PaymentDtoMapper paymentDtoMapper;
Expand Down Expand Up @@ -113,6 +118,11 @@ public PaymentGroupResponse retrieveCasePaymentGroups(@PathVariable(name = "ccdc

paymentGroupResponse = paymentRefundsService.checkRefundAgainstRemissionV2(headers, paymentGroupResponse, ccdCaseNumber);


RefundListDtoResponse refundListDtoResponse = paymentRefundsService.getRefundsApprovedFromRefundService(ccdCaseNumber,headers);
if (refundListDtoResponse != null) {
paymentGroups.stream().forEach(paymentGroup -> paymentGroup.setRefunds(refundListDtoResponse.getRefundList()));
}
return paymentGroupResponse;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ public class PaymentGroupDto {

private boolean isAnyPaymentDisputed;

private List<RefundDto> refunds;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ ResponseEntity<RefundResponse> createAndValidateRetrospectiveRemissionRequest(


void deleteByRefundReference(String refundReference, MultiValueMap<String, String> headers);

RefundListDtoResponse getRefundsApprovedFromRefundService(String ccdCaseNumber, MultiValueMap<String, String> headers);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.time.temporal.ChronoUnit;

import org.apache.commons.lang3.EnumUtils;
import org.apache.poi.hpsf.Decimal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -248,6 +247,54 @@ public ResponseEntity updateTheRemissionAmount(String paymentReference, Resubmit
}
return new ResponseEntity<>(null, HttpStatus.OK);
}

public RefundListDtoResponse getRefundsApprovedFromRefundService (String ccdCaseNumber, MultiValueMap<String, String> headers) {
final var refundListDtoResponse = getRefundsForCalculations(ccdCaseNumber, headers);
if (refundListDtoResponse == null){
return RefundListDtoResponse.buildRefundListWith().refundList(new ArrayList<>()).build();
}
return RefundListDtoResponse.buildRefundListWith()
.refundList(refundListDtoResponse.getRefundList()).build();
}

private RefundListDtoResponse getRefundsForCalculations(String ccdCaseNumber, MultiValueMap<String, String> headers) {

RefundListDtoResponse refundListDtoResponse = null;

UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(refundApiUrl + REFUND_ENDPOINT).queryParam("ccdCaseNumber",ccdCaseNumber);

LOG.info("builder.toUriString() : {}", builder.toUriString());

try {

LOG.info("restTemplateRefundsGroup : {}", restTemplateRefundsGroup);

// call refund app
ResponseEntity<RefundListDtoResponse> refundListDtoResponseEntity = restTemplateRefundsGroup
.exchange(builder.toUriString(), HttpMethod.GET, createEntity(headers), RefundListDtoResponse.class);

return refundListDtoResponseEntity.hasBody() ? refundListDtoResponseEntity.getBody() : null;

} catch (HttpClientErrorException httpClientErrorException) {

if (httpClientErrorException.getStatusCode().equals(HttpStatus.BAD_REQUEST)
&& httpClientErrorException.getMessage().equals("Refund list is empty for given criteria")) {
LOG.info("The refund list is empty.", httpClientErrorException);
return RefundListDtoResponse.buildRefundListWith().refundList(new ArrayList<>()).build();
} else {
LOG.error("Client err ", httpClientErrorException);
}
} catch (Exception exception) {
exception.printStackTrace();
if (exception.getCause() != null) {
LOG.info("exception.getCause(): " + exception.getCause());
LOG.info("exception.getCause().getMessage(): " + exception.getCause().getMessage());
}
LOG.error("Client err ", exception);
}
return refundListDtoResponse;

}
private RefundListDtoResponse getRefundsFromRefundService(String ccdCaseNumber, MultiValueMap<String, String> headers) {


Expand Down Expand Up @@ -717,7 +764,8 @@ else if (!refundedFees.stream().flatMap(List::stream).anyMatch(fee.getId().toStr

refundListDtoResponse.getRefundList().forEach(refundDto -> {

if (refundDto.getPaymentReference().equals(paymentDto1.getReference())) {
if (refundDto.getPaymentReference().equals(paymentDto1.getReference()) &&
isAnAcceptedRefund(refundDto)) {
paymentDto1.setOverPayment(BigDecimal.ZERO);
}
});
Expand Down Expand Up @@ -747,7 +795,8 @@ else if (!refundedFees.stream().flatMap(List::stream).anyMatch(fee.getId().toStr
refundListDtoResponse.getRefundList().forEach(refundDto -> {

if (refundDto.getCcdCaseNumber().equals(feeDto.getCcdCaseNumber()) &&
(Arrays.stream(refundDto.getFeeIds().split(",")).anyMatch(feeDto.getId().toString()::equals))
(Arrays.stream(refundDto.getFeeIds().split(",")).anyMatch(feeDto.getId().toString()::equals)) &&
isAnAcceptedRefund(refundDto)
) {
feeDto.setOverPayment(BigDecimal.ZERO);
}
Expand All @@ -771,6 +820,9 @@ else if (!refundedFees.stream().flatMap(List::stream).anyMatch(fee.getId().toStr
return paymentGroupDto;
}

private boolean isAnAcceptedRefund(RefundDto refundDto){
return refundDto.getRefundStatus().getName().equals("Accepted");
}

public PaymentGroupResponse checkRefundAgainstRemissionV2(MultiValueMap<String, String> headers,
PaymentGroupResponse paymentGroupResponse, String ccdCaseNumber) {
Expand Down Expand Up @@ -900,7 +952,7 @@ else if (!refundedFees.stream().flatMap(List::stream).anyMatch(fee.getId().toStr
if (refundListDtoResponse != null) {
refundListDtoResponse.getRefundList().forEach(refundDto -> {

if (refundDto.getCcdCaseNumber().equals(feeDto.getCcdCaseNumber())
if (refundDto.getCcdCaseNumber().equals(feeDto.getCcdCaseNumber()) && isAnAcceptedRefund(refundDto)
) {
feeDto.setOverPayment(BigDecimal.ZERO);
}
Expand All @@ -913,7 +965,8 @@ else if (!refundedFees.stream().flatMap(List::stream).anyMatch(fee.getId().toStr

refundListDtoResponse.getRefundList().forEach(refundDto -> {

if (refundDto.getPaymentReference().equals(paymentDto.getReference())) {
if (refundDto.getPaymentReference().equals(paymentDto.getReference()) &&
isAnAcceptedRefund(refundDto)) {
paymentDto.setOverPayment(BigDecimal.ZERO);
}
});
Expand Down
Loading