woocommerce/plugins/woocommerce-admin/client/payments/payment-settings-banner.tsx

185 lines
4.5 KiB
TypeScript
Raw Normal View History

2022-04-20 04:28:31 +00:00
/**
* External dependencies
*/
import { Card, CardFooter, CardBody, Button } from '@wordpress/components';
2022-04-06 16:38:38 +00:00
import { Text } from '@woocommerce/experimental';
import { __ } from '@wordpress/i18n';
2022-04-20 04:28:31 +00:00
import {
ONBOARDING_STORE_NAME,
PAYMENT_GATEWAYS_STORE_NAME,
PaymentGateway,
WCDataSelector,
} from '@woocommerce/data';
import { useSelect } from '@wordpress/data';
2022-04-20 07:29:29 +00:00
import { useExperiment } from '@woocommerce/explat';
import { getAdminLink } from '@woocommerce/settings';
2022-04-26 02:47:01 +00:00
import moment from 'moment';
2022-04-20 04:28:31 +00:00
/**
* Internal dependencies
*/
2022-04-19 08:07:07 +00:00
import {
Visa,
MasterCard,
Amex,
ApplePay,
Giropay,
GooglePay,
CB,
DinersClub,
Discover,
UnionPay,
JCB,
Sofort,
} from '../payments-welcome/cards';
2022-04-20 07:29:29 +00:00
import WCPayBannerImage from './wcpay-banner-image';
2022-04-06 16:38:38 +00:00
import './payment-recommendations.scss';
import { isWcPaySupported } from './utils';
2022-04-06 16:38:38 +00:00
2022-04-20 07:29:29 +00:00
export const PaymentMethodsIcons = () => (
2022-04-19 08:07:07 +00:00
<div className="woocommerce-recommended-payments-banner__footer_icon_container">
<Visa />
<MasterCard />
<Amex />
<ApplePay />
<GooglePay />
<CB />
<Giropay />
<DinersClub />
<Discover />
<UnionPay />
<JCB />
<Sofort />
</div>
);
const WcPayBanner = () => {
const WC_PAY_SETUP_URL = getAdminLink(
'admin.php?page=wc-settings&tab=checkout&section=woocommerce_payments'
);
2022-04-06 16:38:38 +00:00
return (
<Card size="medium" className="woocommerce-recommended-payments-banner">
<CardBody className="woocommerce-recommended-payments-banner__body">
<div className="woocommerce-recommended-payments-banner__image_container">
2022-04-20 07:29:29 +00:00
<WCPayBannerImage />
2022-04-06 16:38:38 +00:00
</div>
<div className="woocommerce-recommended-payments-banner__text_container">
<Text
variant="title.small"
as="p"
size="24"
lineHeight="28px"
padding="0 20px 0 0"
>
{ __(
'Accept Payments and manage your business.',
'woocommerce'
) }
</Text>
<Text
className={
'woocommerce-recommended-payments__header-heading'
}
variant="caption"
as="p"
size="12"
lineHeight="16px"
>
{ __(
'By using WooCommerce Payments you agree to be bound by our Terms of Service and acknowledge that you have read our Privacy Policy',
'woocommerce'
) }
</Text>
2022-04-19 08:07:07 +00:00
<Button href={ WC_PAY_SETUP_URL } isPrimary>
2022-04-06 16:38:38 +00:00
{ __( 'Get started', 'woocommerce' ) }
</Button>
</div>
</CardBody>
<CardFooter className="woocommerce-recommended-payments-banner__footer">
<div>
<Text variant="caption" as="p" size="12" lineHeight="16px">
{ __(
'Accepted payment methods include:',
'woocommerce'
) }
</Text>
</div>
<div>
2022-04-20 07:29:29 +00:00
<PaymentMethodsIcons />
2022-04-06 16:38:38 +00:00
</div>
<div>
<Text variant="caption" as="p" size="12" lineHeight="16px">
{ __( '& more.', 'woocommerce' ) }
</Text>
</div>
</CardFooter>
</Card>
);
};
2022-04-19 08:07:07 +00:00
const DefaultPaymentMethodsHeaderText = () => (
<>
<h2>Payment Methods</h2>
<div id="payment_gateways_options-description">
<p>
Installed payment methods are listed below and can be sorted to
control their display order on the frontend.
</p>
</div>
</>
);
2022-04-20 07:29:29 +00:00
export const PaymentsBannerWrapper = () => {
2022-04-20 04:28:31 +00:00
const {
installedPaymentGateways,
paymentGatewaySuggestions,
isResolving,
} = useSelect( ( select: WCDataSelector ) => {
2022-04-19 08:07:07 +00:00
return {
installedPaymentGateways: select(
PAYMENT_GATEWAYS_STORE_NAME
).getPaymentGateways(),
isResolving: select( ONBOARDING_STORE_NAME ).isResolving(
'getPaymentGatewaySuggestions'
),
paymentGatewaySuggestions: select(
ONBOARDING_STORE_NAME
).getPaymentGatewaySuggestions(),
};
} );
2022-04-20 04:28:31 +00:00
const isWcPayInstalled = installedPaymentGateways.some(
( gateway: PaymentGateway ) => {
return gateway.id === 'woocommerce_payments';
}
);
2022-04-19 08:07:07 +00:00
2022-04-20 07:29:29 +00:00
const isWcPayDisabled = installedPaymentGateways.find(
2022-04-20 04:28:31 +00:00
( gateway: PaymentGateway ) => {
return (
gateway.id === 'woocommerce_payments' &&
2022-04-20 07:29:29 +00:00
gateway.enabled === false
2022-04-20 04:28:31 +00:00
);
}
);
2022-04-19 08:07:07 +00:00
2022-04-26 02:47:01 +00:00
const momentDate = moment().utc();
const year = momentDate.format( 'YYYY' );
const month = momentDate.format( 'MM' );
2022-04-20 07:29:29 +00:00
const [ isLoadingExperiment, experimentAssignment ] = useExperiment(
2022-04-26 02:47:01 +00:00
`woocommerce_payments_settings_banner_${ year }_${ month }`
2022-04-20 07:29:29 +00:00
);
if ( ! isResolving && ! isLoadingExperiment ) {
2022-04-19 08:07:07 +00:00
if (
isWcPaySupported( paymentGatewaySuggestions ) &&
2022-04-19 08:07:07 +00:00
isWcPayInstalled &&
2022-04-20 07:29:29 +00:00
isWcPayDisabled &&
experimentAssignment?.variationName === 'treatment'
2022-04-19 08:07:07 +00:00
) {
return <WcPayBanner />;
}
return <DefaultPaymentMethodsHeaderText />;
2022-04-19 08:07:07 +00:00
}
return <DefaultPaymentMethodsHeaderText />;
2022-04-19 08:07:07 +00:00
};