APM-13: Add online banking account form (#91)

This commit is contained in:
Ildar Galeev 2022-05-06 15:02:59 +03:00 committed by GitHub
parent 453fa4fb51
commit 4d4f1a8315
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,10 +4,18 @@ import { Method } from '../method';
import { Title } from '../title';
import { Text } from '../text';
import { Icon } from '../icon/icon';
import { FormName, KnownProviderCategories, OnlineBankingFormInfo, PaymentTerminalPaymentMethod } from 'checkout/state';
import {
FormName,
KnownProviderCategories,
OnlineBankingAccountFormInfo,
OnlineBankingFormInfo,
PaymentTerminalPaymentMethod
} from 'checkout/state';
import { Locale } from 'checkout/locale';
import { PayAction, SetFormInfoAction } from './types';
import { payWithPaymentTerminal } from './pay-with-payment-terminal';
import { getMetadata } from 'checkout/components/ui';
import { ServiceProvider } from 'checkout/backend';
interface OnlineBankingProps {
method: PaymentTerminalPaymentMethod;
@ -19,14 +27,23 @@ interface OnlineBankingProps {
const toOnlineBanking = (category: KnownProviderCategories, setFormInfo: SetFormInfoAction) =>
setFormInfo(new OnlineBankingFormInfo(category, FormName.paymentMethods));
const toOnlineBankingAccount = (serviceProvider: ServiceProvider, setFormInfo: SetFormInfoAction) =>
setFormInfo(new OnlineBankingAccountFormInfo(serviceProvider));
const provideMethod = (
{ serviceProviders, category }: PaymentTerminalPaymentMethod,
pay: PayAction,
setFormInfo: SetFormInfoAction
) =>
serviceProviders.length === 1
? payWithPaymentTerminal(serviceProviders[0].id, pay)
: toOnlineBanking(category, setFormInfo);
) => {
if (serviceProviders.length === 1) {
const provider = serviceProviders[0];
const { form } = getMetadata(provider);
return form
? toOnlineBankingAccount(provider, setFormInfo)
: payWithPaymentTerminal(serviceProviders[0].id, pay);
}
return toOnlineBanking(category, setFormInfo);
};
const getTitle = (l: Locale, category: KnownProviderCategories) => l[`form.payment.method.name.${category}.label`];