diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 209644bc..6d6b7e5f 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-afm-calculator description: Microservice that handles calculation for pagoPA Advanced Fees Management type: application -version: 2.45.0 -appVersion: 2.10.32 +version: 2.46.0 +appVersion: 2.10.32-1-PAGOPA-2348 dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index c5eb511b..8cc05564 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-calculator - tag: "2.10.32" + tag: "2.10.32-1-PAGOPA-2348" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index c45f8de9..3d152968 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-calculator - tag: "2.10.32" + tag: "2.10.32-1-PAGOPA-2348" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index d1d7209f..3802c1fc 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-calculator - tag: "2.10.32" + tag: "2.10.32-1-PAGOPA-2348" pullPolicy: Always livenessProbe: httpGet: diff --git a/integration-test/src/config/data.json b/integration-test/src/config/data.json index d034dd9e..4d47914f 100644 --- a/integration-test/src/config/data.json +++ b/integration-test/src/config/data.json @@ -18,7 +18,8 @@ "touchpoint": "ANY", "paymentType": null, "abi": 14156, - "pspBusinessName": "psp business name int-test-1" + "pspBusinessName": "psp business name int-test-1", + "cart" : true }, { "id": "int-test-2", @@ -38,7 +39,8 @@ "validityDateTo": null, "touchpoint": "ANY", "abi": 14156, - "pspBusinessName": "psp business name int-test-2" + "pspBusinessName": "psp business name int-test-2", + "cart" : true }, { "id": "int-test-3", @@ -59,7 +61,8 @@ "validityDateTo": null, "touchpoint": "ANY", "abi": 14156, - "pspBusinessName": "psp business name int-test-3" + "pspBusinessName": "psp business name int-test-3", + "cart" : true }, { "id": "int-test-4", @@ -82,7 +85,8 @@ "validityDateFrom": null, "validityDateTo": null, "touchpoint": "ANY", - "paymentType": null + "paymentType": null, + "cart" : true }, { "id": "int-test-5", @@ -107,7 +111,8 @@ "validityDateFrom": null, "validityDateTo": null, "abi": 14156, - "pspBusinessName": "psp business name int-test-5" + "pspBusinessName": "psp business name int-test-5", + "cart" : true }, { "id": "int-test-6", @@ -127,7 +132,8 @@ "validityDateTo": null, "paymentType": null, "abi": 14156, - "pspBusinessName": "psp business name int-test-6" + "pspBusinessName": "psp business name int-test-6", + "cart" : true }, { "id": "int-test-7", @@ -147,7 +153,8 @@ "validityDateTo": null, "paymentType": null, "abi": 14156, - "pspBusinessName": "psp business name int-test-7" + "pspBusinessName": "psp business name int-test-7", + "cart" : true }, { "id": "int-test-8", @@ -167,7 +174,8 @@ "validityDateTo": null, "paymentType": null, "abi": 14156, - "pspBusinessName": "psp business name int-test-8" + "pspBusinessName": "psp business name int-test-8", + "cart" : true }, { "id": "int-test-9", @@ -187,7 +195,8 @@ "validityDateTo": null, "paymentType": null, "abi": 14156, - "pspBusinessName": "psp business name int-test-9" + "pspBusinessName": "psp business name int-test-9", + "cart" : true }, { "id": "int-test-10", @@ -207,7 +216,8 @@ "touchpoint": "ANY", "paymentType": "CP", "abi": "AMREX", - "pspBusinessName": "psp business name int-test-10" + "pspBusinessName": "psp business name int-test-10", + "cart" : true }, { "id": "int-test-cart-cart-1", @@ -227,7 +237,8 @@ "touchpoint": "ANY", "paymentType": "CP", "abi": 14156, - "pspBusinessName": "psp business name int-test-cart-1" + "pspBusinessName": "psp business name int-test-cart-1", + "cart" : true }, { "id": "int-test-cart-cart-2", @@ -247,7 +258,8 @@ "touchpoint": "ANY", "paymentType": "CP", "abi": 14156, - "pspBusinessName": "psp business name int-test-cart-2" + "pspBusinessName": "psp business name int-test-cart-2", + "cart" : true }, { "id": "int-test-cart-cart-3", @@ -267,7 +279,8 @@ "touchpoint": "ANY", "paymentType": "CP", "abi": 14156, - "pspBusinessName": "psp business name int-test-cart-3" + "pspBusinessName": "psp business name int-test-cart-3", + "cart" : true }, { "id": "int-test-cart-cart-4", @@ -287,7 +300,8 @@ "touchpoint": "ANY", "paymentType": "CP", "abi": 14156, - "pspBusinessName": "psp business name int-test-cart-4" + "pspBusinessName": "psp business name int-test-cart-4", + "cart" : true }, { "id": "int-test-cart-cart-5", @@ -307,7 +321,8 @@ "touchpoint": "ANY", "paymentType": "CP", "abi": 14156, - "pspBusinessName": "psp business name int-test-cart-5" + "pspBusinessName": "psp business name int-test-cart-5", + "cart" : true }, { "id": "int-test-cart-cart-6", @@ -327,7 +342,8 @@ "touchpoint": "ANY", "paymentType": "CP", "abi": 14156, - "pspBusinessName": "psp business name int-test-cart-6" + "pspBusinessName": "psp business name int-test-cart-6", + "cart" : true }, { "id": "int-test-cart-cart-7", @@ -347,7 +363,50 @@ "touchpoint": "ANY", "paymentType": null, "abi": 10101, - "pspBusinessName": "psp business name int-test-cart-7" + "pspBusinessName": "psp business name int-test-cart-7", + "cart" : true + }, + { + "id": "int-test-cart-cart-8", + "idPsp": "PPAYITR1XXX", + "idBrokerPsp": "88888888899", + "idChannel": "88888888899_01_ONUS", + "digitalStamp": false, + "digitalStampRestriction": false, + "name": "pacchetto 8", + "description": "pacchetto 8", + "paymentAmount": 100, + "minPaymentAmount": 899999999999986, + "maxPaymentAmount": 899999999999988, + "type": "GLOBAL", + "validityDateFrom": null, + "validityDateTo": null, + "touchpoint": "ANY", + "paymentType": "CP", + "abi": 14156, + "pspBusinessName": "psp business name int-test-cart-8", + "cart" : true + }, + { + "id": "int-test-cart-cart-9", + "idPsp": "PPAYITR1XXX", + "idBrokerPsp": "88888888899", + "idChannel": "88888888899_01_ONUS", + "digitalStamp": false, + "digitalStampRestriction": false, + "name": "pacchetto 9", + "description": "pacchetto 9", + "paymentAmount": 150, + "minPaymentAmount": 899999999999986, + "maxPaymentAmount": 899999999999988, + "type": "PRIVATE", + "validityDateFrom": null, + "validityDateTo": null, + "touchpoint": "ANY", + "paymentType": "CP", + "abi": 14156, + "pspBusinessName": "psp business name int-test-cart-9", + "cart" : true } ], "ciBundles": [ @@ -479,7 +538,7 @@ "maxPaymentAmount": 20 }, { - "id": "int-test-cart-cart-10", + "id": "int-test-cart-10", "maxPaymentAmount": 40 } ] @@ -490,10 +549,21 @@ "idBundle": "int-test-cart-cart-7", "attributes": [ { - "id": "int-test-cart-9", + "id": "int-test-cart-11", "maxPaymentAmount": 20 } ] + }, + { + "id": "int-test-cart-10", + "ciFiscalCode": "77777777777", + "idBundle": "int-test-cart-cart-9", + "attributes": [ + { + "id": "int-test-cart-12", + "maxPaymentAmount": 60 + } + ] } ], "touchpoints": [ diff --git a/integration-test/src/features/getFees.feature b/integration-test/src/features/getFees.feature index 4da5d0a2..af692ca5 100644 --- a/integration-test/src/features/getFees.feature +++ b/integration-test/src/features/getFees.feature @@ -79,7 +79,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint "bin": "309500", "paymentMethod": "CP", "touchpoint": null, - "idPspList": [{"idPsp":"88888888889"}], + "idPspList": [{"idPsp":"PPAYITR1XXX"}], "transferList": [ { "creditorInstitution": "77777777777", @@ -96,12 +96,8 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint Then check statusCode is 200 And the body response ordering for the bundleOptions.onUs field is: | onUs | + | true | | false | - | false | - | false | - | false | - | true | - Scenario: Get List of fees by CI, amount, touchpoint and single PSP @@ -113,7 +109,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint "bin": "309500", "paymentMethod": null, "touchpoint": "IO", - "idPspList": [{"idPsp":"88888888888"}], + "idPspList": [{"idPsp":"PPAYITR1XXX"}], "transferList": [ { "creditorInstitution": "77777777777", @@ -130,8 +126,8 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint Then check statusCode is 200 And the body response ordering for the bundleOptions.onUs field is: | onUs | + | true | | false | - | true | | false | @@ -195,7 +191,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint "bin": "309500", "paymentMethod": null, "touchpoint": "IO", - "idPspList": [{"idPsp":"88888888889"}], + "idPspList": [{"idPsp":"BPPIITRRXXX"}], "transferList": [ { "creditorInstitution": "77777777777", @@ -280,13 +276,6 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint Then check statusCode is 200 And the body response ordering for the bundleOptions.onUs field is: | onUs | - | false | - | false | - | false | - | false | - | false | - | false | - | false | Scenario: Execute a GetFees request with allCcp flag set to false Given initial json diff --git a/integration-test/src/features/getFeesByPspMulti.feature b/integration-test/src/features/getFeesByPspMulti.feature index a2e9d0dd..d4f44c11 100644 --- a/integration-test/src/features/getFeesByPspMulti.feature +++ b/integration-test/src/features/getFeesByPspMulti.feature @@ -26,6 +26,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /psps/PPAYITR1XXX/fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response for the bundleOptions.idsCiBundle field is: | idCiBundle | | "int-test-cart-1" | @@ -56,6 +57,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /psps/PPAYITR1XXX/fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response for the bundleOptions.idsCiBundle field is: | idCiBundle | | "int-test-cart-2" | @@ -96,6 +98,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /psps/PPAYITR1XXX/fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response for the bundleOptions.idsCiBundle field is: | idCiBundle | And the sum of the fees is correct and the EC codes are: @@ -134,6 +137,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /psps/PPAYITR1XXX/fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response for the bundleOptions.idsCiBundle field is: | idCiBundle | And the sum of the fees is correct and the EC codes are: @@ -162,6 +166,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /psps/PPAYITR1XXX/fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response for the bundleOptions.idsCiBundle field is: | idCiBundle | | "int-test-cart-6" | @@ -202,6 +207,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /psps/PPAYITR1XXX/fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response for the bundleOptions.idsCiBundle field is: | idCiBundle1 | idCiBundle2 | | "int-test-cart-5" | "int-test-cart-6" | @@ -242,15 +248,45 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /psps/PPAYITR1XXX/fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response for the bundleOptions.idsCiBundle field is: | idCiBundle1 | idCiBundle2 | | "int-test-cart-7" | "int-test-cart-8" | - | "int-test-cart-7" | "int-test-cart-8" | - | "int-test-cart-7" | "int-test-cart-8" | - | "int-test-cart-7" | "int-test-cart-8" | And the sum of the fees is correct and the EC codes are: | feeCode1 | feeCode2 | | "77777777777" | "88888888888" | - | "77777777777" | "88888888888" | - | "77777777777" | "88888888888" | - | "77777777777" | "88888888888" | + + Scenario: Multiple bundles are available, but only one is returned + Given initial json + """ + { + "bin": "309500", + "paymentMethod": "CP", + "touchpoint": "CHECKOUT", + "idPspList": null, + "paymentNotice": [ + { + "primaryCreditorInstitution": "77777777777", + "paymentAmount": 899999999999987, + "transferList": [ + { + "creditorInstitution": "77777777777", + "transferCategory": "TAX1" + } + ] + } + ] + } + """ + When the client send a V2 POST to /psps/PPAYITR1XXX/fees + Then check statusCode is 200 + And the body response has one bundle for each psp + And the body response ordering for the bundleOptions.onUs field is: + | onUs | + | true | + And the body response for the bundleOptions.idsCiBundle field is: + | idCiBundle | + | "int-test-cart-10" | + And the sum of the fees is correct and the EC codes are: + | feeCode | + | "77777777777" | diff --git a/integration-test/src/features/getFeesMulti.feature b/integration-test/src/features/getFeesMulti.feature index b6336e8a..7072f5f6 100644 --- a/integration-test/src/features/getFeesMulti.feature +++ b/integration-test/src/features/getFeesMulti.feature @@ -27,6 +27,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response ordering for the bundleOptions.onUs field is: | onUs | | true | @@ -40,6 +41,41 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint | "77777777777" | | "77777777777" | + Scenario: Commission is higher than the sum of the fees with one psp + Given initial json + """ + { + "bin": "309500", + "paymentMethod": "CP", + "touchpoint": "CHECKOUT", + "idPspList": [{"idPsp":"PPAYITR1XXX"}], + "paymentNotice": [ + { + "primaryCreditorInstitution": "77777777777", + "paymentAmount": 899999999999999, + "transferList": [ + { + "creditorInstitution": "77777777777", + "transferCategory": "TAX1" + } + ] + } + ] + } + """ + When the client send a V2 POST to /fees + Then check statusCode is 200 + And the body response has one bundle for each psp + And the body response ordering for the bundleOptions.onUs field is: + | onUs | + | true | + And the body response for the bundleOptions.idsCiBundle field is: + | idCiBundle | + | "int-test-cart-1" | + And the sum of the fees is correct and the EC codes are: + | feeCode | + | "77777777777" | + Scenario: Commission is lower than the sum of the fees Given initial json """ @@ -64,6 +100,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response ordering for the bundleOptions.onUs field is: | onUs | | true | @@ -111,6 +148,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response ordering for the bundleOptions.onUs field is: | onUs | | true | @@ -154,6 +192,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response ordering for the bundleOptions.onUs field is: | onUs | | true | @@ -187,6 +226,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response ordering for the bundleOptions.onUs field is: | onUs | | true | @@ -232,6 +272,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response ordering for the bundleOptions.onUs field is: | onUs | | true | @@ -277,22 +318,98 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint """ When the client send a V2 POST to /fees Then check statusCode is 200 + And the body response has one bundle for each psp And the body response ordering for the bundleOptions.onUs field is: | onUs | | true | - | true | - | true | - | true | | false | And the body response for the bundleOptions.idsCiBundle field is: | idCiBundle1 | idCiBundle2 | | "int-test-cart-7" | "int-test-cart-8" | - | "int-test-cart-7" | "int-test-cart-8" | - | "int-test-cart-7" | "int-test-cart-8" | - | "int-test-cart-7" | "int-test-cart-8" | And the sum of the fees is correct and the EC codes are: | feeCode1 | feeCode2 | | "77777777777" | "88888888888" | - | "77777777777" | "88888888888" | - | "77777777777" | "88888888888" | - | "77777777777" | "88888888888" | + + Scenario: Multiple ciBundles and multiple paymentNoticeItems + Given initial json + """ + { + "bin": "309500", + "paymentMethod": "CP", + "touchpoint": "CHECKOUT", + "idPspList": null, + "paymentNotice": [ + { + "primaryCreditorInstitution": "77777777777", + "paymentAmount": 899999999998991, + "transferList": [ + { + "creditorInstitution": "77777777777", + "transferCategory": "TAX1" + } + ] + }, + { + "primaryCreditorInstitution": "88888888888", + "paymentAmount": 1000, + "transferList": [ + { + "creditorInstitution": "88888888888", + "transferCategory": "TAX1" + } + ] + } + ] + } + """ + When the client send a V2 POST to /fees + Then check statusCode is 200 + And the body response has one bundle for each psp + And the body response ordering for the bundleOptions.onUs field is: + | onUs | + | true | + | false | + And the body response for the bundleOptions.idsCiBundle field is: + | idCiBundle1 | idCiBundle2 | + | "int-test-cart-5" | "int-test-cart-6" | + And the sum of the fees is correct and the EC codes are: + | feeCode1 | feeCode2 | + | "77777777777" | "88888888888" | + + Scenario: Multiple bundles are available, but only one per psp is returned + Given initial json + """ + { + "bin": "309500", + "paymentMethod": "CP", + "touchpoint": "CHECKOUT", + "idPspList": null, + "paymentNotice": [ + { + "primaryCreditorInstitution": "77777777777", + "paymentAmount": 899999999999987, + "transferList": [ + { + "creditorInstitution": "77777777777", + "transferCategory": "TAX1" + } + ] + } + ] + } + """ + When the client send a V2 POST to /fees + Then check statusCode is 200 + And the body response has one bundle for each psp + And the body response ordering for the bundleOptions.onUs field is: + | onUs | + | true | + | false | + And the body response for the bundleOptions.idsCiBundle field is: + | idCiBundle | + | "int-test-cart-10" | + | "int-test-cart-9" | + And the sum of the fees is correct and the EC codes are: + | feeCode | + | "77777777777" | + | "77777777777" | diff --git a/integration-test/src/step_definitions/support/steps.js b/integration-test/src/step_definitions/support/steps.js index bab54506..84abd3b9 100644 --- a/integration-test/src/step_definitions/support/steps.js +++ b/integration-test/src/step_definitions/support/steps.js @@ -114,13 +114,21 @@ Then('the body response ordering for the bundleOptions.onUs field is:', function // true values first return (a.onUs === b.onUs)? 0 : a.onUs? -1 : 1; }); - for (let i=0; i b.creditorInstitution) ? 1 : ((b.creditorInstitution > a.creditorInstitution) ? -1 : 0); }); - for(let j=0; jit.gov.pagopa calculator - 2.10.32 + 2.10.32-1-PAGOPA-2348 afm-calculator Calculator Logic microservice for pagoPA AFM diff --git a/src/main/java/it/gov/pagopa/afm/calculator/entity/Bundle.java b/src/main/java/it/gov/pagopa/afm/calculator/entity/Bundle.java index 287a2c16..55aa4c69 100644 --- a/src/main/java/it/gov/pagopa/afm/calculator/entity/Bundle.java +++ b/src/main/java/it/gov/pagopa/afm/calculator/entity/Bundle.java @@ -59,4 +59,7 @@ public class Bundle { // useful only if paymentType = CP private Boolean onUs; + + // useful to see if a bundle available for carts + private Boolean cart; } diff --git a/src/main/java/it/gov/pagopa/afm/calculator/service/CalculatorService.java b/src/main/java/it/gov/pagopa/afm/calculator/service/CalculatorService.java index 5775b556..74cd36e6 100644 --- a/src/main/java/it/gov/pagopa/afm/calculator/service/CalculatorService.java +++ b/src/main/java/it/gov/pagopa/afm/calculator/service/CalculatorService.java @@ -138,7 +138,7 @@ private List calculateTaxPayerFee( private List calculateTaxPayerFeeMulti( PaymentOptionMulti paymentOption, int limit, List bundles) { - List transfers = new ArrayList<>(); + Map pspTransfersMap = new HashMap<>(); // 1. Check if ONUS payment: // - ONUS payment = if the bundle ABI attribute matching the one extracted via BIN from the @@ -168,15 +168,18 @@ private List calcul // 2.a: if ONUS payment -> return the transfer list only for bundles with the idChannel // attribute ending in '_ONUS' if (isOnusPaymentType && isOnusBundle(bundle)) { - transfers.addAll(this.getTransferList(paymentOption, bundle)); + addToPspTransfersMap(pspTransfersMap, this.getTransferList(paymentOption, bundle)); } // 2.b: if not ONUS payment -> return the transfer list only for bundles with the idChannel // attribute NOT ending in '_ONUS' if (!isOnusPaymentType && !isOnusBundle(bundle)) { - transfers.addAll(this.getTransferList(paymentOption, bundle)); + addToPspTransfersMap(pspTransfersMap, this.getTransferList(paymentOption, bundle)); } } + // convert mapping of psp and transfer to transfer list + List transfers = new ArrayList<>(pspTransfersMap.values()); + // if it is a payment on the AMEX circuit --> filter to return only AMEX_ONUS if (this.isAMEXAbi(issuers)) { Predicate abiPredicate = t -> amexABI.equalsIgnoreCase(t.getAbi()); @@ -518,6 +521,16 @@ private boolean isBelowThreshold(long paymentAmount) { return paymentAmount < Long.parseLong(StringUtils.trim(amountThreshold)); } + private void addToPspTransfersMap(Map pspTransferMap, + List transferList) { + for(it.gov.pagopa.afm.calculator.model.calculatormulti.Transfer transfer : transferList) { + if(!pspTransferMap.containsKey(transfer.getIdPsp()) || + pspTransferMap.get(transfer.getIdPsp()).getActualPayerFee() > transfer.getActualPayerFee()) { + pspTransferMap.put(transfer.getIdPsp(), transfer); + } + } + } + /** * sort by bundles' fee grouped by PSP * diff --git a/src/test/java/it/gov/pagopa/afm/calculator/TestUtil.java b/src/test/java/it/gov/pagopa/afm/calculator/TestUtil.java index e9169778..f284d898 100644 --- a/src/test/java/it/gov/pagopa/afm/calculator/TestUtil.java +++ b/src/test/java/it/gov/pagopa/afm/calculator/TestUtil.java @@ -283,6 +283,51 @@ public static List getMockMultipleValidBundle() { return bundles; } + public static List getMockMultipleValidBundleSamePsp() { + List bundles = new ArrayList<>(); + bundles.add( + ValidBundle.builder() + .id("1") + .idChannel("13212880150_01") + .name("bundle1") + .idPsp("ABC") + .pspBusinessName("psp business name") + .abi("14160") + .paymentAmount(50L) + .minPaymentAmount(0L) + .maxPaymentAmount(1000L) + .type(BundleType.GLOBAL) + .touchpoint("1") + .paymentType("CP") + .transferCategoryList(List.of("TAX1")) + .ciBundleList(new ArrayList<>()) + .digitalStamp(false) + .digitalStampRestriction(false) + .onUs(true) + .build()); + bundles.add( + ValidBundle.builder() + .id("2") + .idChannel("13212880150_02_ONUS") + .name("bundle2") + .idPsp("ABC") + .pspBusinessName("psp business name") + .abi("14156") + .paymentAmount(55L) + .minPaymentAmount(0L) + .maxPaymentAmount(1000L) + .type(BundleType.PUBLIC) + .touchpoint("1") + .paymentType("CP") + .transferCategoryList(List.of("TAX2")) + .ciBundleList(Collections.singletonList(getMockCiBundle())) + .digitalStamp(false) + .digitalStampRestriction(false) + .onUs(true) + .build()); + return bundles; + } + public static Touchpoint getMockTouchpoints() { return Touchpoint.builder().id("1").name("CHECKOUT").creationDate(LocalDateTime.now()).build(); } diff --git a/src/test/java/it/gov/pagopa/afm/calculator/service/CalculatorServiceTest.java b/src/test/java/it/gov/pagopa/afm/calculator/service/CalculatorServiceTest.java index f3f378bb..0607e581 100644 --- a/src/test/java/it/gov/pagopa/afm/calculator/service/CalculatorServiceTest.java +++ b/src/test/java/it/gov/pagopa/afm/calculator/service/CalculatorServiceTest.java @@ -769,4 +769,21 @@ void calculateMultiFullCommission() throws IOException, JSONException { String expected = TestUtil.readStringFromFile("responses/getFeesMultiWrongEC.json"); JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT); } + + @Test + @Order(28) + void calculateMultiMultipleBundlesOneOutput() throws IOException, JSONException { + CosmosRepository cosmosRepository = Mockito.mock(CosmosRepository.class); + calculatorService.setCosmosRepository(cosmosRepository); + + List validBundles = TestUtil.getMockMultipleValidBundleSamePsp(); + Mockito.doReturn(validBundles).when(cosmosRepository).findByPaymentOption(any(PaymentOptionMulti.class), any(Boolean.class)); + + var paymentOption = TestUtil.readObjectFromFile("requests/getFeesMultiSamePsp.json", PaymentOptionMulti.class); + var result = calculatorService.calculateMulti(paymentOption, 10, true); + String actual = TestUtil.toJson(result); + + String expected = TestUtil.readStringFromFile("responses/getFeesMultiSamePsp.json"); + JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT); + } } diff --git a/src/test/resources/requests/getFeesMultiSamePsp.json b/src/test/resources/requests/getFeesMultiSamePsp.json new file mode 100644 index 00000000..c6e9e831 --- /dev/null +++ b/src/test/resources/requests/getFeesMultiSamePsp.json @@ -0,0 +1,18 @@ +{ + "bin": "1005066", + "paymentMethod": "CP", + "touchpoint": "CHECKOUT", + "idPspList": [], + "paymentNotice": [ + { + "primaryCreditorInstitution": "77777777777", + "paymentAmount": 70, + "transferList": [ + { + "creditorInstitution": "77777777777", + "transferCategory": "TAX1" + } + ] + } + ] +} diff --git a/src/test/resources/responses/getFeesMultiSamePsp.json b/src/test/resources/responses/getFeesMultiSamePsp.json new file mode 100644 index 00000000..a00935e4 --- /dev/null +++ b/src/test/resources/responses/getFeesMultiSamePsp.json @@ -0,0 +1,28 @@ +{ + "belowThreshold": false, + "bundleOptions": [ + { + "taxPayerFee": 55, + "actualPayerFee": 45, + "paymentMethod": "CP", + "touchpoint": "1", + "idBundle": "2", + "bundleName": "bundle2", + "bundleDescription": null, + "idsCiBundle": ["1"], + "idPsp": "ABC", + "idChannel": "13212880150_02_ONUS", + "idBrokerPsp": null, + "onUs": true, + "abi": "14156", + "pspBusinessName": "psp business name", + "fees": [ + { + "creditorInstitution" : "77777777777", + "primaryCiIncurredFee": 10, + "actualCiIncurredFee": 10 + } + ] + } + ] +}