Skip to content

Commit

Permalink
chore: [IOBP-690] Add pre-selection psp logic for payment methods wit…
Browse files Browse the repository at this point in the history
…h pspId indicated (#5838)

## Short description
This PR adds automatic pre-selected PSP selection logic in the past (in
this case useful for PayPal fast payment method). If the get user
wallets returns us a wallet with an indicated pspId, it means that in
the calculateFees if that method is selected, only that id needs to be
sent to the `idPspList`.

## List of changes proposed in this pull request
- Added a logic to select the pspId from the user wallet if present and
send it to the calculateFees request action

## How to test
- Checkout this dev-server PR:
pagopa/io-dev-api-server#386
- If you select "Pagamento veloce con PayPal" from the payment method
selection list, you should be able to navigate directly to the payment
confirm screen.

## Preview


https://github.com/pagopa/io-app/assets/34343582/feb88ba2-2559-4888-8d86-660eb1800882
  • Loading branch information
Hantex9 authored Jun 10, 2024
1 parent 592673a commit e654f6f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ export function* handleWalletPaymentCalculateFees(
return;
}

const { paymentMethodId, ...body } = { ...action.payload, language };
const { paymentMethodId, idPsp, ...body } = { ...action.payload, language };
const calculateFeesRequest = calculateFees({
eCommerceSessionToken: sessionToken,
id: paymentMethodId,
body
body: {
...body,
idPspList: idPsp ? [idPsp] : body.idPspList
}
});

const calculateFeesResult = (yield* call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
} from "../store/selectors/transaction";
import { WalletPaymentOutcomeEnum } from "../types/PaymentOutcomeEnum";
import { paymentsInitOnboardingWithRptIdToResume } from "../../onboarding/store/actions";
import { UIWalletInfoDetails } from "../../common/types/UIWalletInfoDetails";

const WalletPaymentPickMethodScreen = () => {
const dispatch = useIODispatch();
Expand Down Expand Up @@ -114,6 +115,18 @@ const WalletPaymentPickMethodScreen = () => {
// In case of guest payment walletId could be undefined
const walletId = O.toUndefined(selectedWalletIdOption);

// In case of an onboarded wallet, it could be present the idPsp that needs to be preselected in the calculateFees request
const idPsp = pipe(
userWalletsPots,
pot.toOption,
O.chainNullableK(wallets =>
wallets.find(wallet => wallet.walletId === walletId)
),
O.chainNullableK(wallet => wallet.details as UIWalletInfoDetails),
O.map(details => details.pspId),
O.getOrElseW(() => undefined)
);

dispatch(
paymentsCalculatePaymentFeesAction.request({
paymentToken,
Expand All @@ -122,7 +135,8 @@ const WalletPaymentPickMethodScreen = () => {
paymentAmount,
transferList,
isAllCCP,
primaryCreditorInstitution
primaryCreditorInstitution,
idPsp
})
);
})
Expand All @@ -132,6 +146,7 @@ const WalletPaymentPickMethodScreen = () => {
dispatch,
paymentAmountPot,
transactionPot,
userWalletsPots,
selectedPaymentMethodIdOption,
selectedWalletIdOption
]);
Expand Down
7 changes: 6 additions & 1 deletion ts/features/payments/checkout/store/actions/networking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ export const paymentsGetPaymentUserMethodsAction = createAsyncAction(
"PAYMENTS_GET_PAYMENT_USER_METHODS_FAILURE"
)<undefined, Wallets, NetworkError>();

export type CalculateFeePayload = {
paymentMethodId: string;
idPsp?: string;
};

export const paymentsCalculatePaymentFeesAction = createAsyncAction(
"PAYMENTS_CALCULATE_PAYMENT_FEES_REQUEST",
"PAYMENTS_CALCULATE_PAYMENT_FEES_SUCCESS",
"PAYMENTS_CALCULATE_PAYMENT_FEES_FAILURE"
)<
CalculateFeeRequest & { paymentMethodId: string },
CalculateFeeRequest & CalculateFeePayload,
CalculateFeeResponse,
NetworkError
>();
Expand Down

0 comments on commit e654f6f

Please sign in to comment.