Skip to content

Commit

Permalink
chore: [IOBP-665,IOBP-570] PayPal metadata and latest used payment me…
Browse files Browse the repository at this point in the history
…thod adaption (#5803)

## Short description
This PR adds the metadata for fast PayPal payment by adding the masked
email and the pspBusinessName if both are present. In addition, the
selector has been adapted to handle the “recently used” logic by taking
into account the `lastUsage` attribute of the `clients` map

## List of changes proposed in this pull request
- Upgraded the new openapi for wallet & ecommerce
- Changed the selector to filter the "recently used" payment method
following the new openapi definitions
- Added metadata to the "Pagamento veloce con PayPal" with the
pspBusinessName and maskedEmail if both present.

## How to test
- Checkout this PR: pagopa/io-dev-api-server#384
- Start a new payment and when you are in the payment selection step,
you should be able to see a pre-selected method. If in the list of saved
methods or the "recently used" there is a "Pagamento veloce con PayPal",
you should be able even to see metadata in the list item description


## Preview
<img
src="https://github.com/pagopa/io-app/assets/34343582/f2dcd4ae-276d-4f32-b6bf-81fd75911ca3"
width="350px" />
  • Loading branch information
Hantex9 authored Jun 4, 2024
1 parent 50f254f commit 5d017f9
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 18 deletions.
2 changes: 2 additions & 0 deletions locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,8 @@ wallet:
title: Vuoi interrompere l'operazione?
confirm: Sì, interrompi
cancel: No, torna indietro
methodType:
fastPayPalPayment: Pagamento veloce con PayPal
methodSelection:
header: Seleziona un metodo
yourMethods: Saved
Expand Down
2 changes: 2 additions & 0 deletions locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,8 @@ wallet:
title: Vuoi interrompere l'operazione?
confirm: Sì, interrompi
cancel: No, torna indietro
methodType:
fastPayPalPayment: Pagamento veloce con PayPal
methodSelection:
header: Seleziona un metodo
yourMethods: Salvati
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"services_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_services_app_backend.yaml",
"lollipop_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_lollipop_first_consumer.yaml",
"fast_login_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/openapi/generated/api_fast_login.yaml",
"pagopa_api_walletv3": "https://raw.githubusercontent.com/pagopa/pagopa-infra/95477f43e87016a979d26b5a81eee32c308af96d/src/domains/wallet-app/api/payment-wallet/v1/_openapi.json.tpl",
"pagopa_api_ecommerce": "https://raw.githubusercontent.com/pagopa/pagopa-infra/95477f43e87016a979d26b5a81eee32c308af96d/src/domains/ecommerce-app/api/ecommerce-io/v1/_openapi.json.tpl",
"pagopa_api_walletv3": "https://raw.githubusercontent.com/pagopa/pagopa-infra/4ecc4c41f0a0692361d6d93ab7481a22c99bc21d/src/domains/wallet-app/api/payment-wallet/v1/_openapi.json.tpl",
"pagopa_api_ecommerce": "https://raw.githubusercontent.com/pagopa/pagopa-infra/4ecc4c41f0a0692361d6d93ab7481a22c99bc21d/src/domains/ecommerce-app/api/ecommerce-io/v1/_openapi.json.tpl",
"trial_system": "https://raw.githubusercontent.com/pagopa/io-backend/features/add-openapi-trial-service/api_trial_system.yaml",
"private": true,
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,16 @@ const mapUserWalletToRadioItem = (
startImage
};
} else if (details.maskedEmail !== undefined) {
const details = method.details as UIWalletInfoDetails;
const description =
details.pspBusinessName && details.maskedEmail
? `${details.pspBusinessName} · ${details.maskedEmail}`
: undefined;
return {
id: method.walletId,
value: "PayPal",
startImage
value: I18n.t("wallet.payment.methodType.fastPayPalPayment"),
startImage,
description
};
} else if (details.maskedNumber !== undefined) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getGenericError } from "../../../../../../utils/errors";
import { readablePrivacyReport } from "../../../../../../utils/reporters";
import { WalletStatusEnum } from "../../../../../../../definitions/pagopa/ecommerce/WalletStatus";
import { selectWalletPaymentSessionToken } from "../../../store/selectors";
import { WalletClientStatusEnum } from "../../../../../../../definitions/pagopa/ecommerce/WalletClientStatus";

