Redirect to the WC Pay onboarding when WC Pay is installed (https://github.com/woocommerce/woocommerce-admin/pull/8367)
* Redirect to the connect page when WC Pay is installed * Add comment
This commit is contained in:
parent
a2dfbffe89
commit
3e672d7664
|
@ -13,12 +13,14 @@ import {
|
||||||
WCPayCardBody,
|
WCPayCardBody,
|
||||||
SetupRequired,
|
SetupRequired,
|
||||||
} from '@woocommerce/onboarding';
|
} from '@woocommerce/onboarding';
|
||||||
|
import { useDispatch } from '@wordpress/data';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Action } from '../Action';
|
import { Action } from '../Action';
|
||||||
|
import { connectWcpay } from './utils';
|
||||||
|
|
||||||
const TosPrompt = () =>
|
const TosPrompt = () =>
|
||||||
interpolateComponents( {
|
interpolateComponents( {
|
||||||
|
@ -47,6 +49,18 @@ export const Suggestion = ( { paymentGateway, onSetupCallback = null } ) => {
|
||||||
installed: isInstalled,
|
installed: isInstalled,
|
||||||
} = paymentGateway;
|
} = paymentGateway;
|
||||||
|
|
||||||
|
const { createNotice } = useDispatch( 'core/notices' );
|
||||||
|
// When the WC Pay is installed and onSetupCallback is null
|
||||||
|
// Overwrite onSetupCallback to redirect to the setup page
|
||||||
|
// when the user clicks on the "Finish setup" button.
|
||||||
|
// WC Pay doesn't need to be configured in WCA.
|
||||||
|
// It should be configured in its onboarding flow.
|
||||||
|
if ( installed && onSetupCallback === null ) {
|
||||||
|
onSetupCallback = () => {
|
||||||
|
connectWcpay( createNotice );
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WCPayCard>
|
<WCPayCard>
|
||||||
<WCPayCardHeader>
|
<WCPayCardHeader>
|
||||||
|
|
|
@ -11,37 +11,40 @@ import { recordEvent } from '@woocommerce/tracks';
|
||||||
*/
|
*/
|
||||||
import { createNoticesFromResponse } from '~/lib/notices';
|
import { createNoticesFromResponse } from '~/lib/notices';
|
||||||
|
|
||||||
|
export function connectWcpay( createNotice, onCatch ) {
|
||||||
|
const errorMessage = __(
|
||||||
|
'There was an error connecting to WooCommerce Payments. Please try again or connect later in store settings.',
|
||||||
|
'woocommerce-admin'
|
||||||
|
);
|
||||||
|
apiFetch( {
|
||||||
|
path: WC_ADMIN_NAMESPACE + '/plugins/connect-wcpay',
|
||||||
|
method: 'POST',
|
||||||
|
} )
|
||||||
|
.then( ( response ) => {
|
||||||
|
window.location = response.connectUrl;
|
||||||
|
} )
|
||||||
|
.catch( () => {
|
||||||
|
createNotice( 'error', errorMessage );
|
||||||
|
if ( typeof onCatch === 'function' ) {
|
||||||
|
onCatch();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
export function installActivateAndConnectWcpay(
|
export function installActivateAndConnectWcpay(
|
||||||
reject,
|
reject,
|
||||||
createNotice,
|
createNotice,
|
||||||
installAndActivatePlugins
|
installAndActivatePlugins
|
||||||
) {
|
) {
|
||||||
const errorMessage = __(
|
|
||||||
'There was an error connecting to WooCommerce Payments. Please try again or connect later in store settings.',
|
|
||||||
'woocommerce-admin'
|
|
||||||
);
|
|
||||||
|
|
||||||
const connect = () => {
|
|
||||||
apiFetch( {
|
|
||||||
path: WC_ADMIN_NAMESPACE + '/plugins/connect-wcpay',
|
|
||||||
method: 'POST',
|
|
||||||
} )
|
|
||||||
.then( ( response ) => {
|
|
||||||
window.location = response.connectUrl;
|
|
||||||
} )
|
|
||||||
.catch( () => {
|
|
||||||
createNotice( 'error', errorMessage );
|
|
||||||
reject();
|
|
||||||
} );
|
|
||||||
};
|
|
||||||
|
|
||||||
installAndActivatePlugins( [ 'woocommerce-payments' ] )
|
installAndActivatePlugins( [ 'woocommerce-payments' ] )
|
||||||
.then( () => {
|
.then( () => {
|
||||||
recordEvent( 'woocommerce_payments_install', {
|
recordEvent( 'woocommerce_payments_install', {
|
||||||
context: 'tasklist',
|
context: 'tasklist',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
connect();
|
connectWcpay( createNotice, () => {
|
||||||
|
reject();
|
||||||
|
} );
|
||||||
} )
|
} )
|
||||||
.catch( ( error ) => {
|
.catch( ( error ) => {
|
||||||
createNoticesFromResponse( error );
|
createNoticesFromResponse( error );
|
||||||
|
|
Loading…
Reference in New Issue