From 775ee7ac632badc399ef940c982a0cec7de093f1 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Tue, 17 Oct 2023 11:46:55 +0200 Subject: [PATCH 1/8] chore: first implementation of new wallet onboarding --- package.json | 2 +- src/routers/features/walletV3/onboarding.ts | 19 ---------- .../features/walletV3/onboarding/data.ts | 36 +++++++++++++++++++ .../features/walletV3/onboarding/index.ts | 27 ++++++++++++++ .../features/walletV3/onboarding/utils.ts | 5 +++ src/routers/features/walletV3/router.ts | 8 +++++ src/utils/wallet.ts | 1 - 7 files changed, 77 insertions(+), 21 deletions(-) delete mode 100644 src/routers/features/walletV3/onboarding.ts create mode 100644 src/routers/features/walletV3/onboarding/data.ts create mode 100644 src/routers/features/walletV3/onboarding/index.ts create mode 100644 src/routers/features/walletV3/onboarding/utils.ts diff --git a/package.json b/package.json index bced3c85..6e73b1c3 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "api_pn": "https://raw.githubusercontent.com/pagopa/io-backend/v13.10.1-RELEASE/api_pn.yaml", "api_idpay": "https://raw.githubusercontent.com/pagopa/cstar-infrastructure/v4.5.0/src/domains/idpay-app/api/idpay_appio_full/openapi.appio.full.yml", "api_fast_login": "https://raw.githubusercontent.com/pagopa/io-backend/v13.10.1-RELEASE/openapi/generated/api_fast_login.yaml", - "api_pagopa_walletv3": "https://raw.githubusercontent.com/pagopa/pagopa-infra/ca0f61d6c764dcc8a8594c1593d436dcdae58a7c/src/domains/wallet-app/api/wallet-service/v1/_openapi.json.tpl", + "api_pagopa_walletv3": "https://raw.githubusercontent.com/pagopa/pagopa-infra/fde8d344d1eae9d16ca338d4f71095c805b99f75/src/domains/wallet-app/api/payment-wallet/v1/_openapi.json.tpl", "author": "Matteo Boschi", "license": "MIT", "private": false, diff --git a/src/routers/features/walletV3/onboarding.ts b/src/routers/features/walletV3/onboarding.ts deleted file mode 100644 index e5903d0e..00000000 --- a/src/routers/features/walletV3/onboarding.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { pipe } from "fp-ts/lib/function"; -import * as E from "fp-ts/lib/Either"; - -import { WalletCreateRequest } from "../../../../generated/definitions/pagopa/walletv3/WalletCreateRequest"; -import { generateOnboardingWalletData } from "../../../utils/wallet"; -import { addWalletV3Handler } from "./router"; - -/** - * This API is used to start an onboarding process for a new method of payment - */ -addWalletV3Handler("post", "/", (req, res) => { - pipe( - WalletCreateRequest.decode(req.body), - E.fold( - () => res.sendStatus(400), - () => res.json(generateOnboardingWalletData()) - ) - ); -}); diff --git a/src/routers/features/walletV3/onboarding/data.ts b/src/routers/features/walletV3/onboarding/data.ts new file mode 100644 index 00000000..8829fae6 --- /dev/null +++ b/src/routers/features/walletV3/onboarding/data.ts @@ -0,0 +1,36 @@ +import { PaymentMethodStatusEnum } from "../../../../../generated/definitions/pagopa/walletv3/PaymentMethodStatus"; +import { PaymentMethodsResponse } from "../../../../../generated/definitions/pagopa/walletv3/PaymentMethodsResponse"; +import { Range } from "../../../../../generated/definitions/pagopa/walletv3/Range"; + +export const allPaymentMethods: PaymentMethodsResponse = { + paymentMethods: [ + { + id: "1", + name: "Carta di credito", + description: "Pagamento con carta di credito", + asset: "creditCard", + status: PaymentMethodStatusEnum.ENABLED, + paymentTypeCode: "string", + ranges: [ + { + min: 0, + max: 1000 + } as Range + ] + }, + { + id: "2", + name: "BANCOMAT Pay", + description: "Pagamento con BANCOMAT Pay", + asset: "bancomatPay", + status: PaymentMethodStatusEnum.ENABLED, + paymentTypeCode: "string", + ranges: [ + { + min: 0, + max: 500 + } as Range + ] + } + ] +}; diff --git a/src/routers/features/walletV3/onboarding/index.ts b/src/routers/features/walletV3/onboarding/index.ts new file mode 100644 index 00000000..ffae9f98 --- /dev/null +++ b/src/routers/features/walletV3/onboarding/index.ts @@ -0,0 +1,27 @@ +import { pipe } from "fp-ts/lib/function"; +import * as E from "fp-ts/lib/Either"; + +import { WalletCreateRequest } from "../../../../../generated/definitions/pagopa/walletv3/WalletCreateRequest"; +import { generateOnboardingWalletData } from "../../../../utils/wallet"; +import { addPaymentMethodsHandler, addWalletV3Handler } from "../router"; +import { generateAvailablePaymentMethods } from "./utils"; + +/** + * This API is used to start an onboarding process for a new method of payment + */ +addWalletV3Handler("post", "/", (req, res) => { + pipe( + WalletCreateRequest.decode(req.body), + E.fold( + () => res.sendStatus(400), + () => res.json(generateOnboardingWalletData()) + ) + ); +}); + +/** + * This API is used to retrieve a list of payment methods available for the onboarding process + */ +addPaymentMethodsHandler("get", "/", (req, res) => { + res.json(generateAvailablePaymentMethods()); +}); diff --git a/src/routers/features/walletV3/onboarding/utils.ts b/src/routers/features/walletV3/onboarding/utils.ts new file mode 100644 index 00000000..4745b0eb --- /dev/null +++ b/src/routers/features/walletV3/onboarding/utils.ts @@ -0,0 +1,5 @@ +import { PaymentMethodsResponse } from "../../../../../generated/definitions/pagopa/walletv3/PaymentMethodsResponse"; +import { allPaymentMethods } from "./data"; + +export const generateAvailablePaymentMethods = (): PaymentMethodsResponse => + allPaymentMethods; diff --git a/src/routers/features/walletV3/router.ts b/src/routers/features/walletV3/router.ts index d7904872..ba617ad4 100644 --- a/src/routers/features/walletV3/router.ts +++ b/src/routers/features/walletV3/router.ts @@ -4,9 +4,17 @@ import { addHandler, SupportedMethod } from "../../../payloads/response"; export const walletV3Router = Router(); export const addWalletV3Prefix = (path: string) => `/wallets${path}`; +export const addPaymentMethodsPrefix = (path: string) => + `/payment-methods${path}`; export const addWalletV3Handler = ( method: SupportedMethod, path: string, handleRequest: (request: Request, response: Response) => void ) => addHandler(walletV3Router, method, addWalletV3Prefix(path), handleRequest); + +export const addPaymentMethodsHandler = ( + method: SupportedMethod, + path: string, + handleRequest: (request: Request, response: Response) => void +) => addHandler(walletV3Router, method, addWalletV3Prefix(path), handleRequest); diff --git a/src/utils/wallet.ts b/src/utils/wallet.ts index 7d2f1ed3..c520d46a 100644 --- a/src/utils/wallet.ts +++ b/src/utils/wallet.ts @@ -12,6 +12,5 @@ export const appendWalletV3Prefix = (path: string) => `${walletV3Path}${path}`; export const WALLET_ONBOARDING_PATH = "/onboarding-wallet"; export const generateOnboardingWalletData = (): WalletCreateResponse => ({ - walletId: faker.datatype.uuid(), redirectUrl: `${serverUrl}${WALLET_ONBOARDING_PATH}#sessionToken=${faker.datatype.uuid()}` }); From 77c316b7daa05d2f6f9eadb7ba9c5f548677ff29 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Wed, 18 Oct 2023 16:34:05 +0200 Subject: [PATCH 2/8] chore: retrieve list of available payment methods from api request --- .../features/walletV3/onboarding/data.ts | 28 +++++++++---------- .../features/walletV3/onboarding/index.ts | 6 ++-- .../features/walletV3/onboarding/utils.ts | 2 +- src/routers/features/walletV3/router.ts | 8 +++++- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/routers/features/walletV3/onboarding/data.ts b/src/routers/features/walletV3/onboarding/data.ts index 8829fae6..2bf3b873 100644 --- a/src/routers/features/walletV3/onboarding/data.ts +++ b/src/routers/features/walletV3/onboarding/data.ts @@ -17,20 +17,20 @@ export const allPaymentMethods: PaymentMethodsResponse = { max: 1000 } as Range ] - }, - { - id: "2", - name: "BANCOMAT Pay", - description: "Pagamento con BANCOMAT Pay", - asset: "bancomatPay", - status: PaymentMethodStatusEnum.ENABLED, - paymentTypeCode: "string", - ranges: [ - { - min: 0, - max: 500 - } as Range - ] } + // { + // id: "2", + // name: "BANCOMAT Pay", + // description: "Pagamento con BANCOMAT Pay", + // asset: "bancomatPay", + // status: PaymentMethodStatusEnum.ENABLED, + // paymentTypeCode: "string", + // ranges: [ + // { + // min: 0, + // max: 500 + // } as Range + // ] + // } ] }; diff --git a/src/routers/features/walletV3/onboarding/index.ts b/src/routers/features/walletV3/onboarding/index.ts index ffae9f98..d14381fb 100644 --- a/src/routers/features/walletV3/onboarding/index.ts +++ b/src/routers/features/walletV3/onboarding/index.ts @@ -4,7 +4,7 @@ import * as E from "fp-ts/lib/Either"; import { WalletCreateRequest } from "../../../../../generated/definitions/pagopa/walletv3/WalletCreateRequest"; import { generateOnboardingWalletData } from "../../../../utils/wallet"; import { addPaymentMethodsHandler, addWalletV3Handler } from "../router"; -import { generateAvailablePaymentMethods } from "./utils"; +import { generateOnboardablePaymentMethods } from "./utils"; /** * This API is used to start an onboarding process for a new method of payment @@ -14,7 +14,7 @@ addWalletV3Handler("post", "/", (req, res) => { WalletCreateRequest.decode(req.body), E.fold( () => res.sendStatus(400), - () => res.json(generateOnboardingWalletData()) + () => res.status(201).json(generateOnboardingWalletData()) ) ); }); @@ -23,5 +23,5 @@ addWalletV3Handler("post", "/", (req, res) => { * This API is used to retrieve a list of payment methods available for the onboarding process */ addPaymentMethodsHandler("get", "/", (req, res) => { - res.json(generateAvailablePaymentMethods()); + res.json(generateOnboardablePaymentMethods()); }); diff --git a/src/routers/features/walletV3/onboarding/utils.ts b/src/routers/features/walletV3/onboarding/utils.ts index 4745b0eb..94793ebd 100644 --- a/src/routers/features/walletV3/onboarding/utils.ts +++ b/src/routers/features/walletV3/onboarding/utils.ts @@ -1,5 +1,5 @@ import { PaymentMethodsResponse } from "../../../../../generated/definitions/pagopa/walletv3/PaymentMethodsResponse"; import { allPaymentMethods } from "./data"; -export const generateAvailablePaymentMethods = (): PaymentMethodsResponse => +export const generateOnboardablePaymentMethods = (): PaymentMethodsResponse => allPaymentMethods; diff --git a/src/routers/features/walletV3/router.ts b/src/routers/features/walletV3/router.ts index ba617ad4..aebf3f74 100644 --- a/src/routers/features/walletV3/router.ts +++ b/src/routers/features/walletV3/router.ts @@ -17,4 +17,10 @@ export const addPaymentMethodsHandler = ( method: SupportedMethod, path: string, handleRequest: (request: Request, response: Response) => void -) => addHandler(walletV3Router, method, addWalletV3Prefix(path), handleRequest); +) => + addHandler( + walletV3Router, + method, + addPaymentMethodsPrefix(path), + handleRequest + ); From 4718b4c18ba5bab077cd7b86f39274e7d3e7ab19 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Wed, 18 Oct 2023 16:43:45 +0200 Subject: [PATCH 3/8] chore: adapted walletId as response in case of success --- assets/wallet/wallet_onboarding.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/assets/wallet/wallet_onboarding.html b/assets/wallet/wallet_onboarding.html index 78b45dc8..c3994f2a 100644 --- a/assets/wallet/wallet_onboarding.html +++ b/assets/wallet/wallet_onboarding.html @@ -9,7 +9,11 @@ const simulateOutcome = () => { const container = document.getElementById("outcomeSelect"); - window.location.href = `/outcomeView?outcome=${container.value}`; + if (container.value === "0") { + window.location.href = `/outcomeView?outcome=${container.value}&walletId=100`; + } else { + window.location.href = `/outcomeView?outcome=${container.value}`; + } } function onLoad() { From ae8c11e2c08c2de73202847fd2f7421efdc09fe3 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Thu, 19 Oct 2023 15:39:40 +0200 Subject: [PATCH 4/8] chore: added another payment methods --- .../features/walletV3/onboarding/data.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/routers/features/walletV3/onboarding/data.ts b/src/routers/features/walletV3/onboarding/data.ts index 2bf3b873..8829fae6 100644 --- a/src/routers/features/walletV3/onboarding/data.ts +++ b/src/routers/features/walletV3/onboarding/data.ts @@ -17,20 +17,20 @@ export const allPaymentMethods: PaymentMethodsResponse = { max: 1000 } as Range ] + }, + { + id: "2", + name: "BANCOMAT Pay", + description: "Pagamento con BANCOMAT Pay", + asset: "bancomatPay", + status: PaymentMethodStatusEnum.ENABLED, + paymentTypeCode: "string", + ranges: [ + { + min: 0, + max: 500 + } as Range + ] } - // { - // id: "2", - // name: "BANCOMAT Pay", - // description: "Pagamento con BANCOMAT Pay", - // asset: "bancomatPay", - // status: PaymentMethodStatusEnum.ENABLED, - // paymentTypeCode: "string", - // ranges: [ - // { - // min: 0, - // max: 500 - // } as Range - // ] - // } ] }; From 8c34b748ed3de4edf0be70ebfaf813f651be5025 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Mon, 23 Oct 2023 15:49:37 +0200 Subject: [PATCH 5/8] chore: added new apis to handle new wallet onboarding mocks --- assets/wallet/wallet_onboarding.html | 18 +++++++- src/persistence/wallet.ts | 41 +++++++++++++++++++ .../features/walletV3/onboarding/index.ts | 14 +++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 src/persistence/wallet.ts diff --git a/assets/wallet/wallet_onboarding.html b/assets/wallet/wallet_onboarding.html index c3994f2a..9f0e956e 100644 --- a/assets/wallet/wallet_onboarding.html +++ b/assets/wallet/wallet_onboarding.html @@ -1,7 +1,7 @@ -