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

[PAGOPA-1359] fix: Update partially PAID case #77

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,25 @@ function buildCreateDebtPositionRequest(debtPosition, payer) {
dueDate: debtPosition.dueDate,
retentionDate: debtPosition.retentionDate,
fee: 0,
paymentOptionMetadata: [
{
"key": "po-metadata-key",
"value": "po-metadata-value"
}
],
transfer: [
{
idTransfer: debtPosition.transferId1,
amount: (debtPosition.amount * 100 / 3),
remittanceInformation: "Rata 1",
category: "9/0101108TS/",
iban: debtPosition.iban,
transferMetadata: [
{
"key": "key",
"value": "string"
}
]
},
{
idTransfer: debtPosition.transferId2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ public PaVerifyPaymentNoticeRes paVerifyPaymentNotice(PaVerifyPaymentNoticeReq r
request.getQrCode().getNoticeNumber());
try {
result = this.generatePaVerifyPaymentNoticeResponse(paymentOption);
}
catch (Exception e){
} catch (Exception e) {
log.error("[paVerifyPaymentNotice] paymentOption {}", paymentOption, e);
throw e;
}
Expand Down Expand Up @@ -330,7 +329,8 @@ private PaDemandPaymentNoticeResponse createPaDemandPaymentNoticeResponse(
*/
private void checkDebtPositionStatus(PaymentsModelResponse paymentOption) {
String iuvLog = " [iuv=" + paymentOption.getIuv() + "]";
if (paymentOption.getDebtPositionStatus().equals(DebtPositionStatus.EXPIRED)) {
if (paymentOption.getDebtPositionStatus().equals(DebtPositionStatus.EXPIRED)
|| paymentOption.getDueDate().isBefore(LocalDateTime.now())) {
log.error(DEBT_POSITION_STATUS_ERROR + paymentOption.getDebtPositionStatus() + iuvLog);
throw new PartnerValidationException(PaaErrorEnum.PAA_PAGAMENTO_SCADUTO);
} else if (paymentOption.getDebtPositionStatus().equals(DebtPositionStatus.INVALID)) {
Expand All @@ -340,8 +340,8 @@ private void checkDebtPositionStatus(PaymentsModelResponse paymentOption) {
|| paymentOption.getDebtPositionStatus().equals(DebtPositionStatus.PUBLISHED)) {
log.error(DEBT_POSITION_STATUS_ERROR + paymentOption.getDebtPositionStatus() + iuvLog);
throw new PartnerValidationException(PaaErrorEnum.PAA_PAGAMENTO_SCONOSCIUTO);
} else if (paymentOption.getDebtPositionStatus().equals(DebtPositionStatus.PARTIALLY_PAID)
|| paymentOption.getDebtPositionStatus().equals(DebtPositionStatus.PAID)
} else if (paymentOption.getDebtPositionStatus().equals(DebtPositionStatus.PAID)
|| paymentOption.getStatus().equals(PaymentOptionStatus.PO_PAID)
|| paymentOption.getDebtPositionStatus().equals(DebtPositionStatus.REPORTED)) {
log.error(DEBT_POSITION_STATUS_ERROR + paymentOption.getDebtPositionStatus() + iuvLog);
throw new PartnerValidationException(PaaErrorEnum.PAA_PAGAMENTO_DUPLICATO);
Expand Down Expand Up @@ -569,23 +569,20 @@ private CtTransferPAV2 getTransferResponseV2(
return transferPA;
}

private CtMapEntry getPaymentOptionMetadata(
PaymentOptionMetadataModel metadataModel) {
private CtMapEntry getPaymentOptionMetadata(PaymentOptionMetadataModel metadataModel) {
CtMapEntry ctMapEntry = new CtMapEntry();
ctMapEntry.setKey(metadataModel.getKey());
ctMapEntry.setValue(metadataModel.getValue());
return ctMapEntry;
}

private CtMapEntry getTransferMetadata(
TransferMetadataModel metadataModel) {
private CtMapEntry getTransferMetadata(TransferMetadataModel metadataModel) {
CtMapEntry ctMapEntry = new CtMapEntry();
ctMapEntry.setKey(metadataModel.getKey());
ctMapEntry.setValue(metadataModel.getValue());
return ctMapEntry;
}


/**
* The method return iban given transferType and transfer, according to
* https://pagopa.atlassian.net/wiki/spaces/PAG/pages/96403906/paGetPayment#trasferType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void paVerifyPaymentNoticeTest() throws DatatypeConfigurationException, IOExcept
.thenReturn(factoryUtil.createCtPaymentOptionsDescriptionListPA());

PaymentsModelResponse paymentModel =
MockUtil.readModelFromFile("gpd/getPaymentOption.json", PaymentsModelResponse.class);
MockUtil.readModelFromFile("gpd/getPaymentOption_PO_UNPAID.json", PaymentsModelResponse.class);
when(gpdClient.getPaymentOption(anyString(), anyString())).thenReturn(paymentModel);

// Test execution
Expand Down Expand Up @@ -298,7 +298,7 @@ void paGetPaymentTest()

when(gpdClient.getPaymentOption(anyString(), anyString()))
.thenReturn(
MockUtil.readModelFromFile("gpd/getPaymentOption.json", PaymentsModelResponse.class));
MockUtil.readModelFromFile("gpd/getPaymentOption_PO_UNPAID.json", PaymentsModelResponse.class));

// Test execution
PaGetPaymentRes responseBody = partnerService.paGetPayment(requestBody);
Expand All @@ -313,7 +313,7 @@ void paGetPaymentTest()
.isEqualTo(
DatatypeFactory.newInstance().newXMLGregorianCalendar("2022-02-25T17:03:59.408"));
assertEquals("77777777777", requestBody.getQrCode().getFiscalCode());
assertEquals(3, responseBody.getData().getTransferList().getTransfer().size());
assertEquals(2, responseBody.getData().getTransferList().getTransfer().size());

// in paGetPayment v1 the 'richiestaMarcaDaBollo' does not exist
org.hamcrest.MatcherAssert.assertThat(
Expand All @@ -324,10 +324,7 @@ void paGetPaymentTest()
"IBAN", org.hamcrest.Matchers.is("string"))),
org.hamcrest.Matchers.allOf(
org.hamcrest.Matchers.<CtTransferPA>hasProperty(
"IBAN", org.hamcrest.Matchers.is("ABC"))),
org.hamcrest.Matchers.allOf(
org.hamcrest.Matchers.<CtTransferPA>hasProperty(
"IBAN", org.hamcrest.Matchers.nullValue()))));
"IBAN", org.hamcrest.Matchers.is("ABC")))));
}

@Test
Expand Down Expand Up @@ -359,10 +356,10 @@ void paGetPaymentIncompleteAddressTest()
.isEqualTo("Canone Unico Patrimoniale - CORPORATE");
assertThat(responseBody.getData().getDueDate())
.isEqualTo(
DatatypeFactory.newInstance().newXMLGregorianCalendar("2022-04-20T12:15:38.927"));
DatatypeFactory.newInstance().newXMLGregorianCalendar("2125-04-20T12:15:38.927"));
assertThat(responseBody.getData().getRetentionDate())
.isEqualTo(
DatatypeFactory.newInstance().newXMLGregorianCalendar("2022-06-19T12:15:38.927"));
DatatypeFactory.newInstance().newXMLGregorianCalendar("2125-06-19T12:15:38.927"));
assertEquals("77777777777", requestBody.getQrCode().getFiscalCode());

assertEquals("city", responseBody.getData().getDebtor().getCity());
Expand Down Expand Up @@ -801,7 +798,7 @@ void paGetPaymentV2Test()

when(gpdClient.getPaymentOption(anyString(), anyString()))
.thenReturn(
MockUtil.readModelFromFile("gpd/getPaymentOption.json", PaymentsModelResponse.class));
MockUtil.readModelFromFile("gpd/getPaymentOption_PO_UNPAID.json", PaymentsModelResponse.class));

// Test execution
PaGetPaymentV2Response responseBody = pService.paGetPaymentV2(requestBody);
Expand All @@ -816,7 +813,7 @@ void paGetPaymentV2Test()
.isEqualTo(
DatatypeFactory.newInstance().newXMLGregorianCalendar("2022-02-25T17:03:59.408"));
assertEquals("77777777777", requestBody.getQrCode().getFiscalCode());
assertEquals(3, responseBody.getData().getTransferList().getTransfer().size());
assertEquals(2, responseBody.getData().getTransferList().getTransfer().size());

// in paGetPayment v2 there is the new 'richiestaMarcaDaBollo' field and it can be valued
org.hamcrest.MatcherAssert.assertThat(
Expand All @@ -831,12 +828,7 @@ void paGetPaymentV2Test()
org.hamcrest.Matchers.<CtTransferPAV2>hasProperty(
"richiestaMarcaDaBollo", org.hamcrest.Matchers.nullValue()),
org.hamcrest.Matchers.<CtTransferPAV2>hasProperty(
"IBAN", org.hamcrest.Matchers.is("ABC"))),
org.hamcrest.Matchers.allOf(
org.hamcrest.Matchers.<CtTransferPAV2>hasProperty(
"richiestaMarcaDaBollo", org.hamcrest.Matchers.notNullValue()),
org.hamcrest.Matchers.<CtTransferPAV2>hasProperty(
"IBAN", org.hamcrest.Matchers.nullValue()))));
"IBAN", org.hamcrest.Matchers.is("ABC")))));
}

@Test
Expand Down Expand Up @@ -879,10 +871,10 @@ void paGetPaymentIncompleteAddressV2Test()
.isEqualTo("Canone Unico Patrimoniale - CORPORATE");
assertThat(responseBody.getData().getDueDate())
.isEqualTo(
DatatypeFactory.newInstance().newXMLGregorianCalendar("2022-04-20T12:15:38.927"));
DatatypeFactory.newInstance().newXMLGregorianCalendar("2125-04-20T12:15:38.927"));
assertThat(responseBody.getData().getRetentionDate())
.isEqualTo(
DatatypeFactory.newInstance().newXMLGregorianCalendar("2022-06-19T12:15:38.927"));
DatatypeFactory.newInstance().newXMLGregorianCalendar("2125-06-19T12:15:38.927"));
assertEquals("77777777777", requestBody.getQrCode().getFiscalCode());

assertEquals("city", responseBody.getData().getDebtor().getCity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"amount": 10000,
"description": "Canone Unico Patrimoniale - CORPORATE",
"isPartialPayment": false,
"dueDate": "2022-04-20T12:15:38.927",
"retentionDate": "2022-06-19T12:15:38.927",
"paymentDate": "2021-10-01T17:48:22",
"dueDate": "2125-04-20T12:15:38.927",
"retentionDate": "2125-06-19T12:15:38.927",
"paymentDate": null,
"reportingDate": null,
"insertedDate": null,
"paymentMethod": "creditCard",
"fee": 200,
"pspCompany": "PSP name",
"idReceipt": "725d128ec27911edafa10242ac120002",
"idFlowReporting": null,
"status": "PO_PAID",
"status": "PO_UNPAID",
"paymentOptionMetadata": [
{
"key": "string",
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/gpd/getPaymentOption_PO_UNPAID.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"isPartialPayment": true,
"dueDate": "2122-02-24T17:03:59.408Z",
"retentionDate": "2022-02-25T17:03:59.408Z",
"paymentDate": "2022-02-24T17:03:59.408Z",
"paymentDate": null,
"reportingDate": "2022-02-24T17:03:59.408Z",
"insertedDate": "2022-02-24T17:03:59.408Z",
"paymentMethod": "string",
Expand Down
Loading