PaymentModal: Fix checkout terms (#4268)

This commit is contained in:
Alexander Zinchuk 2024-02-23 14:06:30 +01:00
parent 6d21e75efa
commit deede8cb6f
5 changed files with 20 additions and 8 deletions

View File

@ -136,6 +136,7 @@ export async function getPaymentForm(inputInvoice: ApiRequestInputInvoice) {
form: buildApiPaymentForm(result), form: buildApiPaymentForm(result),
invoice: buildApiInvoiceFromForm(result), invoice: buildApiInvoiceFromForm(result),
users: result.users.map(buildApiUser).filter(Boolean), users: result.users.map(buildApiUser).filter(Boolean),
botId: result.botId.toString(),
}; };
} }

View File

@ -3,7 +3,7 @@ import React, { memo, useCallback } from '../../lib/teact/teact';
import { getActions } from '../../global'; import { getActions } from '../../global';
import type { import type {
ApiChat, ApiInvoice, ApiPaymentCredentials, ApiInvoice, ApiPaymentCredentials,
} from '../../api/types'; } from '../../api/types';
import type { FormEditDispatch } from '../../hooks/reducers/usePaymentReducer'; import type { FormEditDispatch } from '../../hooks/reducers/usePaymentReducer';
import type { LangCode, Price } from '../../types'; import type { LangCode, Price } from '../../types';
@ -26,7 +26,6 @@ import Skeleton from '../ui/placeholder/Skeleton';
import styles from './Checkout.module.scss'; import styles from './Checkout.module.scss';
export type OwnProps = { export type OwnProps = {
chat?: ApiChat;
invoice?: ApiInvoice; invoice?: ApiInvoice;
checkoutInfo?: { checkoutInfo?: {
paymentMethod?: string; paymentMethod?: string;
@ -35,6 +34,7 @@ export type OwnProps = {
name?: string; name?: string;
phone?: string; phone?: string;
shippingMethod?: string; shippingMethod?: string;
botName?: string;
}; };
prices?: Price[]; prices?: Price[];
totalPrice?: number; totalPrice?: number;
@ -48,10 +48,10 @@ export type OwnProps = {
onAcceptTos?: (isAccepted: boolean) => void; onAcceptTos?: (isAccepted: boolean) => void;
savedCredentials?: ApiPaymentCredentials[]; savedCredentials?: ApiPaymentCredentials[];
isPaymentFormUrl?: boolean; isPaymentFormUrl?: boolean;
botName?: string;
}; };
const Checkout: FC<OwnProps> = ({ const Checkout: FC<OwnProps> = ({
chat,
invoice, invoice,
prices, prices,
shippingPrices, shippingPrices,
@ -66,6 +66,7 @@ const Checkout: FC<OwnProps> = ({
hasShippingOptions, hasShippingOptions,
savedCredentials, savedCredentials,
isPaymentFormUrl, isPaymentFormUrl,
botName,
}) => { }) => {
const { setPaymentStep } = getActions(); const { setPaymentStep } = getActions();
@ -129,7 +130,7 @@ const Checkout: FC<OwnProps> = ({
} }
function renderTosLink(url: string, isRtl?: boolean) { function renderTosLink(url: string, isRtl?: boolean) {
const langString = lang('PaymentCheckoutAcceptRecurrent', chat?.title); const langString = lang('PaymentCheckoutAcceptRecurrent', botName);
const langStringSplit = langString.split('*'); const langStringSplit = langString.split('*');
return ( return (
<> <>

View File

@ -70,6 +70,7 @@ type StateProps = {
passwordValidUntil?: number; passwordValidUntil?: number;
isExtendedMedia?: boolean; isExtendedMedia?: boolean;
isPaymentFormUrl?: boolean; isPaymentFormUrl?: boolean;
botName?: string;
}; };
type GlobalStateProps = Pick<TabState['payment'], ( type GlobalStateProps = Pick<TabState['payment'], (
@ -83,7 +84,6 @@ const PaymentModal: FC<OwnProps & StateProps & GlobalStateProps> = ({
isOpen, isOpen,
onClose, onClose,
step, step,
chat,
shippingOptions, shippingOptions,
savedInfo, savedInfo,
canSaveCredentials, canSaveCredentials,
@ -113,6 +113,7 @@ const PaymentModal: FC<OwnProps & StateProps & GlobalStateProps> = ({
passwordValidUntil, passwordValidUntil,
isExtendedMedia, isExtendedMedia,
isPaymentFormUrl, isPaymentFormUrl,
botName,
}) => { }) => {
const { const {
loadPasswordInfo, loadPasswordInfo,
@ -292,7 +293,6 @@ const PaymentModal: FC<OwnProps & StateProps & GlobalStateProps> = ({
case PaymentStep.Checkout: case PaymentStep.Checkout:
return ( return (
<Checkout <Checkout
chat={chat}
prices={prices} prices={prices}
dispatch={paymentDispatch} dispatch={paymentDispatch}
shippingPrices={paymentState.shipping && shippingOptions shippingPrices={paymentState.shipping && shippingOptions
@ -309,6 +309,7 @@ const PaymentModal: FC<OwnProps & StateProps & GlobalStateProps> = ({
savedCredentials={savedCredentials} savedCredentials={savedCredentials}
isTosAccepted={isTosAccepted} isTosAccepted={isTosAccepted}
onAcceptTos={setIsTosAccepted} onAcceptTos={setIsTosAccepted}
botName={botName}
/> />
); );
case PaymentStep.SavedPayments: case PaymentStep.SavedPayments:
@ -647,6 +648,7 @@ export default memo(withGlobal<OwnProps>(
temporaryPassword, temporaryPassword,
isExtendedMedia, isExtendedMedia,
url, url,
botName,
} = selectTabState(global).payment; } = selectTabState(global).payment;
let providerName = nativeProvider; let providerName = nativeProvider;
@ -700,6 +702,7 @@ export default memo(withGlobal<OwnProps>(
savedCredentials, savedCredentials,
passwordValidUntil: temporaryPassword?.validUntil, passwordValidUntil: temporaryPassword?.validUntil,
isExtendedMedia, isExtendedMedia,
botName,
}; };
}, },
)(PaymentModal)); )(PaymentModal));

View File

@ -33,6 +33,7 @@ import {
selectSmartGlocalCredentials, selectSmartGlocalCredentials,
selectStripeCredentials, selectStripeCredentials,
selectTabState, selectTabState,
selectUser,
} from '../../selectors'; } from '../../selectors';
addActionHandler('validateRequestedInfo', (global, actions, payload): ActionReturnType => { addActionHandler('validateRequestedInfo', (global, actions, payload): ActionReturnType => {
@ -102,12 +103,17 @@ async function getPaymentForm<T extends GlobalState>(
return undefined; return undefined;
} }
const { form, invoice, users } = result; const {
form, invoice, users, botId,
} = result;
global = getGlobal(); global = getGlobal();
global = addUsers(global, buildCollectionByKey(users, 'id'));
global = setPaymentForm(global, form, tabId); global = setPaymentForm(global, form, tabId);
global = setPaymentStep(global, PaymentStep.Checkout, tabId); global = setPaymentStep(global, PaymentStep.Checkout, tabId);
global = addUsers(global, buildCollectionByKey(users, 'id')); global = updatePayment(global, {
botName: selectUser(global, botId)?.firstName,
}, tabId);
setGlobal(global); setGlobal(global);
return invoice; return invoice;

View File

@ -490,6 +490,7 @@ export type TabState = {
validUntil: number; validUntil: number;
}; };
url?: string; url?: string;
botName?: string;
}; };
chatCreation?: { chatCreation?: {