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

feat(npg-apm): api keys configuration for APM #465

Merged
merged 15 commits into from
Apr 4, 2024
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
9 changes: 8 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CLOSURE_RETRY_INTERVAL=30
JWT_ECOMMERCE_SECRET=ODMzNUZBNTZENDg3NTYyREUyNDhGNDdCRUZDNzI3NDMzMzQwNTFEREZGQ0MyQzA5Mjc1RjY2NTQ1NDk5MDMxNzU5NDc0NUVFMTdDMDhGNzk4Q0Q3RENFMEJBODE1NURDREExNEY2Mzk4QzFEMTU0NTExNjUyMEExMzMwMTdDMDk

PERSONAL_DATA_VAULT_API_KEY=personal-data-vault-api-key
PERSONAL_DATA_VAULT_API_BASE_PATH="http://pagopa-pdv-mock:8092"
PERSONAL_DATA_VAULT_API_BASE_PATH="http://pagopa-pdv-mock:8092/tokenizer/v1/transaction/"


CHECKOUT_BASE_PATH=http://test.pagopa.it/
Expand All @@ -78,6 +78,12 @@ NPG_CONNECTION_TIMEOUT=10000
NPG_API_KEY="npg-api-key"
NPG_CARDS_PSP_LIST=CIPBITMM,BNLIITRR,BCITITMM,UNCRITMM,BPPIITRRXXX,PPAYITR1XXX
NPG_CARDS_PSP_KEYS={"CIPBITMM":"CIPBITMM-api-key","BNLIITRR":"BNLIITRR-api-key","BCITITMM":"BCITITMM-api-key","UNCRITMM":"UNCRITMM-api-key","BPPIITRRXXX":"BPPIITRRXXX-api-key","PPAYITR1XXX":"PPAYITR1XXX-api-key"}
NPG_PAYPAL_PSP_LIST=BCITITMM
NPG_PAYPAL_PSP_KEYS={"BCITITMM":"BCITITMM-api-key-paypal"}
NPG_BANCOMATPAY_PSP_LIST=BCITITMM
NPG_BANCOMATPAY_PSP_KEYS={"BCITITMM":"BCITITMM-api-key-bancomatpay"}
NPG_MYBANK_PSP_LIST=BCITITMM
NPG_MYBANK_PSP_KEYS={"BCITITMM":"BCITITMM-api-key-mybank"}
TRANSACTION_DOCUMENT_TTL=600
ECOMMERCE_EVENT_VERSION=V2

Expand All @@ -97,3 +103,4 @@ NODE_FORWARDER_URL=http://localhost:8096
REDIRECT_URL_MAPPING={'REDIRECT-RBPR':'http://localhost:8096/redirections'}
NODE_FORWARDER_READ_TIMEOUT=10000
NODE_FORWARDER_CONNECTION_TIMEOUT=10000
NPG_AUTHORIZATION_REQUEST_TIMEOUT_SECONDS=600
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ These are all environment variables needed by the application:
| NODE_FORWARDER_CONNECTION_TIMEOUT | | Node forwarder request connection timeout | number | |
| TRANSACTIONS_AUTHORIZATION_REQUESTED_QUEUE_NAME | | Name of the queue for transaction payment gateway polling for authorization requested transactions | string | |
| NPG_AUTHORIZATION_REQUEST_TIMEOUT_SECONDS | | Timeout for npg authorization state query | number | |
| NPG_PAYPAL_PSP_KEYS | | Secret structure that holds psp - api keys association for authorization request used for APM PAYPAL payment method | string | |
| NPG_PAYPAL_PSP_LIST | | List of all psp ids that are expected to be found into the NPG_PAYPAL_PSP_KEYS configuration (used for configuration cross validation) | string | |
| NPG_BANCOMATPAY_PSP_KEYS | | Secret structure that holds psp - api keys association for authorization request used for APM Bancomat pay payment method | string | |
| NPG_BANCOMATPAY_PSP_LIST | | List of all psp ids that are expected to be found into the NPG_BANCOMATPAY_PSP_KEYS configuration (used for configuration cross validation) | string | |
| NPG_MYBANK_PSP_KEYS | | Secret structure that holds psp - api keys association for authorization request used for APM My bank payment method | string | |
| NPG_MYBANK_PSP_LIST | | List of all psp ids that are expected to be found into the NPG_MYBANK_PSP_LIST configuration (used for configuration cross validation) | string | |

