Skip to content

Commit

Permalink
Merge pull request #121 from pagopa/PAGOPA-1327-psp-whitelist
Browse files Browse the repository at this point in the history
feat: [PagoPA-1327]: psp whitelist
  • Loading branch information
alessio-acitelli authored Feb 7, 2024
2 parents 95897e6 + ed9bfa2 commit d0cf43a
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 36 deletions.
2 changes: 1 addition & 1 deletion helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: pagopa-afm-calculator
description: Microservice that handles calculation for pagoPA Advanced Fees Management
type: application
version: 2.14.0
version: 2.15.0
appVersion: 2.10.4
dependencies:
- name: microservice-chart
Expand Down
3 changes: 2 additions & 1 deletion integration-test/src/config/.env.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
AFM_HOST=https://api.dev.platform.pagopa.it/afm/calculator-service/v1
ID_PSP_POSTE=BPPIITRRZZZ
AMEX_ABI=AMREX
AMEX_ABI=AMREX
PSP_WHITELIST=PPAYITR1XXX,BPPIITRRXXX,CIPBITMM,UNCRITMM,BNLIITRR,BCITITMM,BIC36019
1 change: 1 addition & 0 deletions integration-test/src/config/.env.local
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
AFM_HOST=http://localhost:8080
ID_PSP_POSTE=BPPIITRRZZZ
AMEX_ABI=AMREX
PSP_WHITELIST=PPAYITR1XXX,BPPIITRRXXX,CIPBITMM,UNCRITMM,BNLIITRR,BCITITMM,BIC36019
1 change: 1 addition & 0 deletions integration-test/src/config/.env.prod
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
AFM_HOST=https://api.platform.pagopa.it/afm/calculator-service/v1
PSP_WHITELIST=PPAYITR1XXX,BPPIITRRXXX,CIPBITMM,UNCRITMM,BNLIITRR,BCITITMM,BIC36019

