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

178 lines
4.1 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,
Plugin,
PaymentGateway,
WCDataSelector,
} from '@woocommerce/data';
import { useSelect } from '@wordpress/data';
2022-04-20 07:29:29 +00:00
import { useExperiment } from '@woocommerce/explat';
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';
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 =
'./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
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(),
};
} );
const supportsWCPayments =
paymentGatewaySuggestions &&
2022-04-20 04:28:31 +00:00
paymentGatewaySuggestions.filter(
( paymentGatewaySuggestion: Plugin ) => {
return (
paymentGatewaySuggestion.id.indexOf(
'woocommerce_payments'
) === 0
);
}
).length === 1;
2022-04-19 08:07:07 +00:00
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-20 07:29:29 +00:00
const [ isLoadingExperiment, experimentAssignment ] = useExperiment(
'woocommerce_payments_settings_banner_2022_04'
);
if ( ! isResolving && ! isLoadingExperiment ) {
2022-04-19 08:07:07 +00:00
if (
supportsWCPayments &&
isWcPayInstalled &&
2022-04-20 07:29:29 +00:00
isWcPayDisabled &&
experimentAssignment?.variationName === 'treatment'
2022-04-19 08:07:07 +00:00
) {
return <WcPayBanner />;
}
}
2022-04-20 04:28:31 +00:00
return null;
2022-04-19 08:07:07 +00:00
};