diff --git a/api/src/main/java/uk/gov/hmcts/payment/api/dto/mapper/PaymentDtoMapper.java b/api/src/main/java/uk/gov/hmcts/payment/api/dto/mapper/PaymentDtoMapper.java index f0bb563a51..909a2c59ea 100644 --- a/api/src/main/java/uk/gov/hmcts/payment/api/dto/mapper/PaymentDtoMapper.java +++ b/api/src/main/java/uk/gov/hmcts/payment/api/dto/mapper/PaymentDtoMapper.java @@ -344,7 +344,7 @@ public PaymentDto toReconciliationResponseDtoForLibereta(final Payment payment, LOG.info("apportionCheck value in PaymentDtoMapper: {}",apportionCheck); PaymentDto paymentDto = PaymentDto.payment2DtoWith() .paymentReference(payment.getReference()) - .paymentGroupReference(apportionCheck ? null : paymentReference) + .paymentGroupReference(paymentReference) .serviceName(payment.getServiceType()) .siteId(payment.getSiteId()) .amount(payment.getAmount()) diff --git a/api/src/main/java/uk/gov/hmcts/payment/api/service/IacServiceImpl.java b/api/src/main/java/uk/gov/hmcts/payment/api/service/IacServiceImpl.java index 50d8b4bca4..80c5fa7377 100644 --- a/api/src/main/java/uk/gov/hmcts/payment/api/service/IacServiceImpl.java +++ b/api/src/main/java/uk/gov/hmcts/payment/api/service/IacServiceImpl.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Service @@ -96,13 +97,17 @@ public ResponseEntity getIacSupplementaryInfo(List paymentDtos, String serviceName) { List iacPayments = getIacPayments(serviceName, paymentDtos); + iacPayments.forEach(paymentDto -> - paymentFeeLinkRepository.findByCcdCaseNumber(paymentDto.getCcdCaseNumber()).ifPresent(paymentFeeLinks -> - paymentFeeLinks.stream().filter(paymentLink -> paymentDto.getCaseReference() == null && paymentLink.getCaseReference() != null).findFirst().ifPresent(paymentLink -> { - paymentDto.setCaseReference(paymentLink.getCaseReference()); - LOG.info("Setting caseReference {} from paymentFeeLink for CCD Case {}", paymentLink.getCaseReference(), paymentDto.getCcdCaseNumber()); - }) - ) + paymentFeeLinkRepository.findByPaymentReference(paymentDto.getPaymentGroupReference()).ifPresent(paymentFeeLink -> { + if (paymentDto.getCaseReference() == null && paymentFeeLink.getCaseReference() != null && paymentFeeLink.getCaseReference().length() > 0) { + paymentDto.setCaseReference(paymentFeeLink.getCaseReference()); + LOG.info("Setting caseReference {} for Service Request {} in Case {}", + paymentFeeLink.getCaseReference(), + paymentDto.getPaymentGroupReference(), + paymentDto.getCcdCaseNumber()); + } + }) ); } diff --git a/api/src/test/java/uk/gov/hmcts/payment/api/service/IacServiceTest.java b/api/src/test/java/uk/gov/hmcts/payment/api/service/IacServiceTest.java index 4d98fc879f..8b38b423d8 100644 --- a/api/src/test/java/uk/gov/hmcts/payment/api/service/IacServiceTest.java +++ b/api/src/test/java/uk/gov/hmcts/payment/api/service/IacServiceTest.java @@ -46,6 +46,7 @@ public class IacServiceTest { @Before public void setUp() { paymentDto = PaymentDto.payment2DtoWith() + .paymentGroupReference("2024-1706099566733") .paymentReference("RC-2222-3333-4444-5555") .ccdCaseNumber("1111-2222-3333-4444") .caseReference(null) @@ -80,10 +81,10 @@ public void getIacSupplementaryInfoHttpClientErrorException() { } @Test - public void updateCaseReferenceInPaymentDtosSuccess() { + public void updateCaseReferenceInPaymentDtoFeeLinksSuccess() { List paymentDtos = Collections.singletonList(paymentDto); - PaymentFeeLink paymentFeeLink = PaymentFeeLink.paymentFeeLinkWith().ccdCaseNumber("1111-2222-3333-4444").caseReference("IAC/1234/REF").build(); - when(paymentFeeLinkRepository.findByCcdCaseNumber("1111-2222-3333-4444")).thenReturn(Optional.of(Collections.singletonList(paymentFeeLink))); + PaymentFeeLink paymentFeeLink = PaymentFeeLink.paymentFeeLinkWith().paymentReference("2024-1706099566733").caseReference("IAC/1234/REF").build(); + when(paymentFeeLinkRepository.findByPaymentReference("2024-1706099566733")).thenReturn(Optional.of(paymentFeeLink)); iacService.updateCaseReferenceInPaymentDtos(paymentDtos, IAC_SERVICE_CODE); @@ -91,30 +92,27 @@ public void updateCaseReferenceInPaymentDtosSuccess() { } @Test - public void updateCaseReferenceInPaymentDtosMultipleFeeLinksSuccess() { + public void updateCaseReferenceInPaymentDtosIgnoredAsAlreadyPopulated() { + paymentDto.setCaseReference("IAC/1234/REF"); List paymentDtos = Collections.singletonList(paymentDto); - PaymentFeeLink paymentFeeLink1 = PaymentFeeLink.paymentFeeLinkWith().ccdCaseNumber("1111-2222-3333-4444").build(); - PaymentFeeLink paymentFeeLink2 = PaymentFeeLink.paymentFeeLinkWith().ccdCaseNumber("1111-2222-3333-4444").build(); - PaymentFeeLink paymentFeeLink3 = PaymentFeeLink.paymentFeeLinkWith().ccdCaseNumber("1111-2222-3333-4444").caseReference("IAC/1234/REF").build(); - PaymentFeeLink paymentFeeLink4 = PaymentFeeLink.paymentFeeLinkWith().ccdCaseNumber("1111-2222-3333-4444").build(); - List paymentFeeLinks = List.of(paymentFeeLink1, paymentFeeLink2, paymentFeeLink3, paymentFeeLink4); - when(paymentFeeLinkRepository.findByCcdCaseNumber("1111-2222-3333-4444")).thenReturn(Optional.of(paymentFeeLinks)); + PaymentFeeLink paymentFeeLink = PaymentFeeLink.paymentFeeLinkWith().caseReference("IAC/6789/REF").build(); + when(paymentFeeLinkRepository.findByPaymentReference(anyString())).thenReturn(Optional.of(paymentFeeLink)); iacService.updateCaseReferenceInPaymentDtos(paymentDtos, IAC_SERVICE_CODE); assertEquals("IAC/1234/REF", paymentDto.getCaseReference()); } + @Test - public void updateCaseReferenceInPaymentDtosIgnoredAsAlreadyPopulated() { - paymentDto.setCaseReference("IAC/1234/REF"); + public void updateCaseReferenceInPaymentDtosEmptyCaseReference() { List paymentDtos = Collections.singletonList(paymentDto); - PaymentFeeLink paymentFeeLink = PaymentFeeLink.paymentFeeLinkWith().caseReference("IAC/6789/REF").build(); - when(paymentFeeLinkRepository.findByCcdCaseNumber(anyString())).thenReturn(Optional.of(Collections.singletonList(paymentFeeLink))); + PaymentFeeLink paymentFeeLink = PaymentFeeLink.paymentFeeLinkWith().paymentReference("2024-1706099566733").caseReference("").build(); + when(paymentFeeLinkRepository.findByPaymentReference("2024-1706099566733")).thenReturn(Optional.of(paymentFeeLink)); iacService.updateCaseReferenceInPaymentDtos(paymentDtos, IAC_SERVICE_CODE); - assertEquals("IAC/1234/REF", paymentDto.getCaseReference()); + assertEquals(null, paymentDto.getCaseReference()); } @Test