* Mark stripe as enabled by default in supported countries, and link completed task to payment settings

* Update stripe supported code to pull from server side list

* Remove dependence on core method
This commit is contained in:
Justin Shreve 2019-10-29 14:03:07 -04:00 committed by GitHub
parent c70143ccf8
commit 1aea9d7bd7
4 changed files with 49 additions and 25 deletions

View File

@ -158,7 +158,11 @@ class TaskDashboard extends Component {
<i className="material-icons-outlined">{ task.icon }</i>
);
task.after = <i className="material-icons-outlined">chevron_right</i>;
task.onClick = () => updateQueryString( { task: task.key } );
if ( ! task.onClick ) {
task.onClick = () => updateQueryString( { task: task.key } );
}
return task;
} );

View File

@ -12,6 +12,7 @@ import { get } from 'lodash';
* WooCommerce dependencies
*/
import { getSetting } from '@woocommerce/wc-admin-settings';
import { updateQueryString, getAdminLink } from '@woocommerce/navigation';
/**
* Internal dependencies
@ -113,6 +114,13 @@ export function getTasks( { profileItems, options, query } ) {
icon: 'payment',
container: <Payments />,
completed: paymentsCompleted,
onClick: () => {
if ( paymentsCompleted ) {
window.location = getAdminLink( 'admin.php?page=wc-settings&tab=checkout' );
return;
}
updateQueryString( { task: 'payments' } );
},
visible: true,
},
];

View File

@ -16,7 +16,7 @@ import { withDispatch } from '@wordpress/data';
*/
import { Form, Card, Stepper, TextControl, List } from '@woocommerce/components';
import { getAdminLink, getHistory, getNewPath } from '@woocommerce/navigation';
import { WC_ASSET_URL as wcAssetUrl } from '@woocommerce/wc-admin-settings';
import { WC_ASSET_URL as wcAssetUrl, getSetting } from '@woocommerce/wc-admin-settings';
/**
* Internal dependencies
@ -97,9 +97,16 @@ class Payments extends Component {
getHistory().push( getNewPath( {}, '/', {} ) );
}
isStripeEnabled() {
const { countryCode } = this.props;
const stripeCountries = getSetting( 'onboarding', { stripeSupportedCountries: [] } )
.stripeSupportedCountries;
return stripeCountries.includes( countryCode );
}
getInitialValues() {
const values = {
stripe: false,
stripe: this.isStripeEnabled(),
paypal: false,
klarna_checkout: false,
klarna_payments: false,
@ -213,7 +220,7 @@ class Payments extends Component {
),
before: <img src={ wcAssetUrl + 'images/stripe.png' } alt="" />,
after: <FormToggle { ...getInputProps( 'stripe' ) } />,
visible: true,
visible: this.isStripeEnabled(),
},
{
key: 'paypal',
@ -451,7 +458,6 @@ class Payments extends Component {
render() {
const { step, methodRequestPending } = this.state;
const { isSettingsRequesting } = this.props;
return (
<Form
initialValues={ this.getInitialValues() }
@ -465,7 +471,7 @@ class Payments extends Component {
<Card className="is-narrow">
<Stepper
isVertical
isPending={ methodRequestPending || isSettingsRequesting || 'install' === step }
isPending={ methodRequestPending || 'install' === step }
currentStep={ step }
steps={ this.getSteps() }
/>
@ -480,22 +486,15 @@ class Payments extends Component {
export default compose(
withSelect( select => {
const {
getSettings,
getSettingsError,
isGetSettingsRequesting,
getProfileItems,
isJetpackConnected,
getActivePlugins,
getOptions,
} = select( 'wc-api' );
const { getProfileItems, isJetpackConnected, getActivePlugins, getOptions } = select(
'wc-api'
);
const settings = getSettings( 'general' );
const isSettingsError = Boolean( getSettingsError( 'general' ) );
const isSettingsRequesting = isGetSettingsRequesting( 'general' );
const countryCode = getCountryCode( settings.woocommerce_default_country );
const options = getOptions( [ 'woocommerce_onboarding_payments' ] );
const options = getOptions( [
'woocommerce_onboarding_payments',
'woocommerce_default_country',
] );
const countryCode = getCountryCode( options.woocommerce_default_country );
const methods = get( options, [ 'woocommerce_onboarding_payments', 'methods' ], [] );
const installed = get( options, [ 'woocommerce_onboarding_payments', 'installed' ], false );
@ -505,9 +504,6 @@ export default compose(
return {
countryCode,
isSettingsError,
isSettingsRequesting,
settings,
profileItems: getProfileItems(),
activePlugins: getActivePlugins(),
isJetpackConnected: isJetpackConnected(),

View File

@ -344,7 +344,8 @@ class Onboarding {
// Only fetch if the onboarding wizard OR the task list is incomplete.
if ( self::should_show_profiler() || self::should_show_tasks() ) {
$settings['onboarding']['activePlugins'] = self::get_active_plugins();
$settings['onboarding']['activePlugins'] = self::get_active_plugins();
$settings['onboarding']['stripeSupportedCountries'] = self::get_stripe_supported_countries();
}
return $settings;
@ -368,6 +369,7 @@ class Onboarding {
$options[] = 'woocommerce_onboarding_payments';
$options[] = 'woocommerce_allow_tracking';
$options[] = 'woocommerce_stripe_settings';
$options[] = 'woocommerce_default_country';
return $options;
}
@ -386,6 +388,20 @@ class Onboarding {
return $endpoints;
}
/**
* Returns a list of Stripe supported countries. This method can be removed once merged to core.
*
* @param array $endpoints Array of preloaded endpoints.
* @return array
*/
private static function get_stripe_supported_countries() {
// https://stripe.com/global.
return array(
'AU', 'AT', 'BE', 'CA', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HK', 'IE', 'IT', 'JP', 'LV', 'LT', 'LU', 'MY', 'NL', 'NZ', 'NO',
'PL', 'PT', 'SG', 'SK', 'SI', 'ES', 'SE', 'CH', 'GB', 'US',
);
}
/**
* Gets an array of plugins that can be installed & activated via the onboarding wizard.
*