Skip to content

Commit

Permalink
Merge pull request #99 from pagopa/PAGOPA-1147-amex-filter
Browse files Browse the repository at this point in the history
feat:[PagoPa-1147] AMEX filter
  • Loading branch information
pasqualespica authored Aug 22, 2023
2 parents c50d3c1 + 7811875 commit 5e9954c
Show file tree
Hide file tree
Showing 19 changed files with 269 additions and 51 deletions.
3 changes: 2 additions & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ microservice-chart:
COSMOS_URI: https://pagopa-d-weu-afm-marketplace-cosmos-account.documents.azure.com:443/
ISSUER_RANGE_TABLE: 'pagopadweuafmsaissuerrangetable'
AMOUNT_THRESHOLD: '0'
ID_PSP_POSTE: 'POSTE1'
ID_PSP_POSTE: 'BPPIITRRZZZ'
AMEX_ABI: '36019'
ELASTIC_APM_SERVICE_NAME: pagopa-afm-calculator
ELASTIC_APM_APPLICATION_PACKAGES: it.gov.pagopa.afm.calculator
ELASTIC_APM_SERVER_URL: http://quickstart-apm-http.elastic-system.svc:8200
Expand Down
1 change: 1 addition & 0 deletions helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ microservice-chart:
ISSUER_RANGE_TABLE: 'pagopapweuafmsaissuerrangetable'
AMOUNT_THRESHOLD: '0'
ID_PSP_POSTE: 'BPPIITRRXXX'
AMEX_ABI: '36019'
ELASTIC_APM_SERVICE_NAME: pagopa-afm-calculator
ELASTIC_APM_APPLICATION_PACKAGES: it.gov.pagopa.afm.calculator
ELASTIC_APM_SERVER_URL: http://quickstart-apm-http.elastic-system.svc:8200
Expand Down
1 change: 1 addition & 0 deletions helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ microservice-chart:
ISSUER_RANGE_TABLE: 'pagopauweuafmsaissuerrangetable'
AMOUNT_THRESHOLD: '0'
ID_PSP_POSTE: 'BPPIITRRXXX'
AMEX_ABI: '36019'
ELASTIC_APM_SERVICE_NAME: pagopa-afm-calculator
ELASTIC_APM_APPLICATION_PACKAGES: it.gov.pagopa.afm.calculator
ELASTIC_APM_SERVER_URL: http://quickstart-apm-http.elastic-system.svc:8200
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,2 +1,3 @@
AFM_HOST=https://api.dev.platform.pagopa.it/afm/calculator-service/v1
ID_PSP_POSTE=BPPIITRRZZZ
ID_PSP_POSTE=BPPIITRRZZZ
AMEX_ABI=36019
2 changes: 2 additions & 0 deletions integration-test/src/config/.env.local
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
AFM_HOST=http://localhost:8080
ID_PSP_POSTE=BPPIITRRZZZ
AMEX_ABI=36019
3 changes: 2 additions & 1 deletion integration-test/src/config/.env.uat
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
AFM_HOST=https://api.uat.platform.pagopa.it/afm/calculator-service/v1
ID_PSP_POSTE=BPPIITRRXXX
ID_PSP_POSTE=BPPIITRRXXX
AMEX_ABI=36019
19 changes: 19 additions & 0 deletions integration-test/src/config/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@
"validityDateTo": null,
"paymentType": null,
"abi": 14156
},
{
"id": "int-test-10",
"idPsp": "AMEX",
"idBrokerPsp": "88888888899",
"idChannel": "AMEX_ONUS",
"digitalStamp": false,
"digitalStampRestriction": false,
"name": "pacchetto 10",
"description": "pacchetto 10",
"paymentAmount": 999999999999990,
"minPaymentAmount": 0,
"maxPaymentAmount": 999999999999999,
"type": "GLOBAL",
"validityDateFrom": null,
"validityDateTo": null,
"touchpoint": "ANY",
"paymentType": "CP",
"abi": 36019
}
],
"ciBundles": [
Expand Down
100 changes: 72 additions & 28 deletions integration-test/src/features/getFeeByPsp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ Feature: GetFeeByPsp
When the client send POST to /psps/88888888888/fees
Then check statusCode is 200
And the body response ordering for the bundleOptions.onUs field is:
| onUs |
| false |
| false |
| onUs |
| false |
| false |

Scenario: Get List of fees by CI, amount and single PSP
Given initial json
"""
Expand All @@ -99,13 +99,12 @@ Feature: GetFeeByPsp
When the client send POST to /psps/88888888889/fees
Then check statusCode is 200
And the body response ordering for the bundleOptions.onUs field is:
| onUs |
| true |
| false |
| false |
| false |
| false |

| onUs |
| true |
| false |
| false |
| false |
| false |

Scenario: Get List of fees by CI, amount, touchpoint and single PSP
Given initial json
Expand All @@ -130,13 +129,12 @@ Feature: GetFeeByPsp
When the client send POST to /psps/88888888889/fees
Then check statusCode is 200
And the body response ordering for the bundleOptions.onUs field is:
| onUs |
| true |
| false |
| false |
| false |
| false |

| onUs |
| true |
| false |
| false |
| false |
| false |

Scenario: Get List of fees by CI, amount, touchpoint and single PSP 2
Given initial json
Expand Down Expand Up @@ -211,9 +209,9 @@ Feature: GetFeeByPsp
When the client send POST to /psps/88888888889/fees
Then check statusCode is 200
And the body response ordering for the bundleOptions.onUs field is:
| onUs |
| false |
| false |
| onUs |
| false |
| false |

Scenario: Get List of fees by CI, amount, touchpoint, single PSP and above threshold
Given initial json
Expand All @@ -238,13 +236,12 @@ Feature: GetFeeByPsp
When the client send POST to /psps/88888888889/fees
Then check statusCode is 200
And the body response ordering for the bundleOptions.onUs field is:
| onUs |
| true |
| false |
| false |
| false |
| false |

| onUs |
| true |
| false |
| false |
| false |
| false |

Scenario: Get fee by psp with non-existing bin
Given initial json
Expand Down Expand Up @@ -275,3 +272,50 @@ Feature: GetFeeByPsp
"bundleOptions":[]
}
"""

Scenario: Get List of fees by CI, amount, method, touchpoint and single PSP for AMEX payment
Given initial json
"""
{
"paymentAmount": 999999999999990,
"primaryCreditorInstitution": "77777777777",
"bin": "340000",
"paymentMethod": "CP",
"idPspList": null,
"transferList": [
{
"creditorInstitution": "77777777777",
"transferCategory": "TAX1"
},
{
"creditorInstitution": "77777777778",
"transferCategory": "TAX2"
}
]
}
"""
When the client send POST to /psps/AMEX/fees
Then check statusCode is 200
And check response body is
"""
{
"belowThreshold": false,
"bundleOptions": [
{
"taxPayerFee": 999999999999990,
"primaryCiIncurredFee": 0,
"paymentMethod": "CP",
"touchpoint": "ANY",
"idBundle": "int-test-10",
"bundleName": "pacchetto 10",
"bundleDescription": "pacchetto 10",
"idCiBundle": null,
"idPsp": "AMEX",
"idBrokerPsp": "88888888899",
"idChannel": "AMEX_ONUS",
"onUs": true,
"abi": "36019"
}
]
}
"""
30 changes: 29 additions & 1 deletion integration-test/src/features/getFees.feature
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,32 @@ Feature: GetFees - Get List of fees by CI, amount, method, touchpoint
"""
When the client send POST to /fees?maxOccurrences=10&allCcp=false
Then check statusCode is 200
And the body response does not contain the Poste idPsp
And the body response does not contain the Poste idPsp

Scenario: Execute a GetFees request for AMEX payment
Given initial json
"""
{
"paymentAmount": 999999999999998,
"primaryCreditorInstitution": "77777777777",
"bin": "340000",
"paymentMethod": "CP",
"touchpoint": "CHECKOUT",
"idPspList": null,
"transferList": [
{
"creditorInstitution": "77777777777",
"transferCategory": "TAX1"
},
{
"creditorInstitution": "77777777778",
"transferCategory": "TAX2"
}
]
}
"""
When the client send POST to /fees?maxOccurrences=10
Then check statusCode is 200
And the body response ordering for the bundleOptions.onUs field is:
| onUs |
| true |
13 changes: 13 additions & 0 deletions integration-test/src/step_definitions/support/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,24 @@ let isseuerEntity2 = {
ISSUER_ID: "100",
ABI: "14156"
};
let isseuerEntity3 = {
partitionKey: "340000",
rowKey: "321087",
LOW_RANGE: "3400000000000000000",
HIGH_RANGE: "3499999999999999999",
CIRCUIT: "AMEX",
PRODUCT_CODE: "99",
PRODUCT_TYPE: "3",
PRODUCT_CATEGORY: "C",
ISSUER_ID: "999999",
ABI: "36019"
};

// Synchronous
BeforeAll(function() {
tableStorageClient.setup(isseuerEntity1);
tableStorageClient.setup(isseuerEntity2);
tableStorageClient.setup(isseuerEntity3);
});

Given('the configuration {string}', async function(filePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public BundleOption getFeesByPsp(
@RequestBody @Valid PaymentOptionByPsp paymentOptionByPsp,
@RequestParam(required = false, defaultValue = "10") Integer maxOccurrences,
@RequestParam(required = false, defaultValue = "true")
@Parameter(
description =
"Flag for the exclusion of Poste bundles: false -> excluded, true or null ->"
+ " included")
String allCcp) {
@Parameter(
description =
"Flag for the exclusion of Poste bundles: false -> excluded, true or null ->"
+ " included")
String allCcp) {
PaymentOption paymentOption =
PaymentOption.builder()
.paymentAmount(paymentOptionByPsp.getPaymentAmount())
Expand All @@ -111,7 +111,8 @@ public BundleOption getFeesByPsp(
.transferList(paymentOptionByPsp.getTransferList())
.bin(paymentOptionByPsp.getBin())
.build();
return calculatorService.calculate(paymentOption, maxOccurrences, StringUtils.isBlank(allCcp) || Boolean.parseBoolean(allCcp));
return calculatorService.calculate(
paymentOption, maxOccurrences, StringUtils.isBlank(allCcp) || Boolean.parseBoolean(allCcp));
}

@Operation(
Expand Down Expand Up @@ -176,6 +177,7 @@ public BundleOption getFees(
"Flag for the exclusion of Poste bundles: false -> excluded, true or null ->"
+ " included")
String allCcp) {
return calculatorService.calculate(paymentOption, maxOccurrences, StringUtils.isBlank(allCcp) || Boolean.parseBoolean(allCcp));
return calculatorService.calculate(
paymentOption, maxOccurrences, StringUtils.isBlank(allCcp) || Boolean.parseBoolean(allCcp));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.validation.Valid;
import lombok.Setter;
Expand All @@ -41,6 +42,9 @@ public class CalculatorService {

@Autowired IssuersService issuersService;

@Value("${pspAmex.abi:36019}")
private String amexABI;

@Cacheable(value = "calculate")
public BundleOption calculate(@Valid PaymentOption paymentOption, int limit, boolean allCcp) {
List<ValidBundle> filteredBundles = cosmosRepository.findByPaymentOption(paymentOption, allCcp);
Expand Down Expand Up @@ -98,6 +102,14 @@ private List<Transfer> calculateTaxPayerFee(
}
}

// if it is a payment on the AMEX circuit --> filter to return only AMEX_ONUS
if (this.isAMEXAbi(issuers)) {
Predicate<Transfer> abiPredicate = t -> amexABI.equalsIgnoreCase(t.getAbi());
Predicate<Transfer> onusPredicate = t -> Boolean.TRUE.equals(t.getOnUs());
transfers =
transfers.stream().filter(abiPredicate.and(onusPredicate)).collect(Collectors.toList());
}

// sort according onus and taxpayer fee
Collections.sort(transfers);

Expand All @@ -118,6 +130,10 @@ private boolean isUniqueAbi(List<IssuerRangeEntity> issuers) {
&& issuers.stream().map(IssuerRangeEntity::getAbi).distinct().limit(2).count() > 1;
}

private boolean isAMEXAbi(List<IssuerRangeEntity> issuers) {
return !CollectionUtils.isEmpty(issuers) && issuers.get(0).getAbi().equalsIgnoreCase(amexABI);
}

private List<Transfer> getTransferList(
PaymentOption paymentOption, boolean primaryCiInTransferList, ValidBundle bundle) {
List<Transfer> transfers = new ArrayList<>();
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 @@ -23,3 +23,6 @@ payment.amount.threshold=0

# PSP Poste
pspPoste.id=BPPIITRRZZZ

# AMEX (American Express) payment ABI
pspAmex.abi=36019
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ payment.amount.threshold=${AMOUNT_THRESHOLD}

# PSP Poste
pspPoste.id=${ID_PSP_POSTE}

# AMEX (American Express) payment ABI
pspAmex.abi=${AMEX_ABI}
21 changes: 21 additions & 0 deletions src/test/java/it/gov/pagopa/afm/calculator/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ public static ValidBundle getMockValidBundle() {
.build();
}

public static ValidBundle getMockAmexValidBundle() {
return ValidBundle.builder()
.id("1")
.idChannel("AMEX_ONUS")
.name("bundle1")
.idPsp("AMEX")
.abi("36019")
.paymentAmount(1L)
.minPaymentAmount(0L)
.maxPaymentAmount(1000L)
.type(BundleType.PUBLIC)
.touchpoint("1")
.paymentType("CP")
.transferCategoryList(List.of("TAX1"))
.ciBundleList(Collections.singletonList(getMockCiBundle()))
.digitalStamp(false)
.digitalStampRestriction(false)
.onUs(true)
.build();
}

public static List<ValidBundle> getMockMultipleValidBundle() {
List<ValidBundle> bundles = new ArrayList<>();
bundles.add(
Expand Down
Loading

0 comments on commit 5e9954c

Please sign in to comment.