An example configuration of these environment variables is in the `.env.example` file.

Expand Down
8 changes: 7 additions & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ microservice-chart:
NPG_URI: "https://stg-ta.nexigroup.com/api/phoenix-0.0"
NPG_READ_TIMEOUT: "10000"
NPG_CONNECTION_TIMEOUT: "10000"
NPG_CARDS_PSP_LIST: "BCITITMM,CIPBITMM,BIC36019,UNCRITMM,BPPIITRRXXX,PPAYITR1XXX"
NPG_CARDS_PSP_LIST: "BCITITMM,CIPBITMM,BIC36019,UNCRITMM,BPPIITRRXXX,PPAYITR1XXX,BNLIITRR"
NPG_PAYPAL_PSP_LIST: "BCITITMM"
NPG_MYBANK_PSP_LIST: "BCITITMM"
NPG_BANCOMATPAY_PSP_LIST: "BCITITMM"
NPG_AUTHORIZATION_REQUEST_TIMEOUT_SECONDS: "60"
TRANSACTION_DOCUMENT_TTL: "600"
CHECKOUT_BASE_PATH: "https://dev.checkout.pagopa.it"
Expand Down Expand Up @@ -162,6 +165,9 @@ microservice-chart:
JWT_NPG_NOTIFICATION_SECRET: npg-notification-signing-key
NODE_FORWARDER_API_KEY: node-forwarder-api-key
REDIRECT_URL_MAPPING: redirect-url-mapping
NPG_PAYPAL_PSP_KEYS: npg-paypal-psp-keys
NPG_BANCOMATPAY_PSP_KEYS: npg-bancomatpay-psp-keys
NPG_MYBANK_PSP_KEYS: npg-mybank-psp-keys
keyvault:
name: "pagopa-d-ecommerce-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
Expand Down
6 changes: 6 additions & 0 deletions helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ microservice-chart:
NPG_READ_TIMEOUT: "10000"
NPG_CONNECTION_TIMEOUT: "10000"
NPG_CARDS_PSP_LIST: "BCITITMM,CIPBITMM,BIC36019,UNCRITMM,BPPIITRRXXX,PPAYITR1XXX"
NPG_PAYPAL_PSP_LIST: ""
NPG_MYBANK_PSP_LIST: ""
NPG_BANCOMATPAY_PSP_LIST: ""
NPG_AUTHORIZATION_REQUEST_TIMEOUT_SECONDS: "60"
TRANSACTION_DOCUMENT_TTL: "600"
CHECKOUT_BASE_PATH: "https://checkout.pagopa.it"
Expand Down Expand Up @@ -186,6 +189,9 @@ microservice-chart:
JWT_NPG_NOTIFICATION_SECRET: npg-notification-signing-key
NODE_FORWARDER_API_KEY: node-forwarder-api-key
REDIRECT_URL_MAPPING: redirect-url-mapping
NPG_PAYPAL_PSP_KEYS: npg-paypal-psp-keys
NPG_BANCOMATPAY_PSP_KEYS: npg-bancomatpay-psp-keys
NPG_MYBANK_PSP_KEYS: npg-mybank-psp-keys
keyvault:
name: "pagopa-p-ecommerce-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
Expand Down
8 changes: 7 additions & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ microservice-chart:
NPG_URI: "https://stg-ta.nexigroup.com/api/phoenix-0.0"
NPG_READ_TIMEOUT: "10000"
NPG_CONNECTION_TIMEOUT: "10000"
NPG_CARDS_PSP_LIST: "" #TODO to be filled with psp id list that are expected to be present into psp api keys configuration
NPG_CARDS_PSP_LIST: "BCITITMM,CIPBITMM,BIC36019,UNCRITMM,BPPIITRRXXX,PPAYITR1XXX,BNLIITRR"
NPG_PAYPAL_PSP_LIST: "BCITITMM"
NPG_MYBANK_PSP_LIST: "BCITITMM"
NPG_BANCOMATPAY_PSP_LIST: "BCITITMM"
NPG_AUTHORIZATION_REQUEST_TIMEOUT_SECONDS: "60"
TRANSACTION_DOCUMENT_TTL: "600"
CHECKOUT_BASE_PATH: "https://uat.checkout.pagopa.it"
Expand Down Expand Up @@ -180,6 +183,9 @@ microservice-chart:
JWT_NPG_NOTIFICATION_SECRET: npg-notification-signing-key
NODE_FORWARDER_API_KEY: node-forwarder-api-key
REDIRECT_URL_MAPPING: redirect-url-mapping
NPG_PAYPAL_PSP_KEYS: npg-paypal-psp-keys
NPG_BANCOMATPAY_PSP_KEYS: npg-bancomatpay-psp-keys
NPG_MYBANK_PSP_KEYS: npg-mybank-psp-keys
keyvault:
name: "pagopa-u-ecommerce-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<java.version>17</java.version>
<spring-cloud-azure.version>4.0.0</spring-cloud-azure.version>
<jacoco.version>0.8.8</jacoco.version>
<pagopa-ecommerce-commons.version>1.10.2</pagopa-ecommerce-commons.version>
<pagopa-ecommerce-commons.version>1.11.0</pagopa-ecommerce-commons.version>
<spotless.version>2.28.0</spotless.version>
<ecs-logging-version>1.5.0</ecs-logging-version>
<mock-web-server.version>4.11.0</mock-web-server.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import it.pagopa.ecommerce.commons.generated.npg.v1.dto.StateResponseDto;
import it.pagopa.ecommerce.commons.generated.npg.v1.dto.WorkflowStateDto;
import it.pagopa.ecommerce.commons.utils.JwtTokenUtils;
import it.pagopa.ecommerce.commons.utils.NpgPspApiKeysConfig;
import it.pagopa.ecommerce.commons.utils.NpgApiKeyConfiguration;
import it.pagopa.ecommerce.commons.utils.UniqueIdUtils;
import it.pagopa.generated.ecommerce.gateway.v1.api.VposInternalApi;
import it.pagopa.generated.ecommerce.gateway.v1.api.XPayInternalApi;
Expand Down Expand Up @@ -74,9 +74,7 @@ public class PaymentGatewayClient {

private final NpgSessionUrlConfig npgSessionUrlConfig;

private final NpgPspApiKeysConfig npgPspApiKeysConfig;
private final UniqueIdUtils uniqueIdUtils;
private final String npgDefaultApiKey;
private final SecretKey npgNotificationSigningKey;
private final int npgJwtKeyValidityTime;
private final SecretKey ecommerceSigningKey;
Expand All @@ -96,6 +94,7 @@ public class PaymentGatewayClient {
RedirectPaymentMethodId.RBPS,
"SCRIGNO Internet Banking"
);
private final NpgApiKeyConfiguration npgApiKeyConfiguration;

public enum RedirectPaymentMethodId {
RBPR,
Expand Down Expand Up @@ -127,33 +126,31 @@ public PaymentGatewayClient(
UUIDUtils uuidUtils,
ConfidentialMailUtils confidentialMailUtils,
NpgClient npgClient,
NpgPspApiKeysConfig npgPspApiKeysConfig,
NpgSessionUrlConfig npgSessionUrlConfig,
UniqueIdUtils uniqueIdUtils,
@Value("${npg.client.apiKey}") String npgDefaultApiKey,
SecretKey npgNotificationSigningKey,
@Value("${npg.notification.jwt.validity.time}") int npgJwtKeyValidityTime,
SecretKey ecommerceSigningKey,
@Value("${payment.token.validity}") int jwtEcommerceValidityTimeInSeconds,
NodeForwarderClient<RedirectUrlRequestDto, RedirectUrlResponseDto> nodeForwarderRedirectApiClient,
Map<String, URI> redirectBeApiCallUriMap
Map<String, URI> redirectBeApiCallUriMap,
NpgApiKeyConfiguration npgApiKeyConfiguration
) {
this.paymentTransactionGatewayXPayWebClient = paymentTransactionGatewayXPayWebClient;
this.creditCardInternalApiClient = creditCardInternalApiClient;
this.objectMapper = objectMapper;
this.uuidUtils = uuidUtils;
this.confidentialMailUtils = confidentialMailUtils;
this.npgClient = npgClient;
this.npgPspApiKeysConfig = npgPspApiKeysConfig;
this.npgSessionUrlConfig = npgSessionUrlConfig;
this.uniqueIdUtils = uniqueIdUtils;
this.npgDefaultApiKey = npgDefaultApiKey;
this.npgNotificationSigningKey = npgNotificationSigningKey;
this.npgJwtKeyValidityTime = npgJwtKeyValidityTime;
this.nodeForwarderRedirectApiClient = nodeForwarderRedirectApiClient;
this.redirectBeApiCallUriMap = redirectBeApiCallUriMap;
this.ecommerceSigningKey = ecommerceSigningKey;
this.jwtEcommerceValidityTimeInSeconds = jwtEcommerceValidityTimeInSeconds;
this.npgApiKeyConfiguration = npgApiKeyConfiguration;
}

public Mono<XPayAuthResponseEntityDto> requestXPayAuthorization(AuthorizationRequestData authorizationData) {
Expand Down Expand Up @@ -340,11 +337,14 @@ private Mono<Tuple2<String, FieldsDto>> requestNpgBuildSession(
/*
* FIXME: here we are using the same api key used for CARDS but they have to
* been differentiated for each payment methods. This issue is tracked with Jira
* task CHK-2265
* task CHK-2265 and will be fixed in CHK-2686 implementation
*/
Either<NpgApiKeyMissingPspRequestedException, String> buildApiKey = isApmPayment
? npgPspApiKeysConfig.get(authorizationData.pspId())
: Either.right(npgDefaultApiKey);
Either<NpgApiKeyConfigurationException, String> buildApiKey = isApmPayment
? npgApiKeyConfiguration.getApiKeyForPaymentMethod(
NpgClient.PaymentMethod.CARDS,
authorizationData.pspId()
)
: Either.right(npgApiKeyConfiguration.getDefaultApiKey());
return buildApiKey.fold(
Mono::error,
apiKey -> {
Expand Down Expand Up @@ -488,7 +488,8 @@ public Mono<StateResponseDto> requestNpgCardsAuthorization(
)
);
}
final var pspNpgApiKey = npgPspApiKeysConfig.get(authorizationData.pspId());
final var pspNpgApiKey = npgApiKeyConfiguration
.getApiKeyForPaymentMethod(NpgClient.PaymentMethod.CARDS, authorizationData.pspId());
return pspNpgApiKey.fold(
Mono::error,
apiKey -> npgClient.confirmPayment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import it.pagopa.ecommerce.commons.client.NpgClient;
import it.pagopa.ecommerce.commons.utils.NpgApiKeyConfiguration;
import it.pagopa.ecommerce.commons.utils.NpgPspApiKeysConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -29,7 +30,6 @@ public class NpgPspApiKeysConfigBuilder {
* @param apiKeys - the secret api keys configuration json
* @return the parsed map
*/
@Qualifier("npgCardsApiKeys")
@Bean
public it.pagopa.ecommerce.commons.utils.NpgPspApiKeysConfig npgCardsApiKeys(
@Value(
Expand All @@ -38,11 +38,114 @@ public it.pagopa.ecommerce.commons.utils.NpgPspApiKeysConfig npgCardsApiKeys(
@Value(
"${npg.authorization.cards.pspList}"
) Set<String> pspToHandle
) {
return parseApiKeysMap(
apiKeys,
pspToHandle,
NpgClient.PaymentMethod.CARDS
);
}

/**
* Return a map where valued with each psp id - api keys entries
*
* @param apiKeys - the secret api keys configuration json
* @return the parsed map
*/
@Bean
public it.pagopa.ecommerce.commons.utils.NpgPspApiKeysConfig npgPaypalApiKeys(
@Value(
"${npg.authorization.paypal.keys}"
) String apiKeys,
@Value(
"${npg.authorization.paypal.pspList}"
) Set<String> pspToHandle
) {
return parseApiKeysMap(
apiKeys,
pspToHandle,
NpgClient.PaymentMethod.PAYPAL
);
}

/**
* Return a map where valued with each psp id - api keys entries
*
* @param apiKeys - the secret api keys configuration json
* @return the parsed map
*/
@Bean
public it.pagopa.ecommerce.commons.utils.NpgPspApiKeysConfig npgMyBankApiKeys(
@Value(
"${npg.authorization.mybank.keys}"
) String apiKeys,
@Value(
"${npg.authorization.mybank.pspList}"
) Set<String> pspToHandle
) {
return parseApiKeysMap(
apiKeys,
pspToHandle,
NpgClient.PaymentMethod.MYBANK
);
}

/**
* Return a map where valued with each psp id - api keys entries
*
* @param apiKeys - the secret api keys configuration json
* @return the parsed map
*/
@Bean
public it.pagopa.ecommerce.commons.utils.NpgPspApiKeysConfig npgBancomatpayApiKeys(
@Value(
"${npg.authorization.bancomatpay.keys}"
) String apiKeys,
@Value(
"${npg.authorization.bancomatpay.pspList}"
) Set<String> pspToHandle
) {
return parseApiKeysMap(
apiKeys,
pspToHandle,
NpgClient.PaymentMethod.BANCOMATPAY
);
}

@Bean
public NpgApiKeyConfiguration npgApiKeyConfiguration(
NpgPspApiKeysConfig npgCardsApiKeys,
NpgPspApiKeysConfig npgBancomatpayApiKeys,
NpgPspApiKeysConfig npgMyBankApiKeys,
NpgPspApiKeysConfig npgPaypalApiKeys,
@Value("${npg.client.apiKey}") String defaultApiKey
) {
return new NpgApiKeyConfiguration.Builder()
.setDefaultApiKey(defaultApiKey)
.withMethodPspMapping(NpgClient.PaymentMethod.CARDS, npgCardsApiKeys)
.withMethodPspMapping(NpgClient.PaymentMethod.BANCOMATPAY, npgBancomatpayApiKeys)
.withMethodPspMapping(NpgClient.PaymentMethod.MYBANK, npgMyBankApiKeys)
.withMethodPspMapping(NpgClient.PaymentMethod.PAYPAL, npgPaypalApiKeys)
.build();
}

/**
* Return a map where valued with each psp id - api keys entries
*
* @param apiKeys - the secret api keys configuration json
* @return the parsed map
*/
private it.pagopa.ecommerce.commons.utils.NpgPspApiKeysConfig parseApiKeysMap(

String apiKeys,
Set<String> pspToHandle,
NpgClient.PaymentMethod paymentMethod

) {
return it.pagopa.ecommerce.commons.utils.NpgPspApiKeysConfig.parseApiKeyConfiguration(
apiKeys,
pspToHandle,
NpgClient.PaymentMethod.CARDS,
paymentMethod,
objectMapper
)
.fold(exception -> {
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ npg.connectionTimeout=${NPG_CONNECTION_TIMEOUT}
npg.client.apiKey=${NPG_API_KEY}
npg.authorization.cards.keys=${NPG_CARDS_PSP_KEYS}
npg.authorization.cards.pspList=${NPG_CARDS_PSP_LIST}
npg.authorization.paypal.keys=${NPG_PAYPAL_PSP_KEYS}
npg.authorization.paypal.pspList=${NPG_PAYPAL_PSP_LIST}
npg.authorization.bancomatpay.keys=${NPG_BANCOMATPAY_PSP_KEYS}
npg.authorization.bancomatpay.pspList=${NPG_BANCOMATPAY_PSP_LIST}
npg.authorization.mybank.keys=${NPG_MYBANK_PSP_KEYS}
npg.authorization.mybank.pspList=${NPG_MYBANK_PSP_LIST}
npg.authorization.request.timeout.seconds=${NPG_AUTHORIZATION_REQUEST_TIMEOUT_SECONDS}
ecommerce.event.version=${ECOMMERCE_EVENT_VERSION}

Expand Down
Loading
Loading