-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable deferred intent creation when initialization process encounters cache unavailability #7686
Changes from 8 commits
e2a6285
4ed46d9
b623c8f
7869532
5def517
9d8d698
f1d2c51
5306cd8
82fd490
98d6852
e0e85b2
e95b783
73fb1e2
52496de
abc7347
a540e9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: fix | ||
|
||
Enable deferred intent creation when initialization process encounters cache unavailability |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,16 +69,16 @@ class WC_REST_Payments_Settings_Controller_Test extends WCPAY_UnitTestCase { | |
/** | ||
* An array of mocked split UPE payment gateways mapped to payment method ID. | ||
* | ||
* @var array | ||
* @var UPE_Payment_Gateway | ||
*/ | ||
private $mock_upe_payment_gateway; | ||
|
||
/** | ||
* An array of mocked split UPE payment gateways mapped to payment method ID. | ||
* | ||
* @var array | ||
* @var UPE_Split_Payment_Gateway | ||
*/ | ||
private $mock_split_upe_payment_gateways; | ||
private $mock_split_upe_payment_gateway; | ||
|
||
/** | ||
* UPE system under test. | ||
|
@@ -201,7 +201,7 @@ public function set_up() { | |
|
||
$this->upe_controller = new WC_REST_Payments_Settings_Controller( $this->mock_api_client, $this->mock_upe_payment_gateway, $this->mock_wcpay_account ); | ||
|
||
$this->mock_upe_split_payment_gateway = new UPE_Split_Payment_Gateway( | ||
$this->mock_split_upe_payment_gateway = new UPE_Split_Payment_Gateway( | ||
$this->mock_api_client, | ||
$this->mock_wcpay_account, | ||
$customer_service, | ||
|
@@ -216,7 +216,7 @@ public function set_up() { | |
$this->mock_fraud_service | ||
); | ||
|
||
$this->upe_split_controller = new WC_REST_Payments_Settings_Controller( $this->mock_api_client, $this->mock_upe_split_payment_gateway, $this->mock_wcpay_account ); | ||
$this->upe_split_controller = new WC_REST_Payments_Settings_Controller( $this->mock_api_client, $this->mock_split_upe_payment_gateway, $this->mock_wcpay_account ); | ||
|
||
$this->mock_api_client | ||
->method( 'is_server_connected' ) | ||
|
@@ -451,22 +451,14 @@ public function test_upe_update_settings_saves_enabled_payment_methods() { | |
} | ||
|
||
public function test_upe_split_update_settings_saves_enabled_payment_methods() { | ||
$this->mock_upe_split_payment_gateway->update_option( 'upe_enabled_payment_method_ids', [ Payment_Method::CARD ] ); | ||
$this->mock_split_upe_payment_gateway->update_option( 'upe_enabled_payment_method_ids', [ Payment_Method::CARD ] ); | ||
|
||
$request = new WP_REST_Request(); | ||
$request->set_param( 'enabled_payment_method_ids', [ Payment_Method::CARD, Payment_Method::GIROPAY ] ); | ||
|
||
$this->upe_split_controller->update_settings( $request ); | ||
|
||
$this->assertEquals( [ Payment_Method::CARD, Payment_Method::GIROPAY ], $this->mock_upe_split_payment_gateway->get_option( 'upe_enabled_payment_method_ids' ) ); | ||
} | ||
$request = new WP_REST_Request(); | ||
$request->set_param( 'enabled_payment_method_ids', [ Payment_Method::CARD, Payment_Method::GIROPAY ] ); | ||
|
||
public function test_update_settings_validation_fails_if_invalid_gateway_id_supplied() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test was removed because it's an integration test that works only with the legacy gateway. It's not easy nor elegant to mock gateway in Since the tested method relies solely on |
||
$request = new WP_REST_Request( 'POST', self::$settings_route ); | ||
$request->set_param( 'enabled_payment_method_ids', [ 'foo', 'baz' ] ); | ||
$this->upe_split_controller->update_settings( $request ); | ||
|
||
$response = rest_do_request( $request ); | ||
$this->assertEquals( 400, $response->get_status() ); | ||
$this->assertEquals( [ Payment_Method::CARD, Payment_Method::GIROPAY ], $this->mock_split_upe_payment_gateway->get_option( 'upe_enabled_payment_method_ids' ) ); | ||
} | ||
|
||
public function test_update_settings_fails_if_user_cannot_manage_woocommerce() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,21 +59,6 @@ public function test_track_enabled_on_upgrade() { | |
$this->assertSame( '1', get_option( Track_Upe_Status::IS_TRACKED_OPTION ) ); | ||
} | ||
|
||
public function test_track_disabled_on_upgrade() { | ||
update_option( WC_Payments_Features::UPE_FLAG_NAME, 'disabled' ); | ||
|
||
Track_Upe_Status::maybe_track(); | ||
|
||
$this->assertEquals( | ||
[ | ||
'wcpay_upe_disabled' => [], | ||
], | ||
Tracker::get_admin_events() | ||
); | ||
|
||
$this->assertSame( '1', get_option( Track_Upe_Status::IS_TRACKED_OPTION ) ); | ||
} | ||
|
||
Comment on lines
-62
to
-76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to check for |
||
public function test_do_nothing_default_on_upgrade() { | ||
Track_Upe_Status::maybe_track(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,78 +24,6 @@ public function tear_down() { | |
delete_option( '_wcpay_feature_upe' ); | ||
} | ||
|
||
public function test_get_note() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the non-UPE related tests have been removed from this class, since the plugin now executes UPE by default |
||
$note = WC_Payments_Notes_Additional_Payment_Methods::get_note(); | ||
|
||
$this->assertSame( 'Boost your sales by accepting new payment methods', $note->get_title() ); | ||
$this->assertSame( 'Get early access to additional payment methods and an improved checkout experience, coming soon to WooPayments. <a href="https://woo.com/document/woopayments/payment-methods/additional-payment-methods/" target="wcpay_upe_learn_more">Learn more</a>', $note->get_content() ); | ||
$this->assertSame( 'info', $note->get_type() ); | ||
$this->assertSame( 'wc-payments-notes-additional-payment-methods', $note->get_name() ); | ||
$this->assertSame( 'woocommerce-payments', $note->get_source() ); | ||
|
||
list( $enable_upe_action ) = $note->get_actions(); | ||
$this->assertSame( 'wc-payments-notes-additional-payment-methods', $enable_upe_action->name ); | ||
$this->assertSame( 'Enable on your store', $enable_upe_action->label ); | ||
$this->assertStringStartsWith( 'http://example.org/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=woocommerce_payments&action=enable-upe', $enable_upe_action->query ); | ||
|
||
/** | ||
* The $primary property was deprecated from WooCommerce core. Keeping this to maintain the compatibility with old WooCommerce versions. | ||
* @see https://github.com/woocommerce/woocommerce/blob/ff2d7d704a8f72aeb4990811b6972097aa167bea/plugins/woocommerce/src/Admin/Notes/Note.php#L623-L623. | ||
* @see https://github.com/woocommerce/woocommerce-admin/pull/8474 | ||
*/ | ||
if ( isset( $enable_upe_action->primary ) ) { | ||
$this->assertSame( true, $enable_upe_action->primary ); | ||
} | ||
} | ||
|
||
public function test_get_note_does_not_return_note_when_account_is_not_connected() { | ||
$account_mock = $this->getMockBuilder( \WC_Payments_Account::class )->disableOriginalConstructor()->setMethods( [ 'is_stripe_connected' ] )->getMock(); | ||
$account_mock->expects( $this->atLeastOnce() )->method( 'is_stripe_connected' )->will( $this->returnValue( false ) ); | ||
WC_Payments_Notes_Additional_Payment_Methods::set_account( $account_mock ); | ||
|
||
$note = WC_Payments_Notes_Additional_Payment_Methods::get_note(); | ||
|
||
$this->assertNull( $note ); | ||
} | ||
|
||
public function test_get_note_returns_note_when_account_is_connected() { | ||
$account_mock = $this->getMockBuilder( \WC_Payments_Account::class )->disableOriginalConstructor()->setMethods( [ 'is_stripe_connected', 'is_account_partially_onboarded', 'is_progressive_onboarding_in_progress' ] )->getMock(); | ||
$account_mock->expects( $this->once() )->method( 'is_stripe_connected' )->willReturn( true ); | ||
$account_mock->expects( $this->once() )->method( 'is_account_partially_onboarded' )->willReturn( false ); | ||
$account_mock->expects( $this->once() )->method( 'is_progressive_onboarding_in_progress' )->willReturn( false ); | ||
|
||
WC_Payments_Notes_Additional_Payment_Methods::set_account( $account_mock ); | ||
|
||
$note = WC_Payments_Notes_Additional_Payment_Methods::get_note(); | ||
|
||
$this->assertSame( 'Boost your sales by accepting new payment methods', $note->get_title() ); | ||
} | ||
|
||
public function test_get_note_returns_note_when_account_is_partially_onboarded() { | ||
$account_mock = $this->getMockBuilder( \WC_Payments_Account::class )->disableOriginalConstructor()->setMethods( [ 'is_stripe_connected', 'is_account_partially_onboarded', 'is_progressive_onboarding_in_progress' ] )->getMock(); | ||
$account_mock->expects( $this->once() )->method( 'is_stripe_connected' )->willReturn( true ); | ||
$account_mock->expects( $this->once() )->method( 'is_account_partially_onboarded' )->willReturn( true ); | ||
|
||
WC_Payments_Notes_Additional_Payment_Methods::set_account( $account_mock ); | ||
|
||
$note = WC_Payments_Notes_Additional_Payment_Methods::get_note(); | ||
|
||
$this->assertNull( $note ); | ||
} | ||
|
||
public function test_get_note_returns_note_when_account_is_progressive_in_progress() { | ||
$account_mock = $this->getMockBuilder( \WC_Payments_Account::class )->disableOriginalConstructor()->setMethods( [ 'is_stripe_connected', 'is_account_partially_onboarded', 'is_progressive_onboarding_in_progress' ] )->getMock(); | ||
$account_mock->expects( $this->once() )->method( 'is_stripe_connected' )->willReturn( true ); | ||
$account_mock->expects( $this->once() )->method( 'is_account_partially_onboarded' )->willReturn( false ); | ||
$account_mock->expects( $this->once() )->method( 'is_progressive_onboarding_in_progress' )->willReturn( true ); | ||
|
||
WC_Payments_Notes_Additional_Payment_Methods::set_account( $account_mock ); | ||
|
||
$note = WC_Payments_Notes_Additional_Payment_Methods::get_note(); | ||
|
||
$this->assertNull( $note ); | ||
} | ||
|
||
public function test_maybe_enable_feature_flag_redirects_to_onboarding_when_account_not_connected() { | ||
$account_mock = $this->getMockBuilder( \WC_Payments_Account::class )->disableOriginalConstructor()->setMethods( [ 'is_stripe_connected', 'redirect_to_onboarding_welcome_page' ] )->getMock(); | ||
$account_mock->expects( $this->atLeastOnce() )->method( 'is_stripe_connected' )->will( $this->returnValue( false ) ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,14 +55,6 @@ public function test_stripelink_setup_get_note() { | |
$this->assertStringStartsWith( 'https://woo.com/document/woopayments/payment-methods/link-by-stripe/', $set_up_action->query ); | ||
} | ||
|
||
public function test_stripelink_setup_note_null_when_upe_disabled() { | ||
$this->mock_gateway_data( '0', [ 'card', 'link' ], [ 'card' ] ); | ||
|
||
$note = \WC_Payments_Notes_Set_Up_StripeLink::get_note(); | ||
|
||
$this->assertNull( $note ); | ||
} | ||
|
||
Comment on lines
-58
to
-65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is irrelevant going forward due to UPE being always enabled |
||
public function test_stripelink_setup_note_null_when_link_not_available() { | ||
$this->mock_gateway_data( '1', [ 'card' ], [ 'card' ] ); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side question - would it also make sense to return
true
in case$account[ self::DEFERRED_UPE_SERVER_FLAG_NAME ]
is not set?i.e.:
Asking because we're basically saying: "if there's no account data - force dUPE". But if
$account
data is an array without theis_deferred_intent_creation_upe_enabled
key, we're saying that dUPE is disabled. Am I getting my neurons too twisted? 😵There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right and abc7347 improves this together with removing one redundant test which came up after the change, thank you!
The scenario with returning disabled dUPE state wouldn't happen because server always returns a value, but this doesn't mean client can rely on this so I agree with you.