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,
|
||||
SetupRequired,
|
||||
} from '@woocommerce/onboarding';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
import { Action } from '../Action';
|
||||
import { connectWcpay } from './utils';
|
||||
|
||||
const TosPrompt = () =>
|
||||
interpolateComponents( {
|
||||
|
@ -47,6 +49,18 @@ export const Suggestion = ( { paymentGateway, onSetupCallback = null } ) => {
|
|||
installed: isInstalled,
|
||||
} = 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 (
|
||||
<WCPayCard>
|
||||
<WCPayCardHeader>
|
||||
|
|
|
@ -11,37 +11,40 @@ import { recordEvent } from '@woocommerce/tracks';
|
|||
*/
|
||||
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(
|
||||
reject,
|
||||
createNotice,
|
||||
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' ] )
|
||||
.then( () => {
|
||||
recordEvent( 'woocommerce_payments_install', {
|
||||
context: 'tasklist',
|
||||
} );
|
||||
|
||||
connect();
|
||||
connectWcpay( createNotice, () => {
|
||||
reject();
|
||||
} );
|
||||
} )
|
||||
.catch( ( error ) => {
|
||||
createNoticesFromResponse( error );
|
||||
|
|
Loading…
Reference in New Issue