woocommerce/plugins/woocommerce-admin/client/payments/payment-recommendations-ban...

177 lines
4.0 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';
/**
* 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 04:28:31 +00:00
import Banner from './banner';
2022-04-06 16:38:38 +00:00
import './payment-recommendations.scss';
2022-04-19 08:07:07 +00:00
export const PaymentMethods = () => (
<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">
<Banner />
</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-19 08:07:07 +00:00
<PaymentMethods />
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
export const PaymentsRecommendationsBanner = () => {
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 04:28:31 +00:00
const isWcPayEnabled = installedPaymentGateways.find(
( gateway: PaymentGateway ) => {
return (
gateway.id === 'woocommerce_payments' &&
gateway.enabled === true
);
}
);
2022-04-19 08:07:07 +00:00
const isWcPayBannerExplat = true;
if ( ! isResolving ) {
if (
supportsWCPayments &&
isWcPayInstalled &&
! isWcPayEnabled &&
isWcPayBannerExplat
) {
2022-04-20 04:28:31 +00:00
// add tracks event here
2022-04-19 08:07:07 +00:00
return <WcPayBanner />;
}
2022-04-20 04:28:31 +00:00
// add tracks event here because we want to know when the control is shown
2022-04-19 08:07:07 +00:00
}
2022-04-20 04:28:31 +00:00
return null;
2022-04-19 08:07:07 +00:00
};