Skip to content

Commit

Permalink
Merge branch 'master' into IOBP-432-payment-authorization-webview
Browse files Browse the repository at this point in the history
  • Loading branch information
mastro993 authored Nov 30, 2023
2 parents 238cd0c + c01edea commit bdd8a82
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 48 deletions.
4 changes: 2 additions & 2 deletions assets/wallet/wallet_onboarding.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
})
.then(response => response.json())
.then(response => {
window.location.href = `/wallets/outcomes?outcome=${container.value}&walletId=${response.walletId}`;
window.location = `iowallet://127.0.0.1:3000/wallets/outcomes?outcome=${container.value}&walletId=${response.walletId}`;
})
.catch(err => alert(err))
} else {
window.location.href = `/wallets/outcomes?outcome=${container.value}`;
window.location = `iowallet://127.0.0.1:3000/wallets/outcomes?outcome=${container.value}`;
}
}

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
"api_cdc": "https://raw.githubusercontent.com/pagopa/io-app/master/assets/CdcSwagger.yml",
"api_fci": "https://raw.githubusercontent.com/pagopa/io-backend/v13.22.0-RELEASE/api_io_sign.yaml",
"api_pn": "https://raw.githubusercontent.com/pagopa/io-backend/v13.22.0-RELEASE/api_pn.yaml",
"api_idpay": "https://raw.githubusercontent.com/pagopa/cstar-infrastructure/v5.8.0/src/domains/idpay-app/api/idpay_appio_full/openapi.appio.full.yml",
"api_idpay": "https://raw.githubusercontent.com/pagopa/cstar-infrastructure/v6.3.0/src/domains/idpay-app/api/idpay_appio_full/openapi.appio.full.yml",
"api_fast_login": "https://raw.githubusercontent.com/pagopa/io-backend/v13.22.0-RELEASE/openapi/generated/api_fast_login.yaml",
"api_pagopa_walletv3": "https://raw.githubusercontent.com/pagopa/pagopa-infra/5bd3f60aff52d2653111aa47a3975997295ae210/src/domains/wallet-app/api/payment-wallet/v1/_openapi.json.tpl",
"api_pagopa_ecommerce": "https://raw.githubusercontent.com/pagopa/pagopa-infra/f33fd4b201e198d4e893d880c24fdedba52a7b16/src/domains/ecommerce-app/api/ecommerce-io/v1/_openapi.json.tpl",
"api_pagopa_ecommerce": "https://raw.githubusercontent.com/pagopa/pagopa-infra/65878f9913fcc0eaff499ba8a1a20427a412c010/src/domains/ecommerce-app/api/ecommerce-io/v1/_openapi.json.tpl",
"author": "Matteo Boschi",
"license": "MIT",
"private": false,
Expand Down
11 changes: 10 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ const defaultConfig: IoDevServerConfig = {
getMessageResponseCode: 200,
getThirdPartyMessageResponseCode: 200
},
messageTemplateWrappers: [
{
count: 1,
template: {
subjectWordCount: 5,
hasRemoteContent: true,
attachmentCount: 5
}
}
],
pnMessageTemplateWrappers: [
{
count: 0,
Expand All @@ -92,7 +102,6 @@ const defaultConfig: IoDevServerConfig = {
attachmentExpiredAfterSeconds: 10,
attachmentRetryAfterSeconds: 2,
pnOptInMessage: false,
withRemoteAttachments: 0,
paymentsCount: 1,
paymentInvalidAfterDueDateWithValidDueDateCount: 0,
paymentInvalidAfterDueDateWithExpiredDueDateCount: 0,
Expand Down
29 changes: 22 additions & 7 deletions src/features/messages/persistence/messagesPayload.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as path from "path";
import { pipe } from "fp-ts/lib/function";
import * as S from "fp-ts/lib/string";
import { constUndefined, pipe } from "fp-ts/lib/function";
import * as A from "fp-ts/lib/Array";
import * as O from "fp-ts/lib/Option";
import * as B from "fp-ts/lib/boolean";
import * as E from "fp-ts/lib/Either";
import * as O from "fp-ts/lib/Option";
import * as S from "fp-ts/lib/string";
import { faker } from "@faker-js/faker/locale/it";
import { NonEmptyString } from "@pagopa/ts-commons/lib/strings";
import { CreatedMessageWithContent } from "../../../../generated/definitions/backend/CreatedMessageWithContent";
Expand All @@ -27,6 +28,7 @@ import ServicesDB from "../../../persistence/services";
import PaymentsDB from "../../../persistence/payments";
import { AttachmentCategory } from "../types/attachmentCategory";
import { rptIdFromPaymentDataWithRequiredPayee } from "../../../utils/payment";
import { MessageTemplate } from "../types/messageTemplate";

// eslint-disable-next-line functional/no-let
let messageIdIndex = 0;
Expand Down Expand Up @@ -61,21 +63,34 @@ export const withDueDate = (
content: { ...message.content, due_date: dueDate }
});

export const withRemoteAttachments = (
export const withRemoteContent = (
template: MessageTemplate,
message: CreatedMessageWithContent,
attachmentCount: number
markdown: string
): ThirdPartyMessageWithContent => ({
...message,
content: {
...message.content,
third_party_data: {
...message.content.third_party_data,
id: message.id as NonEmptyString,
has_attachments: true
has_attachments: template.attachmentCount > 0
}
},
third_party_message: {
attachments: getRemoteAttachments(attachmentCount)
details: pipe(
template.hasRemoteContent,
B.fold(constUndefined, () => ({
subject: faker.lorem.sentence(template.subjectWordCount),
markdown
}))
),
attachments: pipe(
template.attachmentCount > 0,
B.fold(constUndefined, () =>
getRemoteAttachments(template.attachmentCount)
)
)
}
});

Expand Down
12 changes: 12 additions & 0 deletions src/features/messages/types/messageTemplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as t from "io-ts";

export const MessageTemplate = t.intersection([
t.type({
hasRemoteContent: t.boolean,
attachmentCount: t.number
}),
t.partial({
subjectWordCount: t.number
})
]);
export type MessageTemplate = t.TypeOf<typeof MessageTemplate>;
8 changes: 8 additions & 0 deletions src/features/messages/types/messageTemplateWrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as t from "io-ts";
import { MessageTemplate } from "./messageTemplate";

export const MessageTemplateWrapper = t.type({
template: MessageTemplate,
count: t.number
});
export type MessageTemplateWrapper = t.TypeOf<typeof MessageTemplateWrapper>;
5 changes: 3 additions & 2 deletions src/features/messages/types/messagesConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PNMessageTemplateWrapper } from "../../pn/types/messageTemplateWrapper"
import { HttpResponseCode } from "../../../types/httpResponseCode";
import { AllowRandomValue } from "../../../types/allowRandomValue";
import { LiveModeMessages } from "./liveModeMessages";
import { MessageTemplateWrapper } from "./messageTemplateWrapper";

export const MessagesConfig = t.intersection([
t.type({
Expand All @@ -16,8 +17,6 @@ export const MessagesConfig = t.intersection([
getThirdPartyMessageResponseCode: HttpResponseCode
}),
paymentsCount: t.number,
// number of messages with remote attachments
withRemoteAttachments: t.number,
// number of message - invalid after due date - containing a payment and a valid (not expired) due date
paymentInvalidAfterDueDateWithValidDueDateCount: t.number,
// number of message - invalid after due date - containing a payment and a not valid (expired) due date
Expand Down Expand Up @@ -61,6 +60,8 @@ export const MessagesConfig = t.intersection([
attachmentAvailableAfterSeconds: t.number,
attachmentExpiredAfterSeconds: t.number,
attachmentRetryAfterSeconds: t.number,
// number of messages with remote content
messageTemplateWrappers: t.readonlyArray(MessageTemplateWrapper),
// number of messages coming from PN (aka Piattaforma Notifiche)
pnMessageTemplateWrappers: t.readonlyArray(PNMessageTemplateWrapper),
// PN Opt In message
Expand Down
10 changes: 6 additions & 4 deletions src/persistence/idpay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ let barcodeTransactions: {

export const getIdPayBarcodeTransaction = (
initiativeId: string,
trxExpirationMinutes: number = 1
trxExpirationSeconds: number = 60
): TransactionBarCodeResponse => {
const currentBarcode = barcodeTransactions[initiativeId];
if (currentBarcode === undefined) {
Expand All @@ -671,7 +671,9 @@ export const getIdPayBarcodeTransaction = (
initiativeId,
status: StatusEnum.CREATED,
trxDate: new Date(),
trxExpirationMinutes
trxExpirationSeconds,
initiativeName: faker.company.name(),
residualBudgetCents: 100000
};
barcodeTransactions = {
...barcodeTransactions,
Expand All @@ -681,11 +683,11 @@ export const getIdPayBarcodeTransaction = (
} else {
const timeDiff = new Date().getTime() - currentBarcode.trxDate.getTime();
// trxExpirationMinutes is in minutes, timeDiff is in milliseconds
const isExpired = timeDiff > trxExpirationMinutes * 60 * 1000;
const isExpired = timeDiff > trxExpirationSeconds * 1000;
if (isExpired) {
// eslint-disable-next-line functional/immutable-data
delete barcodeTransactions[initiativeId];
return getIdPayBarcodeTransaction(initiativeId, trxExpirationMinutes);
return getIdPayBarcodeTransaction(initiativeId, trxExpirationSeconds);
}
return currentBarcode;
}
Expand Down
90 changes: 63 additions & 27 deletions src/populate-persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { pipe } from "fp-ts/lib/function";
import * as A from "fp-ts/lib/Array";
import * as B from "fp-ts/lib/boolean";
import * as E from "fp-ts/lib/Either";
import * as O from "fp-ts/lib/Option";
import { faker } from "@faker-js/faker/locale/it";
import _ from "lodash";
import { CreatedMessageWithContentAndAttachments } from "../generated/definitions/backend/CreatedMessageWithContentAndAttachments";
Expand All @@ -11,13 +12,15 @@ import { MessageAttachment } from "../generated/definitions/backend/MessageAttac
import { MessageSubject } from "../generated/definitions/backend/MessageSubject";
import { PrescriptionData } from "../generated/definitions/backend/PrescriptionData";
import { ThirdPartyMessageWithContent } from "../generated/definitions/backend/ThirdPartyMessageWithContent";
import { FiscalCode } from "../generated/definitions/backend/FiscalCode";
import { CreatedMessageWithContent } from "../generated/definitions/backend/CreatedMessageWithContent";
import { ioDevServerConfig } from "./config";
import {
createMessage,
withContent,
withDueDate,
withPaymentData,
withRemoteAttachments
withRemoteContent
} from "./features/messages/persistence/messagesPayload";
import ServicesDB from "./persistence/services";
import MessagesDB from "./features/messages/persistence/messagesDatabase";
Expand Down Expand Up @@ -48,6 +51,8 @@ import {
createPNMessages,
createPNOptInMessage
} from "./features/pn/payloads/messages";
import { MessageTemplateWrapper } from "./features/messages/types/messageTemplateWrapper";
import { MessageTemplate } from "./features/messages/types/messageTemplate";

const getServiceId = (): string => {
const servicesSummaries = ServicesDB.getSummaries(true);
Expand Down Expand Up @@ -82,22 +87,6 @@ export const getNewMessage = (
euCovidCert
);

const getNewRemoteAttachmentsMessage = (
customConfig: IoDevServerConfig,
sender: string,
subject: string,
markdown: string,
attachmentCount: number
): ThirdPartyMessageWithContent =>
withRemoteAttachments(
withContent(
createMessage(customConfig.profile.attrs.fiscal_code, getServiceId()),
`${sender}: ${subject}`,
markdown
),
attachmentCount
);

const createMessagesWithCTA = (
customConfig: IoDevServerConfig
): CreatedMessageWithContentAndAttachments[] =>
Expand Down Expand Up @@ -470,17 +459,64 @@ const createMessagesWithPayments = (
)
);

const createMessagesWithRemoteAttachments = (
const createMessageWithRemoteContent = (
template: MessageTemplate,
fiscalCode: FiscalCode,
templateIndex: number,
messageIndex: number,
markdown: string
): CreatedMessageWithContent | ThirdPartyMessageWithContent =>
pipe(
{
sender: `Sender - ${templateIndex} / ${messageIndex}`,
subject: "Message with remote content"
},
sharedData =>
pipe(
createMessage(fiscalCode, getServiceId()),
createdMessageWithoutContent =>
withContent(
createdMessageWithoutContent,
`${sharedData.sender}: ${sharedData.subject}`,
markdown
),
createdMessageWithContent =>
pipe(
template,
O.fromPredicate(t => t.hasRemoteContent || t.attachmentCount > 0),
O.fold(
() => createdMessageWithContent,
() =>
withRemoteContent(template, createdMessageWithContent, markdown)
)
)
)
);

const createMessagesWithRemoteContent = (
customConfig: IoDevServerConfig
): CreatedMessageWithContentAndAttachments[] =>
A.makeBy(customConfig.messages.withRemoteAttachments, index =>
getNewRemoteAttachmentsMessage(
customConfig,
`Sender ${index}`,
`Subject ${index}: remote attachments`,
messageMarkdown,
1 + index
)
pipe(
customConfig.messages.messageTemplateWrappers,
O.fromNullable,
O.map(messageTemplateWrappers =>
pipe(
messageTemplateWrappers as MessageTemplateWrapper[],
A.mapWithIndex((templateIndex, messageTemplateWrapper) =>
A.makeBy(messageTemplateWrapper.count, messageIndex =>
createMessageWithRemoteContent(
messageTemplateWrapper.template,
customConfig.profile.attrs.fiscal_code,
templateIndex,
messageIndex,
messageMarkdown
)
)
),
A.flatten
)
),
O.getOrElse(() => [] as CreatedMessageWithContentAndAttachments[])
);

const createMessages = (
Expand Down Expand Up @@ -531,7 +567,7 @@ const createMessages = (
...createPNOptInMessage(customConfig),
...createPNMessages(customConfig),

...createMessagesWithRemoteAttachments(customConfig)
...createMessagesWithRemoteContent(customConfig)
];
};

Expand Down
1 change: 0 additions & 1 deletion src/routers/__tests__/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const customConfig = _.merge(ioDevServerConfig, {
withInValidDueDateCount: 2,
standardMessageCount: 10,
archivedMessageCount: 40,
withRemoteAttachments: 0,
pnMessageTemplateWrappers: [
{
count: 1,
Expand Down
4 changes: 3 additions & 1 deletion src/routers/features/idpay/barcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { getWalletDetailResponse } from "../../../payloads/features/idpay/get-wa
import { getIdPayBarcodeTransaction } from "../../../persistence/idpay";
import { addIdPayHandler } from "./router";

const SECONDS_TO_EXPIRE_BARCODE = 120;

addIdPayHandler("post", "/payment/bar-code", (req, res) =>
pipe(
TransactionBarCodeRequest.decode(req.body),
Expand All @@ -22,7 +24,7 @@ addIdPayHandler("post", "/payment/bar-code", (req, res) =>
() => {
const barcodeTransaction = getIdPayBarcodeTransaction(
initiativeId,
2
SECONDS_TO_EXPIRE_BARCODE
);
return res.status(201).json(barcodeTransaction);
}
Expand Down

0 comments on commit bdd8a82

Please sign in to comment.