describe("Test handleWalletPaymentGetUserWallets saga", () => {
const T_SESSION_TOKEN = "ABCD";
Expand All @@ -25,6 +26,12 @@ describe("Test handleWalletPaymentGetUserWallets saga", () => {
paymentMethodId: "paymentMethodId",
paymentMethodAsset: "paymentMethodAsset",
applications: [],
clients: {
IO: {
status: WalletClientStatusEnum.ENABLED,
lastUsage: new Date()
}
},
status: WalletStatusEnum.VALIDATED,
updateDate: new Date()
}
Expand Down
8 changes: 4 additions & 4 deletions ts/features/payments/checkout/store/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
selectPaymentPspAction,
walletPaymentSetCurrentStep
} from "../actions/orchestration";
import { getLatestUsedWallet } from "../../utils";
export const WALLET_PAYMENT_STEP_MAX = 4;

export type PaymentsCheckoutState = {
Expand Down Expand Up @@ -132,10 +133,9 @@ const reducer = (
return {
...state,
userWallets: pot.some(action.payload),
selectedWallet: O.fromNullable(
action.payload?.wallets?.reduce((acc, curr) =>
acc.updateDate > curr.updateDate ? acc : curr
)
selectedWallet: pipe(
O.fromNullable(action.payload.wallets),
O.chain(getLatestUsedWallet)
)
};
case getType(paymentsGetPaymentUserMethodsAction.failure):
Expand Down
12 changes: 2 additions & 10 deletions ts/features/payments/checkout/store/selectors/paymentMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as O from "fp-ts/lib/Option";
import { pipe } from "fp-ts/lib/function";
import { createSelector } from "reselect";
import { PaymentMethodsResponse } from "../../../../../../definitions/pagopa/ecommerce/PaymentMethodsResponse";
import { isValidPaymentMethod } from "../../utils";
import { getLatestUsedWallet, isValidPaymentMethod } from "../../utils";
import { Wallets } from "../../../../../../definitions/pagopa/ecommerce/Wallets";
import { selectPaymentsCheckoutState, walletPaymentDetailsSelector } from ".";

Expand All @@ -17,15 +17,7 @@ export const walletPaymentUserWalletsSelector = createSelector(
export const walletPaymentUserWalletLastUpdatedSelector = createSelector(
walletPaymentUserWalletsSelector,
userWalletsPot =>
pipe(
userWalletsPot,
pot.toOption,
O.map(userWallets =>
userWallets.reduce((acc, curr) =>
acc.updateDate > curr.updateDate ? acc : curr
)
)
)
pipe(userWalletsPot, pot.toOption, O.chain(getLatestUsedWallet))
);

export const walletPaymentAllMethodsSelector = createSelector(
Expand Down
23 changes: 23 additions & 0 deletions ts/features/payments/checkout/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as RA from "fp-ts/lib/ReadonlyArray";
import * as O from "fp-ts/lib/Option";
import { pipe } from "fp-ts/lib/function";
import { PaymentMethodManagementTypeEnum } from "../../../../../definitions/pagopa/ecommerce/PaymentMethodManagementType";
import { PaymentMethodResponse } from "../../../../../definitions/pagopa/ecommerce/PaymentMethodResponse";
import { WalletInfo } from "../../../../../definitions/pagopa/ecommerce/WalletInfo";
import { WalletClientStatusEnum } from "../../../../../definitions/pagopa/walletv3/WalletClientStatus";

export const WALLET_PAYMENT_FEEDBACK_URL =
"https://io.italia.it/diccilatua/ces-pagamento";
Expand All @@ -9,3 +14,21 @@ export const isValidPaymentMethod = (method: PaymentMethodResponse) =>
method.methodManagement === PaymentMethodManagementTypeEnum.NOT_ONBOARDABLE ||
method.methodManagement ===
PaymentMethodManagementTypeEnum.ONBOARDABLE_WITH_PAYMENT;

export const getLatestUsedWallet = (
wallets: ReadonlyArray<WalletInfo>
): O.Option<WalletInfo> =>
pipe(
wallets,
RA.filter(
wallet => wallet.clients.IO.status === WalletClientStatusEnum.ENABLED
),
RA.reduce<WalletInfo, WalletInfo | undefined>(undefined, (acc, curr) =>
acc?.clients.IO?.lastUsage &&
curr.clients.IO?.lastUsage &&
acc.clients.IO.lastUsage > curr.clients.IO.lastUsage
? acc
: curr
),
O.fromNullable
);

0 comments on commit 5d017f9

Please sign in to comment.