diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 7bbb6eb7..3b29021b 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -8,6 +8,9 @@ services:
build:
dockerfile: Dockerfile
context: ../
+ environment:
+ BRAND_LOGO_MAP: '{"MASTERCARD":"assets/mastercard.png","VISA":"assets/visa.png","AMEX":"assets/amex.png","MAESTRO":"assets/maestro.png","JCB":"assets/jcb.png","OTHER":"","DINERS":"assets/diners.png","DISCOVER":"assets/discover.png","UNIONPAY":"assets/unionpay.png"}'
+ PSP_INFO_MAP: '{"60000000001":{"logo":"assets/nexi-logo.png","name":"Nexi","companyName":"Nexi Payments S.p.A.","address":"Corso Sempione","buildingNumber":"55","postalCode":"20149","city":"Milano","province":"MI","fee":{"amount":"2,00"}}}'
env_file:
- ./.env
ports:
diff --git a/helm/Chart.yaml b/helm/Chart.yaml
index b6a0d1b3..e8698b00 100644
--- a/helm/Chart.yaml
+++ b/helm/Chart.yaml
@@ -2,8 +2,8 @@ apiVersion: v2
name: pagopareceiptpdfgenerator
description: Microservice description
type: application
-version: 0.76.0
-appVersion: 1.3.2
+version: 0.83.0
+appVersion: 1.3.8-PRDP-145-feat-add-logo-management
dependencies:
- name: microservice-chart
version: 2.4.0
diff --git a/helm/templates/configmaps.yaml b/helm/templates/configmaps.yaml
new file mode 100644
index 00000000..9fd6fbd8
--- /dev/null
+++ b/helm/templates/configmaps.yaml
@@ -0,0 +1,10 @@
+kind: ConfigMap
+apiVersion: v1
+metadata:
+ name: template-maps
+ namespace: receipts
+data:
+ brand-logo-map: |
+ {"MASTERCARD":"assets/mastercard.png","VISA":"assets/visa.png","AMEX":"https://assets.cdn.platform.pagopa.it/payment-methods/amex.png","MAESTRO":"assets/maestro.png","JCB":"assets/jcb.png","OTHER":"","DINERS":"assets/diners.png","DISCOVER":"assets/discover.png","UNIONPAY":"assets/unionpay.png"}
+ psp-info-map: |
+ {"CIPBITMM":{"logo":"https://assets.cdn.io.italia.it/logos/abi/32875.png","name":"Nexi","companyName":"Nexi Payments S.p.A.","address":"Corso Sempione","buildingNumber":"55","postalCode":"20149","city":"Milano","province":"MI","fee":{"amount":"2,00"}}}
\ No newline at end of file
diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml
index 71a7552e..2a6c7949 100644
--- a/helm/values-dev.yaml
+++ b/helm/values-dev.yaml
@@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-generator
- tag: "1.3.2"
+ tag: "1.3.8-PRDP-145-feat-add-logo-management"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
@@ -100,6 +100,10 @@ microservice-chart:
OTEL_LOGS_EXPORTER: none
OTEL_TRACES_SAMPLER: "always_on"
AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx1024m -XX:+UseG1GC"
+ envConfigMapExternals:
+ template-maps:
+ PSP_INFO_MAP: psp-info-map
+ BRAND_LOGO_MAP: brand-logo-map
envFieldRef:
APP_NAME: "metadata.labels['app.kubernetes.io/instance']"
APP_VERSION: "metadata.labels['app.kubernetes.io/version']"
diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml
index f119272e..f7808967 100644
--- a/helm/values-prod.yaml
+++ b/helm/values-prod.yaml
@@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-generator
- tag: "1.3.2"
+ tag: "1.3.8-PRDP-145-feat-add-logo-management"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
@@ -54,14 +54,14 @@ microservice-chart:
allowPrivilegeEscalation: false
resources:
requests:
- memory: "1512Mi"
- cpu: "0.75"
+ memory: "1024Mi"
+ cpu: "0.40"
limits:
memory: "1512Mi"
cpu: "0.75"
autoscaling:
enable: true
- minReplica: 2
+ minReplica: 3
maxReplica: 10
pollingInterval: 10 # seconds
cooldownPeriod: 50 # seconds
@@ -81,15 +81,15 @@ microservice-chart:
ENV: "prod"
WEBSITE_SITE_NAME: "pagopareceiptpdfgenerator" # required to show cloud role name in application insights
FUNCTIONS_WORKER_RUNTIME: "java"
- RECEIPT_QUEUE_TOPIC: 'pagopa-p-weu-receipts-queue-receipt-waiting-4-gen'
+ RECEIPT_QUEUE_TOPIC: "pagopa-p-weu-receipts-queue-receipt-waiting-4-gen"
RECEIPT_QUEUE_TOPIC_POISON: "pagopa-d-weu-receipts-queue-receipt-waiting-4-gen-poison"
- COSMOS_RECEIPT_QUEUE_MAX_RETRY: '5'
- PDF_ENGINE_ENDPOINT: 'https://api.prod.platform.pagopa.it/shared/pdf-engine/v1/generate-pdf'
- COSMOS_RECEIPT_SERVICE_ENDPOINT: 'https://pagopa-p-weu-receipts-ds-cosmos-account.documents.azure.com:443/'
- COSMOS_RECEIPT_DB_NAME: 'db'
- COSMOS_RECEIPT_CONTAINER_NAME: 'receipts'
- BLOB_STORAGE_ACCOUNT_ENDPOINT: 'https://pagopapweureceiptsfnsa.blob.core.windows.net'
- BLOB_STORAGE_CONTAINER_NAME: 'pagopa-p-weu-receipts-azure-blob-receipt-st-attach'
+ COSMOS_RECEIPT_QUEUE_MAX_RETRY: "5"
+ PDF_ENGINE_ENDPOINT: "https://api.prod.platform.pagopa.it/shared/pdf-engine/v1/generate-pdf"
+ COSMOS_RECEIPT_SERVICE_ENDPOINT: "https://pagopa-p-weu-receipts-ds-cosmos-account.documents.azure.com:443/"
+ COSMOS_RECEIPT_DB_NAME: "db"
+ COSMOS_RECEIPT_CONTAINER_NAME: "receipts"
+ BLOB_STORAGE_ACCOUNT_ENDPOINT: "https://pagopapweureceiptsfnsa.blob.core.windows.net"
+ BLOB_STORAGE_CONTAINER_NAME: "pagopa-p-weu-receipts-azure-blob-receipt-st-attach"
WORKING_DIRECTORY_PATH: "/temp"
ENABLE_ECS_CONSOLE: "true"
CONSOLE_LOG_THRESHOLD: "DEBUG"
@@ -97,19 +97,23 @@ microservice-chart:
CONSOLE_LOG_CHARSET: "UTF-8"
OTEL_RESOURCE_ATTRIBUTES: "service.name=pagopareceiptpdfgeneratorotl,deployment.environment=prod"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317"
- OTEL_LOGS_EXPORTER: none
+ OTEL_LOGS_EXPORTER: "none"
OTEL_TRACES_SAMPLER: "always_on"
AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx1024m -XX:+UseG1GC"
+ envConfigMapExternals:
+ template-maps:
+ PSP_INFO_MAP: psp-info-map
+ BRAND_LOGO_MAP: brand-logo-map
envFieldRef:
APP_NAME: "metadata.labels['app.kubernetes.io/instance']"
APP_VERSION: "metadata.labels['app.kubernetes.io/version']"
envSecret:
- APPLICATIONINSIGHTS_CONNECTION_STRING: 'ai-p-connection-string'
- RECEIPTS_STORAGE_CONN_STRING: 'pdf-blob-storage-p-connection-string'
- COSMOS_RECEIPTS_CONN_STRING: 'cosmos-receipt-p-connection-string'
- OCP_APIM_SUBSCRIPTION_KEY: 'shared-apim-p-subscription-key'
+ APPLICATIONINSIGHTS_CONNECTION_STRING: "ai-p-connection-string"
+ RECEIPTS_STORAGE_CONN_STRING: "pdf-blob-storage-p-connection-string"
+ COSMOS_RECEIPTS_CONN_STRING: "cosmos-receipt-p-connection-string"
+ OCP_APIM_SUBSCRIPTION_KEY: "shared-apim-p-subscription-key"
COSMOS_RECEIPT_KEY: "cosmos-receipt-pkey"
- OTEL_EXPORTER_OTLP_HEADERS: 'elastic-otl-secret-token'
+ OTEL_EXPORTER_OTLP_HEADERS: "elastic-otl-secret-token"
keyvault:
name: "pagopa-p-receipts-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml
index 1ad2b8d4..d7add019 100644
--- a/helm/values-uat.yaml
+++ b/helm/values-uat.yaml
@@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-generator
- tag: "1.3.2"
+ tag: "1.3.8-PRDP-145-feat-add-logo-management"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
@@ -54,8 +54,8 @@ microservice-chart:
allowPrivilegeEscalation: false
resources:
requests:
- memory: "1512Mi"
- cpu: "0.75"
+ memory: "1024Mi"
+ cpu: "0.40"
limits:
memory: "1512Mi"
cpu: "0.75"
@@ -81,15 +81,15 @@ microservice-chart:
ENV: "uat"
WEBSITE_SITE_NAME: "pagopareceiptpdfgenerator" # required to show cloud role name in application insights
FUNCTIONS_WORKER_RUNTIME: "java"
- RECEIPT_QUEUE_TOPIC: 'pagopa-u-weu-receipts-queue-receipt-waiting-4-gen'
+ RECEIPT_QUEUE_TOPIC: "pagopa-u-weu-receipts-queue-receipt-waiting-4-gen"
RECEIPT_QUEUE_TOPIC_POISON: "pagopa-u-weu-receipts-queue-receipt-waiting-4-gen-poison"
- COSMOS_RECEIPT_QUEUE_MAX_RETRY: '5'
- PDF_ENGINE_ENDPOINT: 'https://api.uat.platform.pagopa.it/shared/pdf-engine/v1/generate-pdf'
- COSMOS_RECEIPT_SERVICE_ENDPOINT: 'https://pagopa-u-weu-receipts-ds-cosmos-account.documents.azure.com:443/'
- COSMOS_RECEIPT_DB_NAME: 'db'
- COSMOS_RECEIPT_CONTAINER_NAME: 'receipts'
- BLOB_STORAGE_ACCOUNT_ENDPOINT: 'https://pagopauweureceiptsfnsa.blob.core.windows.net'
- BLOB_STORAGE_CONTAINER_NAME: 'pagopa-u-weu-receipts-azure-blob-receipt-st-attach'
+ COSMOS_RECEIPT_QUEUE_MAX_RETRY: "5"
+ PDF_ENGINE_ENDPOINT: "https://api.uat.platform.pagopa.it/shared/pdf-engine/v1/generate-pdf"
+ COSMOS_RECEIPT_SERVICE_ENDPOINT: "https://pagopa-u-weu-receipts-ds-cosmos-account.documents.azure.com:443/"
+ COSMOS_RECEIPT_DB_NAME: "db"
+ COSMOS_RECEIPT_CONTAINER_NAME: "receipts"
+ BLOB_STORAGE_ACCOUNT_ENDPOINT: "https://pagopauweureceiptsfnsa.blob.core.windows.net"
+ BLOB_STORAGE_CONTAINER_NAME: "pagopa-u-weu-receipts-azure-blob-receipt-st-attach"
WORKING_DIRECTORY_PATH: "/temp"
ENABLE_ECS_CONSOLE: "true"
CONSOLE_LOG_THRESHOLD: "DEBUG"
@@ -100,16 +100,20 @@ microservice-chart:
OTEL_LOGS_EXPORTER: "none"
OTEL_TRACES_SAMPLER: "always_on"
AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx1024m -XX:+UseG1GC"
+ envConfigMapExternals:
+ template-maps:
+ PSP_INFO_MAP: psp-info-map
+ BRAND_LOGO_MAP: brand-logo-map
envFieldRef:
APP_NAME: "metadata.labels['app.kubernetes.io/instance']"
APP_VERSION: "metadata.labels['app.kubernetes.io/version']"
envSecret:
- APPLICATIONINSIGHTS_CONNECTION_STRING: 'ai-u-connection-string'
+ APPLICATIONINSIGHTS_CONNECTION_STRING: "ai-u-connection-string"
RECEIPTS_STORAGE_CONN_STRING: "receipts-storage-account-connection-string"
COSMOS_RECEIPTS_CONN_STRING: "cosmos-receipt-connection-string"
- OCP_APIM_SUBSCRIPTION_KEY: 'shared-apim-u-subscription-key'
+ OCP_APIM_SUBSCRIPTION_KEY: "shared-apim-u-subscription-key"
COSMOS_RECEIPT_KEY: "cosmos-receipt-pkey"
- OTEL_EXPORTER_OTLP_HEADERS: 'elastic-otl-secret-token'
+ OTEL_EXPORTER_OTLP_HEADERS: "elastic-otl-secret-token"
keyvault:
name: "pagopa-u-receipts-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
diff --git a/host.json b/host.json
index fda7e648..b01eb7f0 100644
--- a/host.json
+++ b/host.json
@@ -11,9 +11,9 @@
"queues": {
"maxPollingInterval": "00:00:02",
"visibilityTimeout" : "00:00:30",
- "batchSize": 8,
+ "batchSize": 12,
"maxDequeueCount": 5,
- "newBatchThreshold": 4,
+ "newBatchThreshold": 6,
"messageEncoding": "none"
}
},
diff --git a/pom.xml b/pom.xml
index 50ebf7bc..d8c0019b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
it.gov.pagopa.receipt
receipt-pdf-generator
- 1.3.2
+ 1.3.8-PRDP-145-feat-add-logo-management
jar
pagopa-receipt-pdf-generator
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/exception/PdfJsonMappingException.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/exception/PdfJsonMappingException.java
new file mode 100644
index 00000000..50d291f5
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/exception/PdfJsonMappingException.java
@@ -0,0 +1,8 @@
+package it.gov.pagopa.receipt.pdf.generator.exception;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+public class PdfJsonMappingException extends RuntimeException {
+ public PdfJsonMappingException(JsonProcessingException e) {
+ }
+}
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/PSP.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/PSP.java
index c0a2b22a..5edc8582 100644
--- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/PSP.java
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/PSP.java
@@ -13,5 +13,12 @@ public class PSP {
private String name;
private PSPFee fee;
+ private String companyName;
+ private String logo;
+ private String address;
+ private String buildingNumber;
+ private String postalCode;
+ private String city;
+ private String province;
}
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java
index 42e09177..c10549e6 100644
--- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java
@@ -220,12 +220,7 @@ private ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTempl
.id(BizEventToPdfMapper.getId(bizEvent))
.timestamp(BizEventToPdfMapper.getTimestamp(bizEvent))
.amount(BizEventToPdfMapper.getAmount(bizEvent))
- .psp(PSP.builder()
- .name(BizEventToPdfMapper.getPspName(bizEvent))
- .fee(PSPFee.builder()
- .amount(BizEventToPdfMapper.getPspFee(bizEvent))
- .build())
- .build())
+ .psp(BizEventToPdfMapper.getPsp(bizEvent))
.rrn(BizEventToPdfMapper.getRnn(bizEvent))
.paymentMethod(PaymentMethod.builder()
.name(BizEventToPdfMapper.getPaymentMethodName(bizEvent))
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/utils/BizEventToPdfMapper.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/utils/BizEventToPdfMapper.java
index dd678d08..987cdad3 100644
--- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/utils/BizEventToPdfMapper.java
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/utils/BizEventToPdfMapper.java
@@ -1,7 +1,13 @@
package it.gov.pagopa.receipt.pdf.generator.utils;
+import com.fasterxml.jackson.core.JsonProcessingException;
import it.gov.pagopa.receipt.pdf.generator.entity.event.BizEvent;
+import it.gov.pagopa.receipt.pdf.generator.exception.PdfJsonMappingException;
+import it.gov.pagopa.receipt.pdf.generator.model.template.PSP;
+import it.gov.pagopa.receipt.pdf.generator.model.template.PSPFee;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.time.LocalDateTime;
@@ -17,200 +23,226 @@ public class BizEventToPdfMapper {
/**
* Hide from public usage.
*/
+
+ private static final Map brandLogoMap;
+ private static final Map pspMap;
+
+ static {
+ try {
+ brandLogoMap = ObjectMapperUtils.mapString(System.getenv().get("BRAND_LOGO_MAP"), Map.class);
+ } catch (JsonProcessingException e) {
+ throw new PdfJsonMappingException(e);
+ }
+
+ }
+
+ static {
+ try {
+ pspMap = ObjectMapperUtils.mapString(System.getenv().get("PSP_INFO_MAP"), Map.class);
+ } catch (JsonProcessingException e) {
+ throw new PdfJsonMappingException(e);
+ }
+ }
+
private BizEventToPdfMapper() {
}
public static String getId(BizEvent event) {
- if (
- event.getTransactionDetails() != null &&
- event.getTransactionDetails().getTransaction() != null &&
- event.getTransactionDetails().getTransaction().getIdTransaction() != 0L
- ) {
+ if (event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getTransaction() != null &&
+ event.getTransactionDetails().getTransaction().getIdTransaction() != 0L) {
return String.valueOf(event.getTransactionDetails().getTransaction().getIdTransaction());
}
- if (
- event.getPaymentInfo() != null
- ) {
- return event.getPaymentInfo().getPaymentToken() != null ? event.getPaymentInfo().getPaymentToken() : event.getPaymentInfo().getIUR();
+ if (event.getPaymentInfo() != null) {
+ return event.getPaymentInfo().getPaymentToken() != null ? event.getPaymentInfo().getPaymentToken()
+ : event.getPaymentInfo().getIUR();
}
return null;
}
public static String getTimestamp(BizEvent event) {
- if(
- event.getTransactionDetails() != null &&
- event.getTransactionDetails().getTransaction() != null &&
- event.getTransactionDetails().getTransaction().getCreationDate() != null
- ){
+ if (event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getTransaction() != null &&
+ event.getTransactionDetails().getTransaction().getCreationDate() != null) {
return dateFormat(event.getTransactionDetails().getTransaction().getCreationDate(), true);
}
return event.getPaymentInfo() != null ? dateFormat(event.getPaymentInfo().getPaymentDateTime(), false) : null;
}
- public static String getAmount(BizEvent event){
- if(
- event.getTransactionDetails() != null &&
- event.getTransactionDetails().getTransaction() != null &&
- event.getTransactionDetails().getTransaction().getAmount() != 0L
- ){
- //Amount in transactionDetails is defined in cents (es. 25500 not 255.00)
+ public static String getAmount(BizEvent event) {
+ if (event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getTransaction() != null &&
+ event.getTransactionDetails().getTransaction().getAmount() != 0L) {
+ // Amount in transactionDetails is defined in cents (es. 25500 not 255.00)
return currencyFormat(String.valueOf(event.getTransactionDetails().getTransaction().getAmount() / 100.00));
}
return event.getPaymentInfo() != null ? currencyFormat(event.getPaymentInfo().getAmount()) : null;
}
- public static String getPspName(BizEvent event){
- if(
- event.getTransactionDetails() != null &&
- event.getTransactionDetails().getTransaction() != null &&
- event.getTransactionDetails().getTransaction().getPsp() != null &&
- event.getTransactionDetails().getTransaction().getPsp().getBusinessName() != null
- ){
- return event.getTransactionDetails().getTransaction().getPsp().getBusinessName();
- }
-
- return event.getPsp() != null ? event.getPsp().getPsp() : null;
- }
-
- public static String getPspFee(BizEvent event){
- if(
- event.getTransactionDetails() != null &&
- event.getTransactionDetails().getTransaction() != null &&
- event.getTransactionDetails().getTransaction().getFee() != 0L
- ){
- //Fee in transactionDetails is defined in cents (es. 25500 not 255.00)
+ public static String getPspFee(BizEvent event) {
+ if (event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getTransaction() != null &&
+ event.getTransactionDetails().getTransaction().getFee() != 0L) {
+ // Fee in transactionDetails is defined in cents (es. 25500 not 255.00)
return currencyFormat(String.valueOf(event.getTransactionDetails().getTransaction().getFee() / 100.00));
}
return event.getPaymentInfo() != null ? currencyFormat(event.getPaymentInfo().getFee()) : null;
}
- public static String getRnn(BizEvent event){
- if(
- event.getTransactionDetails() != null &&
- event.getTransactionDetails().getTransaction() != null &&
- event.getTransactionDetails().getTransaction().getRrn() != null
- ){
+ public static String getRnn(BizEvent event) {
+ if (event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getTransaction() != null &&
+ event.getTransactionDetails().getTransaction().getRrn() != null) {
return event.getTransactionDetails().getTransaction().getRrn();
}
- if (
- event.getPaymentInfo() != null
- ) {
- return event.getPaymentInfo().getPaymentToken() != null ? event.getPaymentInfo().getPaymentToken() : event.getPaymentInfo().getIUR();
+ if (event.getPaymentInfo() != null) {
+ return event.getPaymentInfo().getPaymentToken() != null ? event.getPaymentInfo().getPaymentToken()
+ : event.getPaymentInfo().getIUR();
}
return null;
}
- public static String getAuthCode(BizEvent event){
- if(
- event.getTransactionDetails() != null &&
- event.getTransactionDetails().getTransaction() != null
- ){
+ public static String getAuthCode(BizEvent event) {
+ if (event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getTransaction() != null) {
return event.getTransactionDetails().getTransaction().getAuthorizationCode();
}
return null;
}
- public static String getPaymentMethodName(BizEvent event){
- if(
- event.getTransactionDetails() != null &&
- event.getTransactionDetails().getWallet() != null &&
- event.getTransactionDetails().getWallet().getInfo() != null
- ){
+ public static String getPaymentMethodName(BizEvent event) {
+ if (event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getWallet() != null &&
+ event.getTransactionDetails().getWallet().getInfo() != null) {
return event.getTransactionDetails().getWallet().getInfo().getBrand();
}
return null;
}
- public static String getPaymentMethodLogo(BizEvent event){
- //TODO analyse -> transactionDetails.wallet.info.brandLogo doesn't exist
+ public static String getPaymentMethodLogo(BizEvent event) {
+ // TODO analyse -> transactionDetails.wallet.info.brandLogo doesn't exist
+
+ if (event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getWallet() != null &&
+ event.getTransactionDetails().getWallet().getInfo() != null) {
+ return brandLogoMap.getOrDefault(
+ event.getTransactionDetails().getWallet()
+ .getInfo().getBrand(),
+ null);
+ }
return null;
}
- public static String getPaymentMethodAccountHolder(BizEvent event){
- if(
- event.getTransactionDetails() != null &&
- event.getTransactionDetails().getWallet() != null &&
- event.getTransactionDetails().getWallet().getInfo() != null &&
- event.getTransactionDetails().getWallet().getInfo().getHolder() != null
- ){
+ public static String getPaymentMethodAccountHolder(BizEvent event) {
+ if (event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getWallet() != null &&
+ event.getTransactionDetails().getWallet().getInfo() != null &&
+ event.getTransactionDetails().getWallet().getInfo().getHolder() != null) {
return event.getTransactionDetails().getWallet().getInfo().getHolder();
}
return event.getPayer() != null ? event.getPayer().getFullName() : null;
}
- public static String getUserMail(){
+ public static String getUserMail() {
return null;
}
- public static String getUserFullName(BizEvent event){
+ public static String getUserFullName(BizEvent event) {
return event.getPayer() != null ? event.getPayer().getFullName() : null;
}
- public static String getUserTaxCode(BizEvent event){
+ public static String getUserTaxCode(BizEvent event) {
return event.getPayer() != null ? event.getPayer().getEntityUniqueIdentifierValue() : null;
}
-
- public static String getRefNumberType(BizEvent event){
- if(
- event.getDebtorPosition() != null &&
- event.getDebtorPosition().getModelType().equals("2")
- ){
+ public static String getRefNumberType(BizEvent event) {
+ if (event.getDebtorPosition() != null &&
+ event.getDebtorPosition().getModelType() != null &&
+ event.getDebtorPosition().getModelType().equals("2")) {
return REF_TYPE_IUV;
}
return REF_TYPE_NOTICE;
}
- public static String getRefNumberValue(BizEvent event){
+ public static String getRefNumberValue(BizEvent event) {
return event.getDebtorPosition() != null ? event.getDebtorPosition().getIuv() : null;
}
- public static String getDebtorFullName(BizEvent event){
+ public static String getDebtorFullName(BizEvent event) {
return event.getDebtor() != null ? event.getDebtor().getFullName() : null;
}
- public static String getDebtorTaxCode(BizEvent event){
+ public static String getDebtorTaxCode(BizEvent event) {
return event.getDebtor() != null ? event.getDebtor().getEntityUniqueIdentifierValue() : null;
}
- public static String getPayeeName(BizEvent event){
+ public static String getPayeeName(BizEvent event) {
return event.getCreditor() != null ? event.getCreditor().getOfficeName() : null;
}
- public static String getPayeeTaxCode(BizEvent event){
+ public static String getPayeeTaxCode(BizEvent event) {
return event.getCreditor() != null ? event.getCreditor().getCompanyName() : null;
}
- public static String getItemSubject(BizEvent event){
+ public static String getItemSubject(BizEvent event) {
return event.getPaymentInfo() != null ? event.getPaymentInfo().getRemittanceInformation() : null;
}
- public static String getItemAmount(BizEvent event){
+ public static String getItemAmount(BizEvent event) {
return event.getPaymentInfo() != null ? currencyFormat(event.getPaymentInfo().getAmount()) : null;
}
- private static String currencyFormat(String value){
+ private static String currencyFormat(String value) {
BigDecimal valueToFormat = new BigDecimal(value);
NumberFormat numberFormat = NumberFormat.getInstance(Locale.ITALY);
return numberFormat.format(valueToFormat);
}
+ public static PSP getPsp(BizEvent event) {
+
+ if (event.getPsp() != null &&
+ event.getPsp().getIdPsp() != null &&
+ event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getTransaction() != null &&
+ event.getTransactionDetails().getTransaction().getPsp() != null) {
+ String name = event.getTransactionDetails().getTransaction().getPsp().getBusinessName();
+ LinkedHashMap info = (LinkedHashMap) pspMap
+ .getOrDefault(event.getPsp().getIdPsp(), new LinkedHashMap<>());
+ return PSP.builder()
+ .name(name)
+ .fee(PSPFee.builder()
+ .amount(getPspFee(event))
+ .build())
+ .companyName(info.get("companyName"))
+ .address(info.get("address"))
+ .city(info.get("city"))
+ .province(info.get("province"))
+ .buildingNumber(info.get("buildingNumber"))
+ .postalCode(info.get("postalCode"))
+ .logo(info.get("logo"))
+ .build();
+
+ }
+
+ return null;
+ }
+
private static String dateFormat(String date, boolean withTimeZone){
DateTimeFormatter simpleDateFormat = DateTimeFormatter.ofPattern("dd MMMM yyyy, HH:mm:ss").withLocale(Locale.ITALY);
- if(withTimeZone){
+ if (withTimeZone) {
return ZonedDateTime.parse(date).format(simpleDateFormat);
}
diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/generator/GenerateReceiptPdfTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/generator/GenerateReceiptPdfTest.java
index c1922dae..711cad75 100644
--- a/src/test/java/it/gov/pagopa/receipt/pdf/generator/GenerateReceiptPdfTest.java
+++ b/src/test/java/it/gov/pagopa/receipt/pdf/generator/GenerateReceiptPdfTest.java
@@ -15,15 +15,18 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.*;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
+import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariable;
+import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariables;
@ExtendWith(MockitoExtension.class)
class GenerateReceiptPdfTest {
- private static final String BIZ_EVENT_VALID_MESSAGE = "{\"id\":\"062-a330-4210-9c67-465b7d641aVS\",\"version\":\"2\",\"idPaymentManager\":null,\"complete\":\"false\",\"receiptId\":\"9a9bad2caf604b86a339476373c659b0\",\"missingInfo\":[\"idPaymentManager\",\"psp.pspPartitaIVA\",\"paymentInfo.primaryCiIncurredFee\",\"paymentInfo.idBundle\",\"paymentInfo.idCiBundle\",\"paymentInfo.metadata\"],\"debtorPosition\":{\"modelType\":\"2\",\"noticeNumber\":\"302119891614290410\",\"iuv\":\"02119891614290410\"},\"creditor\":{\"idPA\":\"66666666666\",\"idBrokerPA\":\"66666666666\",\"idStation\":\"66666666666_01\",\"companyName\":\"PA paolo\",\"officeName\":\"office PA\"},\"psp\":{\"idPsp\":\"60000000001\",\"idBrokerPsp\":\"60000000001\",\"idChannel\":\"60000000001_01\",\"psp\":\"PSP Paolo\",\"pspPartitaIVA\":null,\"pspFiscalCode\":\"CF60000000006\",\"channelDescription\":\"app\"},\"debtor\":{\"fullName\":\"John Doe\",\"entityUniqueIdentifierType\":\"F\",\"entityUniqueIdentifierValue\":\"JHNDOE00A01F205N\",\"streetName\":\"street\",\"civicNumber\":\"12\",\"postalCode\":\"89020\",\"city\":\"city\",\"stateProvinceRegion\":\"MI\",\"country\":\"IT\",\"eMail\":\"john.doe@test.it\"},\"payer\":{\"fullName\":\"John Doe\",\"entityUniqueIdentifierType\":\"F\",\"entityUniqueIdentifierValue\":\"JHNDOE00A01F205N\",\"streetName\":\"street\",\"civicNumber\":\"12\",\"postalCode\":\"89020\",\"city\":\"city\",\"stateProvinceRegion\":\"MI\",\"country\":\"IT\",\"eMail\":\"john.doe@test.it\"},\"paymentInfo\":{\"paymentDateTime\":\"2023-04-12T16:21:39.022486\",\"applicationDate\":\"2021-10-01\",\"transferDate\":\"2021-10-02\",\"dueDate\":\"2021-07-31\",\"paymentToken\":\"9a9bad2caf604b86a339476373c659b0\",\"amount\":\"7000\",\"fee\":\"200\",\"primaryCiIncurredFee\":null,\"idBundle\":null,\"idCiBundle\":null,\"totalNotice\":\"1\",\"paymentMethod\":\"creditCard\",\"touchpoint\":\"app\",\"remittanceInformation\":\"TARI 2021\",\"description\":\"TARI 2021\",\"metadata\":null},\"transferList\":[{\"idTransfer\":\"1\",\"fiscalCodePA\":\"77777777777\",\"companyName\":\"Pa Salvo\",\"amount\":\"7000\",\"transferCategory\":\"0101101IM\",\"remittanceInformation\":\"TARI Comune EC_TE\",\"metadata\":null,\"mbdattachment\":null,\"iban\":\"IT96R0123454321000000012345\"}],\"transactionDetails\":null,\"timestamp\":1686919660002,\"properties\":{},\"eventStatus\":\"DONE\",\"eventRetryEnrichmentCount\":0,\"eventTriggeredBySchedule\":false,\"eventErrorMessage\":null}";
+ private static final String BIZ_EVENT_VALID_MESSAGE = "{\"id\":\"variant062-a330-4210-9c67-465b7d641aVS\",\"version\":\"2\",\"idPaymentManager\":null,\"complete\":\"false\",\"receiptId\":\"9a9bad2caf604b86a339476373c659b0\",\"missingInfo\":[\"idPaymentManager\",\"psp.pspPartitaIVA\",\"paymentInfo.primaryCiIncurredFee\",\"paymentInfo.idBundle\",\"paymentInfo.idCiBundle\",\"paymentInfo.metadata\"],\"debtorPosition\":{\"modelType\":\"2\",\"noticeNumber\":\"302119891614290410\",\"iuv\":\"02119891614290410\"},\"creditor\":{\"idPA\":\"66666666666\",\"idBrokerPA\":\"66666666666\",\"idStation\":\"66666666666_01\",\"companyName\":\"PA paolo\",\"officeName\":\"office PA\"},\"psp\":{\"idPsp\":\"60000000001\",\"idBrokerPsp\":\"60000000001\",\"idChannel\":\"60000000001_01\",\"psp\":\"PSP Paolo\",\"pspPartitaIVA\":null,\"pspFiscalCode\":\"CF60000000006\",\"channelDescription\":\"app\"},\"debtor\":{\"fullName\":\"John Doe\",\"entityUniqueIdentifierType\":\"F\",\"entityUniqueIdentifierValue\":\"JHNDOE00A01F205N\",\"streetName\":\"street\",\"civicNumber\":\"12\",\"postalCode\":\"89020\",\"city\":\"city\",\"stateProvinceRegion\":\"MI\",\"country\":\"IT\",\"eMail\":\"john.doe@test.it\"},\"payer\":{\"fullName\":\"John Doe\",\"entityUniqueIdentifierType\":\"F\",\"entityUniqueIdentifierValue\":\"JHNDOE00A01F205N\",\"streetName\":\"street\",\"civicNumber\":\"12\",\"postalCode\":\"89020\",\"city\":\"city\",\"stateProvinceRegion\":\"MI\",\"country\":\"IT\",\"eMail\":\"john.doe@test.it\"},\"paymentInfo\":{\"paymentDateTime\":\"2023-04-12T16:21:39.022486\",\"applicationDate\":\"2021-10-01\",\"transferDate\":\"2021-10-02\",\"dueDate\":\"2021-07-31\",\"paymentToken\":\"9a9bad2caf604b86a339476373c659b0\",\"amount\":\"7000\",\"fee\":\"200\",\"primaryCiIncurredFee\":null,\"idBundle\":null,\"idCiBundle\":null,\"totalNotice\":\"1\",\"paymentMethod\":\"creditCard\",\"touchpoint\":\"app\",\"remittanceInformation\":\"TARI 2021\",\"description\":\"TARI 2021\",\"metadata\":null},\"transferList\":[{\"idTransfer\":\"1\",\"fiscalCodePA\":\"77777777777\",\"companyName\":\"Pa Salvo\",\"amount\":\"7000\",\"transferCategory\":\"0101101IM\",\"remittanceInformation\":\"TARI Comune EC_TE\",\"metadata\":null,\"mbdattachment\":null,\"iban\":\"IT96R0123454321000000012345\"}],\"transactionDetails\":{\"transaction\":{\"psp\":{\"businessName\":\"Nexi\"}},\"wallet\":{\"info\":{\"brand\":\"MASTER\"}}},\"timestamp\":1686919660002,\"properties\":{},\"eventStatus\":\"DONE\",\"eventRetryEnrichmentCount\":0,\"eventTriggeredBySchedule\":false,\"eventErrorMessage\":null}";
private static final String BIZ_EVENT_INVALID_MESSAGE = "invalid message";
private static final long ORIGINAL_GENERATED_AT = 0L;
diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImplTest.java
index 5749146b..c5c687b2 100644
--- a/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImplTest.java
+++ b/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImplTest.java
@@ -9,6 +9,8 @@
import it.gov.pagopa.receipt.pdf.generator.entity.receipt.ReceiptMetadata;
import it.gov.pagopa.receipt.pdf.generator.entity.receipt.enumeration.ReasonErrorCode;
import it.gov.pagopa.receipt.pdf.generator.entity.receipt.enumeration.ReceiptStatusType;
+import it.gov.pagopa.receipt.pdf.generator.exception.BizEventNotValidException;
+import it.gov.pagopa.receipt.pdf.generator.exception.PdfJsonMappingException;
import it.gov.pagopa.receipt.pdf.generator.model.PdfGeneration;
import it.gov.pagopa.receipt.pdf.generator.model.PdfMetadata;
import it.gov.pagopa.receipt.pdf.generator.model.response.BlobStorageResponse;
@@ -24,10 +26,12 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.concurrent.atomic.AtomicReference;
import static it.gov.pagopa.receipt.pdf.generator.service.impl.GenerateReceiptPdfServiceImpl.ALREADY_CREATED;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
+import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariables;
class GenerateReceiptPdfServiceImplTest {
@@ -79,7 +83,7 @@ public void teardown() throws IOException {
}
@Test
- void generateReceiptsPayerNullWithSuccess() {
+ void generateReceiptsPayerNullWithSuccess() throws Exception {
Receipt receiptOnly = getReceiptWithOnlyDebtor(false);
BizEvent bizEventOnly = getBizEventWithOnlyDebtor();
@@ -88,23 +92,26 @@ void generateReceiptsPayerNullWithSuccess() {
doReturn(getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.CREATED.value()))
.when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
- PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly, Path.of("/tmp"));
+ AtomicReference pdfGeneration = new AtomicReference<>();
+ withEnvironmentVariables().set("BRAND_LOGO_MAP", "{\"MASTER\":\"assets/mastercard.png\"}\n").set("PSP_INFO_MAP","{\"60000000001\":{\"logo\":\"assets/nexi_logo.png\"}}\n").execute(() ->
+ pdfGeneration.set(sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp") ))
+ );
assertNotNull(pdfGeneration);
- assertTrue(pdfGeneration.isGenerateOnlyDebtor());
- assertNotNull(pdfGeneration.getDebtorMetadata());
- assertNull(pdfGeneration.getDebtorMetadata().getErrorMessage());
- assertNotNull(pdfGeneration.getDebtorMetadata().getDocumentName());
- assertNotNull(pdfGeneration.getDebtorMetadata().getDocumentUrl());
- assertEquals(HttpStatus.SC_OK, pdfGeneration.getDebtorMetadata().getStatusCode());
- assertNull(pdfGeneration.getPayerMetadata());
+ assertTrue(pdfGeneration.get().isGenerateOnlyDebtor());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata());
+ assertNull(pdfGeneration.get().getDebtorMetadata().getErrorMessage());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata().getDocumentName());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata().getDocumentUrl());
+ assertEquals(HttpStatus.SC_OK, pdfGeneration.get().getDebtorMetadata().getStatusCode());
+ assertNull(pdfGeneration.get().getPayerMetadata());
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
}
@Test
- void generateReceiptsSameDebtorPayerWithSuccess() {
+ void generateReceiptsSameDebtorPayerWithSuccess() throws Exception {
Receipt receiptOnly = getReceiptWithDebtorPayer(VALID_CF_DEBTOR, false, false);
BizEvent bizEventOnly = getBizEventWithDebtorPayer(VALID_CF_DEBTOR);
@@ -113,23 +120,26 @@ void generateReceiptsSameDebtorPayerWithSuccess() {
doReturn(getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.CREATED.value()))
.when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
- PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly, Path.of("/tmp"));
+ AtomicReference pdfGeneration = new AtomicReference<>();
+ withEnvironmentVariables().set("BRAND_LOGO_MAP", "{\"MASTER\":\"assets/mastercard.png\"}\n").set("PSP_INFO_MAP","{\"60000000001\":{\"logo\":\"assets/nexi_logo.png\"}}\n").execute(() ->
+ pdfGeneration.set(sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")))
+ );
assertNotNull(pdfGeneration);
- assertTrue(pdfGeneration.isGenerateOnlyDebtor());
- assertNotNull(pdfGeneration.getDebtorMetadata());
- assertNull(pdfGeneration.getDebtorMetadata().getErrorMessage());
- assertNotNull(pdfGeneration.getDebtorMetadata().getDocumentName());
- assertNotNull(pdfGeneration.getDebtorMetadata().getDocumentUrl());
- assertEquals(HttpStatus.SC_OK, pdfGeneration.getDebtorMetadata().getStatusCode());
- assertNull(pdfGeneration.getPayerMetadata());
+ assertTrue(pdfGeneration.get().isGenerateOnlyDebtor());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata());
+ assertNull(pdfGeneration.get().getDebtorMetadata().getErrorMessage());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata().getDocumentName());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata().getDocumentUrl());
+ assertEquals(HttpStatus.SC_OK, pdfGeneration.get().getDebtorMetadata().getStatusCode());
+ assertNull(pdfGeneration.get().getPayerMetadata());
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
}
@Test
- void generateReceiptsDifferentDebtorPayerWithSuccess() {
+ void generateReceiptsDifferentDebtorPayerWithSuccess() throws Exception {
Receipt receiptOnly = getReceiptWithDebtorPayer(VALID_CF_PAYER, false, false);
BizEvent bizEventOnly = getBizEventWithDebtorPayer(VALID_CF_PAYER);
@@ -140,20 +150,23 @@ void generateReceiptsDifferentDebtorPayerWithSuccess() {
getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.CREATED.value()))
.when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
- PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly, Path.of("/tmp"));
+ AtomicReference pdfGeneration = new AtomicReference<>();
+ withEnvironmentVariables().set("BRAND_LOGO_MAP", "{\"MASTER\":\"assets/mastercard.png\"}\n").set("PSP_INFO_MAP","{\"60000000001\":{\"logo\":\"assets/nexi_logo.png\"}}\n").execute(() ->
+ pdfGeneration.set(sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")))
+ );
assertNotNull(pdfGeneration);
- assertFalse(pdfGeneration.isGenerateOnlyDebtor());
- assertNotNull(pdfGeneration.getDebtorMetadata());
- assertNull(pdfGeneration.getDebtorMetadata().getErrorMessage());
- assertNotNull(pdfGeneration.getDebtorMetadata().getDocumentName());
- assertNotNull(pdfGeneration.getDebtorMetadata().getDocumentUrl());
- assertEquals(HttpStatus.SC_OK, pdfGeneration.getDebtorMetadata().getStatusCode());
- assertNotNull(pdfGeneration.getPayerMetadata());
- assertNull(pdfGeneration.getPayerMetadata().getErrorMessage());
- assertNotNull(pdfGeneration.getPayerMetadata().getDocumentName());
- assertNotNull(pdfGeneration.getPayerMetadata().getDocumentUrl());
- assertEquals(HttpStatus.SC_OK, pdfGeneration.getPayerMetadata().getStatusCode());
+ assertFalse(pdfGeneration.get().isGenerateOnlyDebtor());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata());
+ assertNull(pdfGeneration.get().getDebtorMetadata().getErrorMessage());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata().getDocumentName());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata().getDocumentUrl());
+ assertEquals(HttpStatus.SC_OK, pdfGeneration.get().getDebtorMetadata().getStatusCode());
+ assertNotNull(pdfGeneration.get().getPayerMetadata());
+ assertNull(pdfGeneration.get().getPayerMetadata().getErrorMessage());
+ assertNotNull(pdfGeneration.get().getPayerMetadata().getDocumentName());
+ assertNotNull(pdfGeneration.get().getPayerMetadata().getDocumentUrl());
+ assertEquals(HttpStatus.SC_OK, pdfGeneration.get().getPayerMetadata().getStatusCode());
verify(pdfEngineClientMock, times(2)).generatePDF(any(), any());
verify(receiptBlobClientMock, times(2)).savePdfToBlobStorage(any(), anyString());
@@ -200,7 +213,7 @@ void generateReceiptsSameDebtorPayerAndDebtorReceiptAlreadyCreatedWithSuccess()
}
@Test
- void generateReceiptsDifferentDebtorPayerAndPayerReceiptAlreadyCreatedWithSuccess() {
+ void generateReceiptsDifferentDebtorPayerAndPayerReceiptAlreadyCreatedWithSuccess() throws Exception {
Receipt receiptOnly = getReceiptWithDebtorPayer(VALID_CF_PAYER, false, true);
BizEvent bizEventOnly = getBizEventWithDebtorPayer(VALID_CF_PAYER);
@@ -209,50 +222,56 @@ void generateReceiptsDifferentDebtorPayerAndPayerReceiptAlreadyCreatedWithSucces
doReturn(getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.CREATED.value()))
.when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
- PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly, Path.of("/tmp"));
+ AtomicReference pdfGeneration = new AtomicReference<>();
+ withEnvironmentVariables().set("BRAND_LOGO_MAP", "{\"MASTER\":\"assets/mastercard.png\"}\n").set("PSP_INFO_MAP","{\"60000000001\":{\"logo\":\"assets/nexi_logo.png\"}}\n").execute(() ->
+ pdfGeneration.set(sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")))
+ );
assertNotNull(pdfGeneration);
- assertFalse(pdfGeneration.isGenerateOnlyDebtor());
- assertNotNull(pdfGeneration.getDebtorMetadata());
- assertNull(pdfGeneration.getDebtorMetadata().getErrorMessage());
- assertNotNull(pdfGeneration.getDebtorMetadata().getDocumentName());
- assertNotNull(pdfGeneration.getDebtorMetadata().getDocumentUrl());
- assertEquals(HttpStatus.SC_OK, pdfGeneration.getDebtorMetadata().getStatusCode());
- assertNotNull(pdfGeneration.getPayerMetadata());
- assertNull(pdfGeneration.getPayerMetadata().getErrorMessage());
- assertNull(pdfGeneration.getPayerMetadata().getDocumentName());
- assertNull(pdfGeneration.getPayerMetadata().getDocumentUrl());
- assertEquals(ALREADY_CREATED, pdfGeneration.getPayerMetadata().getStatusCode());
+ assertFalse(pdfGeneration.get().isGenerateOnlyDebtor());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata());
+ assertNull(pdfGeneration.get().getDebtorMetadata().getErrorMessage());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata().getDocumentName());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata().getDocumentUrl());
+ assertEquals(HttpStatus.SC_OK, pdfGeneration.get().getDebtorMetadata().getStatusCode());
+ assertNotNull(pdfGeneration.get().getPayerMetadata());
+ assertNull(pdfGeneration.get().getPayerMetadata().getErrorMessage());
+ assertNull(pdfGeneration.get().getPayerMetadata().getDocumentName());
+ assertNull(pdfGeneration.get().getPayerMetadata().getDocumentUrl());
+ assertEquals(ALREADY_CREATED, pdfGeneration.get().getPayerMetadata().getStatusCode());
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
}
@Test
- void generateReceiptsPayerNullFailPDFEngineCallReturn500() {
+ void generateReceiptsPayerNullFailPDFEngineCallReturn500() throws Exception {
Receipt receiptOnly = getReceiptWithOnlyDebtor(false);
BizEvent bizEventOnly = getBizEventWithOnlyDebtor();
doReturn(getPdfEngineResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, ""))
.when(pdfEngineClientMock).generatePDF(any(), any());
- PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly, Path.of("/tmp"));
+ AtomicReference pdfGeneration = new AtomicReference<>();
+ withEnvironmentVariables().set("BRAND_LOGO_MAP", "{\"MASTER\":\"assets/mastercard.png\"}\n").set("PSP_INFO_MAP","{\"60000000001\":{\"logo\":\"assets/nexi_logo.png\"}}\n").execute(() ->
+ pdfGeneration.set(sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")))
+ );
assertNotNull(pdfGeneration);
- assertTrue(pdfGeneration.isGenerateOnlyDebtor());
- assertNotNull(pdfGeneration.getDebtorMetadata());
- assertNotNull(pdfGeneration.getDebtorMetadata().getErrorMessage());
- assertNull(pdfGeneration.getDebtorMetadata().getDocumentName());
- assertNull(pdfGeneration.getDebtorMetadata().getDocumentUrl());
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, pdfGeneration.getDebtorMetadata().getStatusCode());
- assertNull(pdfGeneration.getPayerMetadata());
+ assertTrue(pdfGeneration.get().isGenerateOnlyDebtor());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata().getErrorMessage());
+ assertNull(pdfGeneration.get().getDebtorMetadata().getDocumentName());
+ assertNull(pdfGeneration.get().getDebtorMetadata().getDocumentUrl());
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, pdfGeneration.get().getDebtorMetadata().getStatusCode());
+ assertNull(pdfGeneration.get().getPayerMetadata());
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock, never()).savePdfToBlobStorage(any(), anyString());
}
@Test
- void generateReceiptsPayerNullFailSaveToBlobStorageThrowsException() {
+ void generateReceiptsPayerNullFailSaveToBlobStorageThrowsException() throws Exception {
Receipt receiptOnly = getReceiptWithOnlyDebtor(false);
BizEvent bizEventOnly = getBizEventWithOnlyDebtor();
@@ -260,23 +279,27 @@ void generateReceiptsPayerNullFailSaveToBlobStorageThrowsException() {
.when(pdfEngineClientMock).generatePDF(any(), any());
doThrow(RuntimeException.class).when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
- PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly, Path.of("/tmp"));
+
+ AtomicReference pdfGeneration = new AtomicReference<>();
+ withEnvironmentVariables().set("BRAND_LOGO_MAP", "{\"MASTER\":\"assets/mastercard.png\"}\n").set("PSP_INFO_MAP","{\"60000000001\":{\"logo\":\"assets/nexi_logo.png\"}}\n").execute(() ->
+ pdfGeneration.set(sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")))
+ );
assertNotNull(pdfGeneration);
- assertTrue(pdfGeneration.isGenerateOnlyDebtor());
- assertNotNull(pdfGeneration.getDebtorMetadata());
- assertNotNull(pdfGeneration.getDebtorMetadata().getErrorMessage());
- assertNull(pdfGeneration.getDebtorMetadata().getDocumentName());
- assertNull(pdfGeneration.getDebtorMetadata().getDocumentUrl());
- assertEquals(ReasonErrorCode.ERROR_BLOB_STORAGE.getCode(), pdfGeneration.getDebtorMetadata().getStatusCode());
- assertNull(pdfGeneration.getPayerMetadata());
+ assertTrue(pdfGeneration.get().isGenerateOnlyDebtor());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata());
+ assertNotNull(pdfGeneration.get().getDebtorMetadata().getErrorMessage());
+ assertNull(pdfGeneration.get().getDebtorMetadata().getDocumentName());
+ assertNull(pdfGeneration.get().getDebtorMetadata().getDocumentUrl());
+ assertEquals(ReasonErrorCode.ERROR_BLOB_STORAGE.getCode(), pdfGeneration.get().getDebtorMetadata().getStatusCode());
+ assertNull(pdfGeneration.get().getPayerMetadata());
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
}
@Test
- void generateReceiptsPayerNullFailSaveToBlobStorageReturn500() {
+ void generateReceiptsPayerNullFailSaveToBlobStorageReturn500() throws Exception {
Receipt receiptOnly = getReceiptWithOnlyDebtor(false);
BizEvent bizEventOnly = getBizEventWithOnlyDebtor();
@@ -285,16 +308,19 @@ void generateReceiptsPayerNullFailSaveToBlobStorageReturn500() {
doReturn(getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.INTERNAL_SERVER_ERROR.value()))
.when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
- PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly, Path.of("/tmp"));
+ AtomicReference pdfGeneration = new AtomicReference<>();
+ withEnvironmentVariables().set("BRAND_LOGO_MAP", "{\"MASTER\":\"assets/mastercard.png\"}\n").set("PSP_INFO_MAP","{\"60000000001\":{\"logo\":\"assets/nexi_logo.png\"}}\n").execute(() ->
+ pdfGeneration.set(sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")))
+ );
assertNotNull(pdfGeneration);
- assertTrue(pdfGeneration.isGenerateOnlyDebtor());
- assertNotNull(pdfGeneration.getDebtorMetadata());
- assertNotNull(pdfGeneration.getDebtorMetadata().getErrorMessage());
- assertNull(pdfGeneration.getDebtorMetadata().getDocumentName());
- assertNull(pdfGeneration.getDebtorMetadata().getDocumentUrl());
- assertEquals(ReasonErrorCode.ERROR_BLOB_STORAGE.getCode(), pdfGeneration.getDebtorMetadata().getStatusCode());
- assertNull(pdfGeneration.getPayerMetadata());
+ assertTrue(pdfGeneration.get().isGenerateOnlyDebtor());
+ assertNotNull((pdfGeneration.get().getDebtorMetadata()));
+ assertNotNull((pdfGeneration.get().getDebtorMetadata().getErrorMessage()));
+ assertNull((pdfGeneration.get().getDebtorMetadata().getDocumentName()));
+ assertNull((pdfGeneration.get().getDebtorMetadata().getDocumentUrl()));
+ assertEquals(ReasonErrorCode.ERROR_BLOB_STORAGE.getCode(), (pdfGeneration.get().getDebtorMetadata().getStatusCode()));
+ assertNull((pdfGeneration.get().getPayerMetadata()));
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
@@ -629,6 +655,7 @@ private BizEvent getBizEvent(Payer payer) {
.officeName("office PA")
.build())
.psp(Psp.builder()
+ .idPsp("60000000001")
.psp("PSP Paolo")
.build())
.debtor(Debtor.builder()
@@ -645,6 +672,7 @@ private BizEvent getBizEvent(Payer payer) {
.IUR("IUR")
.build())
.transactionDetails(TransactionDetails.builder()
+ .wallet(WalletItem.builder().info(Info.builder().brand("MASTER").build()).build())
.transaction(Transaction.builder()
.idTransaction(1L)
.grandTotal(0L)
@@ -652,9 +680,10 @@ private BizEvent getBizEvent(Payer payer) {
.fee(200L)
.rrn("rrn")
.authorizationCode("authCode")
- .creationDate("creation date")
+ .creationDate("2023-10-14T00:03:27Z")
.psp(TransactionPsp.builder()
- .businessName("business name")
+ .businessName("Nexi")
+ .serviceName("Nexi")
.build())
.build())
.build())