Skip to content

Commit

Permalink
[PIDM-42] fix(payment-status): move existing partial payment validati…
Browse files Browse the repository at this point in the history
…on to get/activate phase; adapt existing unit test;
  • Loading branch information
dylantangredi-bvt committed Jan 31, 2025
1 parent 2ee80ab commit 7aac4b2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import it.gov.pagopa.debtposition.entity.PaymentOption;
import it.gov.pagopa.debtposition.entity.PaymentPosition;
import it.gov.pagopa.debtposition.exception.AppError;
import it.gov.pagopa.debtposition.exception.AppException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.EnumSet;
Expand Down Expand Up @@ -93,4 +95,22 @@ public static PaymentPosition expirationCheckAndUpdate(PaymentOption po) {
}
return pp;
}

/**
* Checks if the user is trying to pay the full amount for the payment position but
* there is an installment already paid, in which case
*
* @param paymentOptionToPay the payment option being paid
* @param nav the identifier of the notice being paid
*/
public static void checkAlreadyPaidInstallments(PaymentOption paymentOptionToPay, String nav) {

PaymentPosition paymentPosition = paymentOptionToPay.getPaymentPosition();
if (Boolean.FALSE.equals(paymentOptionToPay.getIsPartialPayment())
&& paymentPosition.getStatus().equals(DebtPositionStatus.PARTIALLY_PAID)) {

throw new AppException(
AppError.PAYMENT_OPTION_ALREADY_PAID, paymentOptionToPay.getOrganizationFiscalCode(), nav);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public PaymentOption getPaymentOptionByNAV(@NotBlank String organizationFiscalCo
// PaymentPosition used when converting PaymentOption to POWithDebtor
DebtPositionStatus.validityCheckAndUpdate(paymentOption);
DebtPositionStatus.expirationCheckAndUpdate(paymentOption);
DebtPositionStatus.checkAlreadyPaidInstallments(paymentOption, nav);

return paymentOption;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ private static void checkPaymentOptionPayable(PaymentPosition ppToPay, String na
// La posizione debitoria è già in PARTIALLY_PAID ed arriva una richiesta di pagamento su una payment option non rateizzata (isPartialPayment = false) => errore
// PIDM-42: if this is a full payment and the position is partially paid then
// log this but allow the payment option status to be changed to PO_PAID instead of throwing an error
// NOTE: the exception handling has been moved to the get/activate validation (checkAlreadyPaidInstallments)
if (ppToPay.getStatus().equals(DebtPositionStatus.PARTIALLY_PAID)
&& Boolean.FALSE.equals(poToPay.getIsPartialPayment())) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ void payPaymentOption_Multiple_Partial_409() throws Exception {
}

@Test
void payPaymentOption_Multiple_Partial2_409() throws Exception {
void getPaymentOption_Multiple_Partial_409() throws Exception {
// creo una posizione debitoria (senza 'validity date' impostata e nav non valorizzato) con più
// opzioni di pagamento
mvc.perform(
Expand Down Expand Up @@ -652,13 +652,12 @@ void payPaymentOption_Multiple_Partial2_409() throws Exception {
MockMvcResultMatchers.jsonPath("$.status")
.value(DebtPositionStatus.PARTIALLY_PAID.toString()));

// effettuo un nuovo pagamento sulla payment option non rateizzabile (isPartialPayment = false)
// e ottengo errore
// effettuo una GET/ACTIVATE sulla payment option corrispondente alla rata unica/intero importo
// e ottengo errore 409
mvc.perform(
post("/organizations/PAY_Multiple_Partial2_409_12345678901/paymentoptions/"
+ auxDigit
+ "123456IUVMULTIPLEMOCK3/pay")
.content(TestUtil.toJson(DebtPositionMock.getPayPOMock1()))
get("/organizations/PAY_Multiple_Partial2_409_12345678901/paymentoptions/"
+ auxDigit
+ "123456IUVMULTIPLEMOCK3")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isConflict());
}
Expand Down

0 comments on commit 7aac4b2

Please sign in to comment.