Redirect to WooPayments Connect page in the Payments task (#45540)

* Add get_action_url for Payments task

* Check if plugin active before redirecting to connect page

* Add changelog

* Fix linting issues

* Point payments task to welcome page when WCPay incentive active

* Point WooPayments installed task to Connect page

* Rename WooPayments to payments

* Add from query arg

* Adjust payments task URL logic to account for suggestions logic

* Fix for partially onboarded accounts

* Replace Get paid with WooPayments

* Add new test for unsupported countries

* Add missing api definition

* Add missing baseURL

* Maybe change order of tests to fix failing test

* Revert changes to package.json (error in push)

---------

Co-authored-by: Vlad Olaru <vlad@pixelgrade.com>
Co-authored-by: oaratovskyi <oleksandr.aratovskyi@automattic.com>
This commit is contained in:
Ahmed 2024-03-15 12:08:04 +00:00 committed by GitHub
parent d9013d4737
commit ed3aab14cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 88 additions and 16 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Redirect to WooPayments Connect page in the Payments task if the merchant is from a supported country and WooPayments is installed

View File

@ -592,25 +592,22 @@ class Plugins extends \WC_REST_Data_Controller {
}
/**
* Returns a URL that can be used to by WCPay to verify business details with Stripe.
* Returns a URL that can be used to by WCPay to verify business details.
*
* @return WP_Error|array Connect URL.
*/
public function connect_wcpay() {
if ( ! class_exists( 'WC_Payments_Account' ) ) {
if ( ! class_exists( 'WC_Payments' ) ) {
return new \WP_Error( 'woocommerce_rest_helper_connect', __( 'There was an error communicating with the WooPayments plugin.', 'woocommerce' ), 500 );
}
$args = WooCommercePayments::is_account_partially_onboarded() ? [
'wcpay-login' => '1',
'_wpnonce' => wp_create_nonce( 'wcpay-login' ),
] : [
'wcpay-connect' => 'WCADMIN_PAYMENT_TASK',
'_wpnonce' => wp_create_nonce( 'wcpay-connect' ),
];
// Redirect to the WooPayments overview page if the merchant started onboarding but left KYC immediately.
// Redirect to the connect page if they haven't started onboarding.
$path = WooCommercePayments::is_account_partially_onboarded() ? '/payments/overview' : '/payments/connect';
// Point to the WooPayments Connect page rather than straight to the onboarding flow.
return( array(
'connectUrl' => add_query_arg( $args, admin_url() ),
'connectUrl' => add_query_arg( 'from', 'WCADMIN_PAYMENT_TASK', admin_url( 'admin.php?page=wc-admin&path=' . $path ) ),
) );
}

View File

@ -4,6 +4,7 @@ namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks;
use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
use Automattic\WooCommerce\Internal\Admin\WcPayWelcomePage;
/**
* Payments Task
@ -12,6 +13,7 @@ class Payments extends Task {
/**
* Used to cache is_complete() method result.
*
* @var null
*/
private $is_complete_result = null;
@ -94,4 +96,25 @@ class Payments extends Task {
return ! empty( $enabled_gateways );
}
/**
* Action URL.
*
* @return string
*/
public function get_action_url() {
// Check if the WooPayments plugin is active and the store is supported.
if ( WooCommercePayments::is_supported() && WooCommercePayments::is_wcpay_active() ) {
// Point to the WooPayments Connect page.
return add_query_arg( 'from', 'WCADMIN_PAYMENT_TASK', admin_url( 'admin.php?page=wc-admin&path=/payments/connect' ) );
}
// Check if there is an active WooPayments incentive via the welcome page.
if ( WcPayWelcomePage::instance()->must_be_visible() ) {
// Point to the WooPayments welcome page.
return add_query_arg( 'from', 'WCADMIN_PAYMENT_TASK', admin_url( 'admin.php?page=wc-admin&path=/wc-pay-welcome-page' ) );
}
return admin_url( 'admin.php?page=wc-admin&task=payments' );
}
}

View File

@ -109,7 +109,7 @@ class WooCommercePayments extends Task {
}
/**
* Check if the plugin was requested during onboarding.
* Check if the WooPayments plugin was requested during onboarding.
*
* @return bool
*/
@ -123,7 +123,7 @@ class WooCommercePayments extends Task {
}
/**
* Check if the plugin is installed.
* Check if the WooPayments plugin is installed.
*
* @return bool
*/
@ -133,7 +133,16 @@ class WooCommercePayments extends Task {
}
/**
* Check if WooCommerce Payments is connected.
* Check if the WooPayments plugin is active.
*
* @return bool
*/
public static function is_wcpay_active() {
return class_exists( '\WC_Payments' );
}
/**
* Check if WooPayments is connected.
*
* @return bool
*/
@ -149,7 +158,7 @@ class WooCommercePayments extends Task {
}
/**
* Check if WooCommerce Payments needs setup.
* Check if WooPayments needs setup.
* Errored data or payments not enabled.
*
* @return bool

View File

@ -30,14 +30,14 @@ test.describe( 'Payment setup task', () => {
} );
} );
test( 'Can visit the payment setup task from the homescreen if the setup wizard has been skipped', async ( {
test( 'Can visit the WooPayments Connect page instead of setup task for supported countries', async ( {
page,
} ) => {
await page.goto( 'wp-admin/admin.php?page=wc-admin' );
await page.locator( 'text=Get paid' ).click();
await expect(
page.locator( '.woocommerce-layout__header-wrapper > h1' )
).toHaveText( 'Get paid' );
).toHaveText( 'WooPayments' );
} );
test( 'Saving valid bank account transfer details enables the payment method', async ( {
@ -85,6 +85,45 @@ test.describe( 'Payment setup task', () => {
).toHaveClass( 'wc-payment-gateway-method-toggle-enabled' );
} );
test( 'Can visit the payment setup task from the homescreen if the setup wizard has been skipped', async ( {
baseURL,
page,
} ) => {
const api = new wcApi( {
url: baseURL,
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
version: 'wc/v3',
} );
// ensure store address is a non supported country
await api.post( 'settings/general/batch', {
update: [
{
id: 'woocommerce_store_address',
value: 'addr 1',
},
{
id: 'woocommerce_store_city',
value: 'San Francisco',
},
{
id: 'woocommerce_default_country',
// Morocco: Unsupported country:region
value: 'MA:maagd',
},
{
id: 'woocommerce_store_postcode',
value: '80000',
},
],
} );
await page.goto( 'wp-admin/admin.php?page=wc-admin' );
await page.locator( 'text=Get paid' ).click();
await expect(
page.locator( '.woocommerce-layout__header-wrapper > h1' )
).toHaveText( 'Get paid' );
} );
test( 'Enabling cash on delivery enables the payment method', async ( {
page,
baseURL,