3 changes: 2 additions & 1 deletion integration-test/src/config/.env.uat
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
AFM_HOST=https://api.uat.platform.pagopa.it/afm/calculator-service/v1
ID_PSP_POSTE=BPPIITRRXXX
AMEX_ABI=AMREX
AMEX_ABI=AMREX
PSP_WHITELIST=PPAYITR1XXX,BPPIITRRXXX,CIPBITMM,UNCRITMM,BNLIITRR,BCITITMM,BIC36019
22 changes: 11 additions & 11 deletions integration-test/src/config/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"bundles": [
{
"id": "int-test-1",
"idPsp": "88888888888",
"idPsp": "PPAYITR1XXX",
"idBrokerPsp": "88888888899",
"idChannel": "88888888899_01_ONUS",
"digitalStamp": false,
Expand All @@ -22,7 +22,7 @@
},
{
"id": "int-test-2",
"idPsp": "88888888888",
"idPsp": "PPAYITR1XXX",
"idBrokerPsp": "88888888899",
"idChannel": "88888888899_01_ONUS",
"digitalStamp": false,
Expand All @@ -42,7 +42,7 @@
},
{
"id": "int-test-3",
"idPsp": "88888888889",
"idPsp": "BPPIITRRXXX",
"idBrokerPsp": "88888888899",
"idChannel": "88888888899_01_ONUS",
"digitalStamp": false,
Expand All @@ -63,7 +63,7 @@
},
{
"id": "int-test-4",
"idPsp": "88888888889",
"idPsp": "BPPIITRRXXX",
"idBrokerPsp": "88888888899",
"idChannel": "88888888899_01_ONUS",
"digitalStamp": false,
Expand All @@ -86,7 +86,7 @@
},
{
"id": "int-test-5",
"idPsp": "88888888888",
"idPsp": "PPAYITR1XXX",
"idBrokerPsp": "88888888899",
"idChannel": "88888888899_01_ONUS",
"digitalStamp": false,
Expand All @@ -111,7 +111,7 @@
},
{
"id": "int-test-6",
"idPsp": "88888888889",
"idPsp": "BPPIITRRXXX",
"idBrokerPsp": "88888888899",
"idChannel": "88888888899_01_ONUS",
"digitalStamp": false,
Expand All @@ -131,7 +131,7 @@
},
{
"id": "int-test-7",
"idPsp": "88888888889",
"idPsp": "BPPIITRRXXX",
"idBrokerPsp": "88888888899",
"idChannel": "88888888899_01_ONUS",
"digitalStamp": true,
Expand All @@ -151,7 +151,7 @@
},
{
"id": "int-test-8",
"idPsp": "88888888889",
"idPsp": "BPPIITRRXXX",
"idBrokerPsp": "88888888899",
"idChannel": "88888888899_01_ONUS",
"digitalStamp": true,
Expand All @@ -171,7 +171,7 @@
},
{
"id": "int-test-9",
"idPsp": "BPPIITRRZZZ",
"idPsp": "CIPBITMM",
"idBrokerPsp": "14847241008",
"idChannel": "88888888899_01_ONUS",
"digitalStamp": true,
Expand All @@ -191,9 +191,9 @@
},
{
"id": "int-test-10",
"idPsp": "AMEX",
"idPsp": "UNCRITMM",
"idBrokerPsp": "88888888899",
"idChannel": "AMEX_ONUS",
"idChannel": "UNCRITMM_ONUS",
"digitalStamp": false,
"digitalStampRestriction": false,
"name": "pacchetto 10",
Expand Down
32 changes: 16 additions & 16 deletions integration-test/src/features/getFeeByPsp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Feature: GetFeeByPsp
]
}
"""
When the client send POST to /psps/88888888888/fees
When the client send POST to /psps/PPAYITR1XXX/fees
Then check statusCode is 200
And check response body is
"""
Expand All @@ -40,7 +40,7 @@ Feature: GetFeeByPsp
"bundleName": "pacchetto 1",
"bundleDescription": "pacchetto 1",
"idCiBundle": "int-test-1",
"idPsp": "88888888888",
"idPsp": "PPAYITR1XXX",
"idBrokerPsp": "88888888899",
"idChannel": "88888888899_01_ONUS",
"onUs": false,
Expand Down Expand Up @@ -71,7 +71,7 @@ Feature: GetFeeByPsp
]
}
"""
When the client send POST to /psps/88888888888/fees
When the client send POST to /psps/PPAYITR1XXX/fees
Then check statusCode is 200
And the body response ordering for the bundleOptions.onUs field is:
| onUs |
Expand All @@ -97,15 +97,15 @@ Feature: GetFeeByPsp
]
}
"""
When the client send POST to /psps/88888888889/fees
When the client send POST to /psps/BPPIITRRXXX/fees
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
Given initial json
Expand All @@ -127,15 +127,15 @@ Feature: GetFeeByPsp
]
}
"""
When the client send POST to /psps/88888888889/fees
When the client send POST to /psps/BPPIITRRXXX/fees
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 2
Given initial json
Expand All @@ -159,7 +159,7 @@ Feature: GetFeeByPsp
]
}
"""
When the client send POST to /psps/88888888889/fees
When the client send POST to /psps/BPPIITRRXXX/fees
Then check statusCode is 200
And check response body is
"""
Expand All @@ -175,7 +175,7 @@ Feature: GetFeeByPsp
"bundleName": "pacchetto 7",
"bundleDescription": "pacchetto 7",
"idCiBundle": null,
"idPsp": "88888888889",
"idPsp": "BPPIITRRXXX",
"idBrokerPsp": "88888888899",
"idChannel": "88888888899_01_ONUS",
"onUs": false,
Expand Down Expand Up @@ -208,7 +208,7 @@ Feature: GetFeeByPsp
]
}
"""
When the client send POST to /psps/88888888889/fees
When the client send POST to /psps/BPPIITRRXXX/fees
Then check statusCode is 200
And the body response ordering for the bundleOptions.onUs field is:
| onUs |
Expand All @@ -235,15 +235,15 @@ Feature: GetFeeByPsp
]
}
"""
When the client send POST to /psps/88888888889/fees
When the client send POST to /psps/BPPIITRRXXX/fees
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 fee by psp with non-existing bin
Given initial json
Expand All @@ -265,7 +265,7 @@ Feature: GetFeeByPsp
]
}
"""
When the client send POST to /psps/88888888889/fees
When the client send POST to /psps/BPPIITRRXXX/fees
Then check statusCode is 200
And check response body is
"""
Expand Down Expand Up @@ -296,7 +296,7 @@ Feature: GetFeeByPsp
]
}
"""
When the client send POST to /psps/AMEX/fees
When the client send POST to /psps/UNCRITMM/fees
Then check statusCode is 200
And check response body is
"""
Expand All @@ -312,9 +312,9 @@ Feature: GetFeeByPsp
"bundleName": "pacchetto 10",
"bundleDescription": "pacchetto 10",
"idCiBundle": null,
"idPsp": "AMEX",
"idPsp": "UNCRITMM",
"idBrokerPsp": "88888888899",
"idChannel": "AMEX_ONUS",
"idChannel": "UNCRITMM_ONUS",
"onUs": true,
"abi": "AMREX",
"pspBusinessName": "psp business name int-test-10"
Expand Down
8 changes: 4 additions & 4 deletions integration-test/src/features/getFees.feature
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint
And the body response ordering for the bundleOptions.onUs field is:
| onUs |
| true |
| false |
| true |
| false |
| false |
| false |
| false |
| false |
| false |

Scenario: Get List of fees by CI, amount, method and single PSP
Given initial json
Expand Down Expand Up @@ -144,7 +144,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",
Expand Down Expand Up @@ -175,7 +175,7 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint
"bundleName": "pacchetto 7",
"bundleDescription": "pacchetto 7",
"idCiBundle": null,
"idPsp": "88888888889",
"idPsp": "BPPIITRRXXX",
"idChannel": "88888888899_01_ONUS",
"idBrokerPsp": "88888888899",
"onUs": false,
Expand Down Expand Up @@ -245,13 +245,13 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint
And the body response ordering for the bundleOptions.onUs field is:
| onUs |
| true |
| false |
| true |
| false |
| false |
| false |
| false |
| false |
| false |


Scenario: Execute a GetFees request with non-existing bin
Expand Down
5 changes: 5 additions & 0 deletions integration-test/src/step_definitions/support/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ Then(/^check response body is$/, function(payload) {
});

Then('the body response ordering for the bundleOptions.onUs field is:', function (dataTable) {
// force the obtained list to be sorted by onUs field value
responseToCheck.data.bundleOptions.sort(function (a, b) {
// true values first
return (a.onUs === b.onUs)? 0 : a.onUs? -1 : 1;
});
for (let i=0; i<responseToCheck.data.bundleOptions.length; i++){
let bodyOnUs = responseToCheck.data.bundleOptions[i].onUs;
let checkOnUs = JSON.parse(dataTable.rows()[i][0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;
Expand All @@ -36,6 +37,11 @@ public class CosmosRepository {

@Value("${pspPoste.id}")
private String pspPosteId;

@Value("#{'${psp.whitelist}'.split(',')}")
private List<String> pspWhitelist;

private static final String ID_PSP_PARAM = "idPsp";

/**
* @param ciFiscalCode fiscal code of the CI
Expand Down Expand Up @@ -136,9 +142,15 @@ private Iterable<ValidBundle> findValidBundles(PaymentOption paymentOption, bool

// add filter for Poste bundles
if (!allCcp) {
var allCcpFilter = isNotEqual("idPsp", pspPosteId);
var allCcpFilter = isNotEqual(ID_PSP_PARAM, pspPosteId);
queryResult = and(queryResult, allCcpFilter);
}

// add filter for PSP whitelist
if (!CollectionUtils.isEmpty(pspWhitelist)) {
var pspIn = in(ID_PSP_PARAM, pspWhitelist);
queryResult = and(queryResult, pspIn);
}

// execute the query
return cosmosTemplate.find(new CosmosQuery(queryResult), ValidBundle.class, "validbundles");
Expand Down Expand Up @@ -230,7 +242,7 @@ private Criteria getPspFilterCriteria(
Criteria queryTmp = null;
while (iterator.hasNext()) {
var pspSearch = iterator.next();
var queryItem = isEqual("idPsp", pspSearch.getIdPsp());
var queryItem = isEqual(ID_PSP_PARAM, pspSearch.getIdPsp());
if (StringUtils.isNotEmpty(pspSearch.getIdChannel())) {
queryItem = and(queryItem, isEqual("idChannel", pspSearch.getIdChannel()));
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ pspPoste.id=BPPIITRRZZZ

# AMEX (American Express) payment ABI
pspAmex.abi=AMREX

# PSP whitelist to manage which bundles must be filtered
psp.whitelist=PPAYITR1XXX,BPPIITRRXXX,CIPBITMM,UNCRITMM,BNLIITRR,BCITITMM,BIC36019
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ pspPoste.id=${ID_PSP_POSTE}

# AMEX (American Express) payment ABI
pspAmex.abi=${AMEX_ABI}

# PSP whitelist to manage which bundles must be filtered
psp.whitelist=${PSP_WHITELIST}
3 changes: 3 additions & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ payment.amount.threshold=0
# PSP Poste
pspPoste.id=testIdPspPoste

# PSP whitelist to manage which bundles must be filtered
psp.whitelist=PPAYITR1XXX,BPPIITRRXXX,CIPBITMM,UNCRITMM,BNLIITRR,BCITITMM,BIC36019

# Openapi
springdoc.writer-with-order-by-keys=false
springdoc.writer-with-default-pretty-printer=true
Expand Down

0 comments on commit d0cf43a

Please sign in to comment.