Skip to content

Commit

Permalink
PAY-7310: Update to identify Case Reference by Payment Group (#1684)
Browse files Browse the repository at this point in the history
* PAY-7310: Update to identify Case Reference by Payment Group

* PAY-7310: Update to identify Case Reference by Payment Group
  • Loading branch information
davejones74 authored Sep 16, 2024
1 parent 12ba331 commit 4888671
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -96,13 +97,17 @@ public ResponseEntity<SupplementaryPaymentDto> getIacSupplementaryInfo(List<Paym
@Override
public void updateCaseReferenceInPaymentDtos(List<PaymentDto> paymentDtos, String serviceName) {
List<PaymentDto> 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());
}
})
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -80,41 +81,38 @@ public void getIacSupplementaryInfoHttpClientErrorException() {
}

@Test
public void updateCaseReferenceInPaymentDtosSuccess() {
public void updateCaseReferenceInPaymentDtoFeeLinksSuccess() {
List<PaymentDto> 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);

assertEquals("IAC/1234/REF", paymentDto.getCaseReference());
}

@Test
public void updateCaseReferenceInPaymentDtosMultipleFeeLinksSuccess() {
public void updateCaseReferenceInPaymentDtosIgnoredAsAlreadyPopulated() {
paymentDto.setCaseReference("IAC/1234/REF");
List<PaymentDto> 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<PaymentFeeLink> 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<PaymentDto> 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
Expand Down

0 comments on commit 4888671

Please sign in to comment.