diff --git a/openapi/openapi.json b/openapi/openapi.json index c2a98e2..a474582 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -1,497 +1,415 @@ { - "openapi": "3.0.3", - "info": { - "title": "gpd-payments-pull", - "description": "GPD Payments Pull Services", - "termsOfService": "https://www.pagopa.gov.it/", - "version": "1.0.8" + "openapi" : "3.0.3", + "info" : { + "title" : "gpd-payments-pull", + "description" : "GPD Payments Pull Services", + "termsOfService" : "https://www.pagopa.gov.it/", + "version" : "1.0.8" }, - "servers": [ - { - "url": "${host}/gpd/payments/pull/api/v1" - } - ], - "tags": [ - { - "name": "Payment Notices", - "description": "Payment Notices Operations" - } - ], - "paths": { - "/info": { - "get": { - "tags": [ - "Generic" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AppInfo" + "servers" : [ { + "url" : "${host}/gpd/payments/pull/api/v1" + } ], + "tags" : [ { + "name" : "Payment Notices", + "description" : "Payment Notices Operations" + } ], + "paths" : { + "/info" : { + "get" : { + "tags" : [ "Generic" ], + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/AppInfo" } } } }, - "400": { - "description": "Bad Request", - "content": { - "application/json": {} + "400" : { + "description" : "Bad Request", + "content" : { + "application/json" : { } } } } } }, - "/payment-notices/v1": { - "get": { - "tags": [ - "Payment Notices" - ], - "summary": "Get Payment Notices", - "description": "Retrieve payment notices from ACA and GPD sources, filtered by a due date", - "parameters": [ - { - "name": "dueDate", - "in": "query", - "description": "Optional date to filter paymentNotices (if provided use the format yyyy-MM-dd)", - "schema": { - "$ref": "#/components/schemas/LocalDate" - } - }, - { - "name": "limit", - "in": "query", - "description": "Number of elements on one page. Default = 50", - "schema": { - "format": "int32", - "default": "50", - "maximum": 100, - "minimum": 1, - "type": "integer" - } - }, - { - "name": "page", - "in": "query", - "description": "Page number. Page value starts from 0", - "schema": { - "format": "int32", - "default": "0", - "minimum": 0, - "type": "integer" - } - }, - { - "name": "x-tax-code", - "in": "header", - "description": "Tax code to use for retrieving notices", - "required": true, - "schema": { - "type": "string" - } + "/payment-notices/v1" : { + "get" : { + "tags" : [ "Payment Notices" ], + "summary" : "Get Payment Notices", + "description" : "Retrieve payment notices from ACA and GPD sources, filtered by a due date", + "parameters" : [ { + "name" : "dueDate", + "in" : "query", + "description" : "Optional date to filter paymentNotices (if provided use the format yyyy-MM-dd)", + "schema" : { + "$ref" : "#/components/schemas/LocalDate" + } + }, { + "name" : "limit", + "in" : "query", + "description" : "Number of elements on one page. Default = 50", + "schema" : { + "format" : "int32", + "default" : "50", + "maximum" : 100, + "minimum" : 1, + "type" : "integer" + } + }, { + "name" : "page", + "in" : "query", + "description" : "Page number. Page value starts from 0", + "schema" : { + "format" : "int32", + "default" : "0", + "minimum" : 0, + "type" : "integer" } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/PaymentNotice" + }, { + "name" : "x-tax-code", + "in" : "header", + "description" : "Tax code to use for retrieving notices", + "required" : true, + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/PaymentNotice" } } } } }, - "500": { - "$ref": "#/components/responses/InternalServerError" + "500" : { + "$ref" : "#/components/responses/InternalServerError" }, - "400": { - "$ref": "#/components/responses/AppException400" + "400" : { + "$ref" : "#/components/responses/AppException400" } }, - "security": [ - { - "ApiKey": [] - } - ] + "security" : [ { + "ApiKey" : [ ] + } ] } } }, - "components": { - "schemas": { - "AppInfo": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "version": { - "type": "string" - }, - "environment": { - "type": "string" + "components" : { + "schemas" : { + "AppInfo" : { + "type" : "object", + "properties" : { + "name" : { + "type" : "string" + }, + "version" : { + "type" : "string" + }, + "environment" : { + "type" : "string" } } }, - "ErrorResponse": { - "type": "object", - "properties": { - "title": { - "type": "string", - "example": "Internal Server Error" - }, - "status": { - "format": "int32", - "type": "integer", - "example": 500 - }, - "detail": { - "type": "string", - "example": "An unexpected error has occurred. Please contact support." - }, - "instance": { - "type": "string", - "example": "PN-500" + "ErrorResponse" : { + "type" : "object", + "properties" : { + "title" : { + "type" : "string", + "example" : "Internal Server Error" + }, + "status" : { + "format" : "int32", + "type" : "integer", + "example" : 500 + }, + "detail" : { + "type" : "string", + "example" : "An unexpected error has occurred. Please contact support." + }, + "instance" : { + "type" : "string", + "example" : "PN-500" } } }, - "Installment": { - "required": [ - "nav", - "iuv", - "paTaxCode", - "paFullName", - "amount", - "description", - "dueDate", - "insertedDate", - "status", - "lastUpdatedDate" - ], - "type": "object", - "properties": { - "nav": { - "description": "Notice Code", - "type": "string" - }, - "iuv": { - "description": "Unique identifier", - "type": "string" - }, - "paTaxCode": { - "description": "Tax code of the Creditor Body", - "type": "string" - }, - "paFullName": { - "description": "Company name of the Creditor Body", - "type": "string" - }, - "amount": { - "format": "int64", - "description": "Payment Option Amount", - "type": "integer" - }, - "description": { - "description": "Description of the OP (e.g. \"SISA - 741T, 942T - Checks without authorization or funding\")", - "type": "string" - }, - "dueDate": { - "allOf": [ - { - "$ref": "#/components/schemas/LocalDateTime" - }, - { - "description": "Is the date by which (TO) the Payment option is payable." - } - ] - }, - "retentionDate": { - "allOf": [ - { - "$ref": "#/components/schemas/LocalDateTime" - }, - { - "description": "Not currently used in any logic. The purpose of this date will be to give the possibility to specify a time period after the dueDate within which a payment option, even if expired, will still be payable." - } - ] - }, - "insertedDate": { - "allOf": [ - { - "$ref": "#/components/schemas/LocalDateTime" - }, - { - "description": "date of insertion of the OP" - } - ] - }, - "notificationFee": { - "format": "int64", - "description": "corresponds to the SEND notification costs", - "type": "integer" - }, - "status": { - "allOf": [ - { - "$ref": "#/components/schemas/TransferStatus" - }, - { - "description": "Status of the OP" - } - ] - }, - "lastUpdatedDate": { - "allOf": [ - { - "$ref": "#/components/schemas/LocalDateTime" - }, - { - "description": "OP update date" - } - ] + "Installment" : { + "required" : [ "nav", "iuv", "paTaxCode", "paFullName", "amount", "description", "dueDate", "insertedDate", "status", "lastUpdatedDate" ], + "type" : "object", + "properties" : { + "nav" : { + "description" : "Notice Code", + "type" : "string" + }, + "iuv" : { + "description" : "Unique identifier", + "type" : "string" + }, + "paTaxCode" : { + "description" : "Tax code of the Creditor Body", + "type" : "string" + }, + "paFullName" : { + "description" : "Company name of the Creditor Body", + "type" : "string" + }, + "amount" : { + "format" : "int64", + "description" : "Payment Option Amount", + "type" : "integer" + }, + "description" : { + "description" : "Description of the OP (e.g. \"SISA - 741T, 942T - Checks without authorization or funding\")", + "type" : "string" + }, + "dueDate" : { + "allOf" : [ { + "$ref" : "#/components/schemas/LocalDateTime" + }, { + "description" : "Is the date by which (TO) the Payment option is payable." + } ] + }, + "retentionDate" : { + "allOf" : [ { + "$ref" : "#/components/schemas/LocalDateTime" + }, { + "description" : "Not currently used in any logic. The purpose of this date will be to give the possibility to specify a time period after the dueDate within which a payment option, even if expired, will still be payable." + } ] + }, + "insertedDate" : { + "allOf" : [ { + "$ref" : "#/components/schemas/LocalDateTime" + }, { + "description" : "date of insertion of the OP" + } ] + }, + "notificationFee" : { + "format" : "int64", + "description" : "corresponds to the SEND notification costs", + "type" : "integer" + }, + "status" : { + "allOf" : [ { + "$ref" : "#/components/schemas/PaymentOptionStatus" + }, { + "description" : "Status of the OP" + } ] + }, + "lastUpdatedDate" : { + "allOf" : [ { + "$ref" : "#/components/schemas/LocalDateTime" + }, { + "description" : "OP update date" + } ] } } }, - "LocalDate": { - "format": "date", - "type": "string", - "example": "2022-03-10" + "LocalDate" : { + "format" : "date", + "type" : "string", + "example" : "2022-03-10" }, - "LocalDateTime": { - "format": "date-time", - "type": "string", - "example": "2022-03-10T12:15:50" + "LocalDateTime" : { + "format" : "date-time", + "type" : "string", + "example" : "2022-03-10T12:15:50" }, - "PaymentNotice": { - "required": [ - "iupd", - "debtorTaxCode", - "debtorFullName", - "debtorType", - "paTaxCode", - "paFullName", - "insertedDate", - "publishDate", - "validityDate", - "status", - "lastUpdateDate", - "paymentOptions" - ], - "type": "object", - "properties": { - "iupd": { - "description": "Unique ID of the Debt Position (for positions originating from ACA the IUPD starts with ACA_)", - "type": "string" - }, - "debtorTaxCode": { - "description": "Tax code of the person to whom the Debt Position is registered", - "type": "string" - }, - "debtorFullName": { - "description": "Full name of the person to whom the Debt Position is registered", - "type": "string" - }, - "debtorType": { - "description": "Type of subject to whom the Debt Position is registered (Will be F (Physical) or G(Legal))", - "type": "string" - }, - "paTaxCode": { - "description": "Tax code of the Creditor Body", - "type": "string" - }, - "paFullName": { - "description": "Company name of the Creditor Body", - "type": "string" - }, - "insertedDate": { - "allOf": [ - { - "$ref": "#/components/schemas/LocalDateTime" - }, - { - "description": "Date of entry of the Debt Position" - } - ] - }, - "publishDate": { - "allOf": [ - { - "$ref": "#/components/schemas/LocalDateTime" - }, - { - "description": "Date of publication of the Debt Position. In the case of Positions created by ACA it corresponds to the insertion date." - } - ] - }, - "validityDate": { - "allOf": [ - { - "$ref": "#/components/schemas/LocalDateTime" - }, - { - "description": "Start date of validity of the Debt Position. if set to null it goes directly to valid when publishing" - } - ] - }, - "status": { - "allOf": [ - { - "$ref": "#/components/schemas/PaymentNoticeStatus" - }, - { - "description": "State of the Debt Position. Will be\nVALID\n or\nPARTIALLY_PAID" - } - ] - }, - "lastUpdateDate": { - "allOf": [ - { - "$ref": "#/components/schemas/LocalDate" - }, - { - "description": "Date of update of the Debt Position" - } - ] - }, - "paymentOptions": { - "description": "Array structure containing any payment options (there always exists at least 1)", - "type": "array", - "items": { - "$ref": "#/components/schemas/PaymentOption" + "PaymentNotice" : { + "required" : [ "iupd", "debtorTaxCode", "debtorFullName", "debtorType", "paTaxCode", "paFullName", "insertedDate", "publishDate", "validityDate", "status", "lastUpdateDate", "paymentOptions" ], + "type" : "object", + "properties" : { + "iupd" : { + "description" : "Unique ID of the Debt Position (for positions originating from ACA the IUPD starts with ACA_)", + "type" : "string" + }, + "debtorTaxCode" : { + "description" : "Tax code of the person to whom the Debt Position is registered", + "type" : "string" + }, + "debtorFullName" : { + "description" : "Full name of the person to whom the Debt Position is registered", + "type" : "string" + }, + "debtorType" : { + "description" : "Type of subject to whom the Debt Position is registered (Will be F (Physical) or G(Legal))", + "type" : "string" + }, + "paTaxCode" : { + "description" : "Tax code of the Creditor Body", + "type" : "string" + }, + "paFullName" : { + "description" : "Company name of the Creditor Body", + "type" : "string" + }, + "insertedDate" : { + "allOf" : [ { + "$ref" : "#/components/schemas/LocalDateTime" + }, { + "description" : "Date of entry of the Debt Position" + } ] + }, + "publishDate" : { + "allOf" : [ { + "$ref" : "#/components/schemas/LocalDateTime" + }, { + "description" : "Date of publication of the Debt Position. In the case of Positions created by ACA it corresponds to the insertion date." + } ] + }, + "validityDate" : { + "allOf" : [ { + "$ref" : "#/components/schemas/LocalDateTime" + }, { + "description" : "Start date of validity of the Debt Position. if set to null it goes directly to valid when publishing" + } ] + }, + "status" : { + "allOf" : [ { + "$ref" : "#/components/schemas/PaymentNoticeStatus" + }, { + "description" : "State of the Debt Position. Will be\nVALID\n or\nPARTIALLY_PAID" + } ] + }, + "lastUpdateDate" : { + "allOf" : [ { + "$ref" : "#/components/schemas/LocalDate" + }, { + "description" : "Date of update of the Debt Position" + } ] + }, + "paymentOptions" : { + "description" : "Array structure containing any payment options (there always exists at least 1)", + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/PaymentOption" } } } }, - "PaymentNoticeStatus": { - "enum": [ - "VALID", - "PARTIALLY_PAID" - ], - "type": "string" + "PaymentNoticeStatus" : { + "enum" : [ "VALID", "PARTIALLY_PAID" ], + "type" : "string" }, - "PaymentOption": { - "required": [ - "numberOfInstallments", - "switchToExpired", - "installments" - ], - "type": "object", - "properties": { - "description": { - "description": "Description of the payment option", - "type": "string" - }, - "numberOfInstallments": { - "format": "int32", - "description": "Number of installments that make up the payment option, if equal to 1 it is a single payment", - "type": "integer" - }, - "amount": { - "format": "int64", - "description": "total amount for the payment option", - "type": "integer" - }, - "dueDate": { - "allOf": [ - { - "$ref": "#/components/schemas/LocalDateTime" - }, - { - "description": "Is the date by which the Payment option is payable." - } - ] - }, - "isPartialPayment": { - "description": "Indicates whether the OP is part of an installment plan", - "type": "boolean" - }, - "switchToExpired": { - "description": "Indicates, if set to true, in the case of PD created on GPD, that once the expiration date (dueDate ) has passed the PD is automatically set to the expired status", - "type": "boolean" - }, - "installments": { - "description": "Array structure containing the installments that make up the payment option (there always exists at least 1)", - "type": "array", - "items": { - "$ref": "#/components/schemas/Installment" + "PaymentOption" : { + "required" : [ "numberOfInstallments", "switchToExpired", "installments" ], + "type" : "object", + "properties" : { + "description" : { + "description" : "Description of the payment option", + "type" : "string" + }, + "numberOfInstallments" : { + "format" : "int32", + "description" : "Number of installments that make up the payment option, if equal to 1 it is a single payment", + "type" : "integer" + }, + "amount" : { + "format" : "int64", + "description" : "total amount for the payment option", + "type" : "integer" + }, + "dueDate" : { + "allOf" : [ { + "$ref" : "#/components/schemas/LocalDateTime" + }, { + "description" : "Is the date by which the Payment option is payable." + } ] + }, + "isPartialPayment" : { + "description" : "Indicates whether the OP is part of an installment plan", + "type" : "boolean" + }, + "switchToExpired" : { + "description" : "Indicates, if set to true, in the case of PD created on GPD, that once the expiration date (dueDate ) has passed the PD is automatically set to the expired status", + "type" : "boolean" + }, + "installments" : { + "description" : "Array structure containing the installments that make up the payment option (there always exists at least 1)", + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Installment" } } } }, - "TransferStatus": { - "enum": [ - "T_UNREPORTED", - "T_REPORTED" - ], - "type": "string" + "PaymentOptionStatus" : { + "enum" : [ "PO_UNPAID", "PO_PAID", "PO_PARTIALLY_REPORTED", "PO_REPORTED" ], + "type" : "string" } }, - "responses": { - "AppException400": { - "description": "Default app exception for status 400", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ErrorResponse" + "responses" : { + "AppException400" : { + "description" : "Default app exception for status 400", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ErrorResponse" }, - "examples": { - "Error": { - "value": { - "type": "", - "title": "Bad Request", - "status": 400, - "detail": "The provided due date [] is invalid", - "instance": "PPL_703" + "examples" : { + "Error" : { + "value" : { + "type" : "", + "title" : "Bad Request", + "status" : 400, + "detail" : "The provided due date [] is invalid", + "instance" : "PPL_703" } } } } } }, - "AppException404": { - "description": "Default app exception for status 404", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ErrorResponse" + "AppException404" : { + "description" : "Default app exception for status 404", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ErrorResponse" }, - "example": { - "type": "", - "title": "Not Found", - "status": 404, - "detail": "Payment Notice [] not found", - "instance": "PPL_900" + "example" : { + "type" : "", + "title" : "Not Found", + "status" : 404, + "detail" : "Payment Notice [] not found", + "instance" : "PPL_900" } } } }, - "InternalServerError": { - "description": "Internal Server Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ErrorResponse" + "InternalServerError" : { + "description" : "Internal Server Error", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ErrorResponse" }, - "example": { - "type": "", - "title": "Internal Server Error", - "status": 500, - "detail": "An unexpected error has occurred. Please contact support.", - "instance": "PPL_603" + "example" : { + "type" : "", + "title" : "Internal Server Error", + "status" : 500, + "detail" : "An unexpected error has occurred. Please contact support.", + "instance" : "PPL_603" } } } } }, - "securitySchemes": { - "ApiKey": { - "type": "apiKey", - "name": "Ocp-Apim-Subscription-Key" + "securitySchemes" : { + "ApiKey" : { + "type" : "apiKey", + "name" : "Ocp-Apim-Subscription-Key" } } } -} +} \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/gpd/payments/pull/entity/PaymentOption.java b/src/main/java/it/gov/pagopa/gpd/payments/pull/entity/PaymentOption.java index f52bc74..921c088 100644 --- a/src/main/java/it/gov/pagopa/gpd/payments/pull/entity/PaymentOption.java +++ b/src/main/java/it/gov/pagopa/gpd/payments/pull/entity/PaymentOption.java @@ -114,7 +114,7 @@ public class PaymentOption implements Serializable { @Builder.Default @OneToMany( targetEntity = Transfer.class, - fetch = FetchType.EAGER, + fetch = FetchType.LAZY, mappedBy = "paymentOption", cascade = CascadeType.ALL, orphanRemoval = true) diff --git a/src/main/java/it/gov/pagopa/gpd/payments/pull/mapper/PaymentNoticeMapper.java b/src/main/java/it/gov/pagopa/gpd/payments/pull/mapper/PaymentNoticeMapper.java index 00935bd..e9e4514 100644 --- a/src/main/java/it/gov/pagopa/gpd/payments/pull/mapper/PaymentNoticeMapper.java +++ b/src/main/java/it/gov/pagopa/gpd/payments/pull/mapper/PaymentNoticeMapper.java @@ -7,6 +7,11 @@ import it.gov.pagopa.gpd.payments.pull.models.PaymentOption; import it.gov.pagopa.gpd.payments.pull.models.enums.PaymentNoticeStatus; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + /** * Payment Notice mapping methods */ @@ -19,7 +24,7 @@ public class PaymentNoticeMapper { * @return mapped PaymentNotice instance */ public static PaymentNotice manNotice(PaymentPosition paymentPosition) { - return PaymentNotice + PaymentNotice paymentNotice = PaymentNotice .builder() .iupd(paymentPosition.getIupd()) .debtorFullName(paymentPosition.getFullName()) @@ -32,55 +37,63 @@ public static PaymentNotice manNotice(PaymentPosition paymentPosition) { .paFullName(paymentPosition.getCompanyName()) .publishDate(paymentPosition.getPublishDate()) .debtorType(paymentPosition.getType().toString()) - .paymentOptions(paymentPosition.getPaymentOption().stream() - .map(item -> { - PaymentOption paymentOption = mapOption(item); - paymentOption.setSwitchToExpired(paymentOption.getSwitchToExpired()); - return paymentOption; - }).toList()) .build(); + List paymentOptions = new java.util.ArrayList<>(paymentPosition.getPaymentOption().stream() + .filter(item -> !item.getIsPartialPayment()).map( + item -> mapOptions(paymentPosition, Collections.singletonList(item))).toList()); + if (paymentOptions.size() != paymentPosition.getPaymentOption().size()) { + paymentOptions.add(mapOptions(paymentPosition, paymentPosition.getPaymentOption().stream() + .filter(it.gov.pagopa.gpd.payments.pull.entity.PaymentOption::getIsPartialPayment).toList())); + } + paymentNotice.setPaymentOptions(paymentOptions); + return paymentNotice; } /** * Maps a PaymentOption model, starting from PaymentOption entity and related entities * - * @param paymentOption instance of PaymentOption entity to use as mapping source + * @param paymentPosition instance of PaymentOption entity to use as mapping source * @return Mapped PaymentOption model instance */ - public static PaymentOption mapOption(it.gov.pagopa.gpd.payments.pull.entity.PaymentOption paymentOption) { + public static PaymentOption mapOptions( + PaymentPosition paymentPosition, + List paymentOptions) { return PaymentOption .builder() - .description(paymentOption.getDescription()) - .amount(paymentOption.getAmount()) - .dueDate(paymentOption.getDueDate()) - .numberOfInstallments(paymentOption.getTransfer().size()) - .isPartialPayment(paymentOption.getIsPartialPayment()) - .switchToExpired(paymentOption.getPaymentPosition().getSwitchToExpired()) - .installments(paymentOption.getTransfer().stream().map(item -> - mapInstallment(item)).toList()) + .description(paymentOptions.get(0).getDescription()) + .amount(paymentOptions.stream().map( + it.gov.pagopa.gpd.payments.pull.entity.PaymentOption::getAmount).reduce(0L, Long::sum)) + .dueDate(paymentOptions.stream().map(it.gov.pagopa.gpd.payments.pull.entity.PaymentOption::getDueDate) + .max(LocalDateTime::compareTo).get()) + .numberOfInstallments(paymentOptions.size()) + .isPartialPayment(paymentOptions.get(0).getIsPartialPayment()) + .switchToExpired(paymentPosition.getSwitchToExpired()) + .installments(paymentOptions.stream().map(item -> + mapInstallment(item, paymentPosition)).toList()) .build(); } /** - * Maps an Installment instance using Transfer data, and related entities + * Maps an Installment instance using PaymentOption data, and related entities * - * @param transfer instance of Transfer entity + * @param paymentOption instance of PaymentOption entity * @return mapped Installment instance */ - public static Installment mapInstallment(Transfer transfer) { + public static Installment mapInstallment( + it.gov.pagopa.gpd.payments.pull.entity.PaymentOption paymentOption, PaymentPosition paymentPosition) { return Installment.builder() - .nav(transfer.getPaymentOption().getNav()) - .iuv(transfer.getIuv()) - .paTaxCode(transfer.getOrganizationFiscalCode()) - .paFullName(transfer.getPaymentOption().getPaymentPosition().getCompanyName()) //TODO: Missing name from option/transfer list - .amount(transfer.getAmount()) - .description(transfer.getPaymentOption().getDescription()) //TODO: To define if remittance information to use - .dueDate(transfer.getPaymentOption().getDueDate()) - .retentionDate(transfer.getPaymentOption().getRetentionDate()) - .insertedDate(transfer.getInsertedDate()) - .notificationFee(transfer.getPaymentOption().getNotificationFee()) - .status(transfer.getStatus()) - .lastUpdatedDate(transfer.getLastUpdatedDate()) + .nav(paymentOption.getNav()) + .iuv(paymentOption.getIuv()) + .paTaxCode(paymentOption.getOrganizationFiscalCode()) + .paFullName(paymentPosition.getCompanyName()) //TODO: Missing name from option/transfer list + .amount(paymentOption.getAmount()) + .description(paymentOption.getDescription()) //TODO: To define if remittance information to use + .dueDate(paymentOption.getDueDate()) + .retentionDate(paymentOption.getRetentionDate()) + .insertedDate(paymentOption.getInsertedDate()) + .notificationFee(paymentOption.getNotificationFee()) + .status(paymentOption.getStatus()) + .lastUpdatedDate(paymentOption.getLastUpdatedDate()) .build(); } diff --git a/src/main/java/it/gov/pagopa/gpd/payments/pull/models/Installment.java b/src/main/java/it/gov/pagopa/gpd/payments/pull/models/Installment.java index 4b48c3b..1da3a3c 100644 --- a/src/main/java/it/gov/pagopa/gpd/payments/pull/models/Installment.java +++ b/src/main/java/it/gov/pagopa/gpd/payments/pull/models/Installment.java @@ -1,6 +1,7 @@ package it.gov.pagopa.gpd.payments.pull.models; import io.quarkus.runtime.annotations.RegisterForReflection; +import it.gov.pagopa.gpd.payments.pull.models.enums.PaymentOptionStatus; import it.gov.pagopa.gpd.payments.pull.models.enums.TransferStatus; import lombok.AllArgsConstructor; import lombok.Builder; @@ -43,7 +44,7 @@ public class Installment implements Serializable { @Schema(description = "corresponds to the SEND notification costs") private long notificationFee; @Schema(description = "Status of the OP", required = true) - private TransferStatus status; + private PaymentOptionStatus status; @Schema(description = "OP update date", required = true) private LocalDateTime lastUpdatedDate; diff --git a/src/test/java/it/gov/pagopa/gpd/payments/pull/service/impl/PaymentNoticesServiceImplTest.java b/src/test/java/it/gov/pagopa/gpd/payments/pull/service/impl/PaymentNoticesServiceImplTest.java index 2d657b7..638cec2 100644 --- a/src/test/java/it/gov/pagopa/gpd/payments/pull/service/impl/PaymentNoticesServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/gpd/payments/pull/service/impl/PaymentNoticesServiceImplTest.java @@ -16,6 +16,8 @@ import org.junit.jupiter.api.Test; import javax.inject.Inject; +import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -37,17 +39,20 @@ class PaymentNoticesServiceImplTest { @Test void getPaymentNoticesShouldReturnOK() { - doReturn(Uni.createFrom().item(Arrays.asList(createPaymentPosition(""), - createPaymentPosition("ACA_")))) + doReturn(Uni.createFrom().item(Arrays.asList(createPaymentPosition("", false), + createPaymentPosition("ACA_", false), + createPaymentPosition("PARTIAL_", true)))) .when(paymentPositionRepository).findPaymentPositionsByTaxCodeAndDueDate (FISCAL_CODE, DUE_DATE, 50, 0); List response = assertDoesNotThrow(() -> paymentNoticesService.getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0)) .await().indefinitely(); assertNotNull(response); - assertEquals(1, response.size()); + assertEquals(2, response.size()); assertEquals("iupd", response.get(0).getIupd()); assertEquals(1, response.get(0).getPaymentOptions().size()); + assertEquals(1, response.get(1).getPaymentOptions().size()); + assertEquals(2, response.get(1).getPaymentOptions().get(0).getInstallments().size()); verify(paymentPositionRepository).findPaymentPositionsByTaxCodeAndDueDate( FISCAL_CODE, DUE_DATE, 50, 0); } @@ -68,7 +73,7 @@ void getPaymentNoticesShouldReturnExceptionOnRepositoryError() { @Test void getPaymentNoticesShouldReturnExceptionOnMappingError() { - PaymentPosition paymentPosition = createPaymentPosition(""); + PaymentPosition paymentPosition = createPaymentPosition("", true); paymentPosition.setPaymentOption(null); doReturn(Uni.createFrom().item(Collections.singletonList(paymentPosition))) .when(paymentPositionRepository).findPaymentPositionsByTaxCodeAndDueDate @@ -81,23 +86,29 @@ void getPaymentNoticesShouldReturnExceptionOnMappingError() { assertEquals(AppErrorCodeEnum.PPL_800, ((PaymentNoticeException) causes.get(causes.size()-1)).getErrorCode()); } - PaymentPosition createPaymentPosition(String prefix) { + PaymentPosition createPaymentPosition(String prefix, Boolean isPartialPayment) { PaymentPosition paymentPosition = PaymentPosition.builder() .iupd(prefix+"iupd") .status(DebtPositionStatus.VALID) .type(Type.F) .build(); - PaymentOption paymentOption = PaymentOption.builder() + List paymentOption = new ArrayList<>( + List.of(new PaymentOption[]{PaymentOption.builder() .amount(100) - .isPartialPayment(false) - .build(); + .dueDate(LocalDateTime.now()) + .isPartialPayment(isPartialPayment) + .build()})); + + if (isPartialPayment) { + paymentOption.add(PaymentOption.builder() + .amount(100) + .dueDate(LocalDateTime.now()) + .isPartialPayment(true) + .build()); + } - paymentOption.setTransfer(Collections.singletonList( - Transfer.builder().amount(100).paymentOption(paymentOption).build()) - ); - paymentOption.setPaymentPosition(paymentPosition); - paymentPosition.setPaymentOption(Collections.singletonList(paymentOption)); + paymentPosition.setPaymentOption(paymentOption); return paymentPosition; }