Add is_offline flag and split payment sections

This commit is contained in:
Ilyas Foo 2022-03-31 12:23:26 +08:00
parent 73409592b7
commit fd4a4a5604
4 changed files with 24 additions and 5 deletions

View File

@ -39,6 +39,7 @@ export type Plugin = {
recommendation_priority?: number;
is_visible?: boolean;
is_local_partner?: boolean;
is_offline?: boolean;
};
type PaypalOnboardingState = 'unknown' | 'start' | 'progressive' | 'onboarded';

View File

@ -179,7 +179,7 @@ export const PaymentGatewaySuggestions = ( { onComplete, query } ) => {
return gateway;
}, [ isResolving, query, paymentGateways ] );
const [ wcPayGateway, enabledGateways, additionalGateways ] = useMemo(
const [ wcPayGateway, enabledGateways, offlineGateways, additionalGateways ] = useMemo(
() =>
Array.from( paymentGateways.values() )
.sort( ( a, b ) => {
@ -196,7 +196,7 @@ export const PaymentGatewaySuggestions = ( { onComplete, query } ) => {
} )
.reduce(
( all, gateway ) => {
const [ wcPay, enabled, additional ] = all;
const [ wcPay, enabled, offline, additional ] = all;
// WCPay is handled separately when not installed and configured
if (
@ -207,13 +207,15 @@ export const PaymentGatewaySuggestions = ( { onComplete, query } ) => {
wcPay.push( gateway );
} else if ( gateway.enabled ) {
enabled.push( gateway );
} else if ( gateway.is_offline ) {
offline.push( gateway );
} else {
additional.push( gateway );
}
return all;
},
[ [], [], [] ]
[ [], [], [], [] ]
),
[ paymentGateways ]
);
@ -250,14 +252,26 @@ export const PaymentGatewaySuggestions = ( { onComplete, query } ) => {
{ !! additionalGateways.length && (
<List
heading={ __(
'Additional payment gateways',
'woocommerce'
'Choose a payment provider',
'woocommerce-admin'
) }
recommendation={ recommendation }
paymentGateways={ additionalGateways }
markConfigured={ markConfigured }
/>
) }
{ !! offlineGateways.length && (
<List
heading={ __(
'Offline payment methods',
'woocommerce-admin'
) }
recommendation={ recommendation }
paymentGateways={ offlineGateways }
markConfigured={ markConfigured }
/>
) }
</div>
);
};

View File

@ -49,6 +49,7 @@ const paymentGatewaySuggestions = [
image:
'http://localhost:8888/wp-content/plugins/woocommerce-admin/images/onboarding/cod.svg',
is_visible: true,
is_offline: true,
},
{
id: 'bacs',
@ -57,6 +58,7 @@ const paymentGatewaySuggestions = [
image:
'http://localhost:8888/wp-content/plugins/woocommerce-admin/images/onboarding/bacs.svg',
is_visible: true,
is_offline: true,
},
{
id: 'woocommerce_payments:non-us',

View File

@ -198,6 +198,7 @@ class DefaultPaymentGateways {
'is_visible' => array(
self::get_rules_for_cbd( false ),
),
'is_offline' => true,
),
array(
'id' => 'bacs',
@ -207,6 +208,7 @@ class DefaultPaymentGateways {
'is_visible' => array(
self::get_rules_for_cbd( false ),
),
'is_offline' => true,
),
array(
'id' => 'woocommerce_payments',