@@ -3757,6 +3757,92 @@ public function test_get_recommended_payment_method_no_country_code_provided( $i
37573757 remove_filter ( 'woocommerce_countries_base_country ' , $ filter_callback );
37583758 }
37593759
3760+ public function test_updating_subscription_for_non_3ds_cards_removes_hook () {
3761+ $ _GET ['change_payment_method ' ] = 10 ;
3762+ WC_Subscriptions::set_wcs_is_subscription (
3763+ function ( $ order ) {
3764+ return true ;
3765+ }
3766+ );
3767+
3768+ $ pi = new Payment_Information ( 'pm_test ' , WC_Helper_Order::create_order (), null , new WC_Payment_Token_CC (), null , null , null , '' , 'card ' );
3769+
3770+ $ request = $ this ->mock_wcpay_request ( Create_And_Confirm_Intention::class );
3771+ $ request ->expects ( $ this ->once () )
3772+ ->method ( 'set_payment_methods ' )
3773+ ->with ( [ 'card ' ] );
3774+ $ request ->expects ( $ this ->once () )
3775+ ->method ( 'format_response ' )
3776+ ->willReturn ( WC_Helper_Intention::create_intention ( [ 'status ' => 'success ' ] ) );
3777+
3778+ add_filter (
3779+ 'woocommerce_subscriptions_update_payment_via_pay_shortcode ' ,
3780+ [ $ this ->card_gateway , 'update_payment_method_for_subscriptions ' ],
3781+ 10 ,
3782+ 3
3783+ );
3784+
3785+ $ this ->assertEquals (
3786+ 10 ,
3787+ has_filter ( 'woocommerce_subscriptions_update_payment_via_pay_shortcode ' , [ $ this ->card_gateway , 'update_payment_method_for_subscriptions ' ] ),
3788+ 'Hook should be registered before payment processing '
3789+ );
3790+
3791+ $ this ->card_gateway ->process_payment_for_order ( WC ()->cart , $ pi );
3792+
3793+ $ this ->assertFalse (
3794+ has_filter ( 'woocommerce_subscriptions_update_payment_via_pay_shortcode ' , [ $ this ->card_gateway , 'update_payment_method_for_subscriptions ' ] ),
3795+ 'Hook should be removed after processing payment for subscription with non-3DS card '
3796+ );
3797+ }
3798+
3799+ public function test_updating_subscription_for_3ds_cards_sets_delayed_update_payment_method_all () {
3800+ $ _GET ['change_payment_method ' ] = 10 ;
3801+ WC_Subscriptions::set_wcs_is_subscription (
3802+ function ( $ order ) {
3803+ return true ;
3804+ }
3805+ );
3806+
3807+ $ order = WC_Helper_Order::create_order ();
3808+
3809+ // Set up POST data including update_all_subscriptions_payment_method.
3810+ $ _POST = [
3811+ 'payment_method ' => 'woocommerce_payments ' ,
3812+ 'update_all_subscriptions_payment_method ' => '1 ' ,
3813+ ];
3814+
3815+ $ pi = new Payment_Information ( 'pm_test ' , $ order , null , new WC_Payment_Token_CC (), null , null , null , '' , 'card ' );
3816+
3817+ $ request = $ this ->mock_wcpay_request ( Create_And_Confirm_Intention::class );
3818+ $ request ->expects ( $ this ->once () )
3819+ ->method ( 'set_payment_methods ' )
3820+ ->with ( [ 'card ' ] );
3821+ $ request ->expects ( $ this ->once () )
3822+ ->method ( 'format_response ' )
3823+ ->willReturn (
3824+ WC_Helper_Intention::create_intention (
3825+ [
3826+ 'status ' => 'requires_action ' ,
3827+ 'next_action ' => [
3828+ 'type ' => 'use_stripe_sdk ' ,
3829+ ],
3830+ ]
3831+ )
3832+ );
3833+
3834+ try {
3835+ // The test exits early so we need to handle the exception.
3836+ $ this ->card_gateway ->process_payment_for_order ( WC ()->cart , $ pi );
3837+ } catch ( Exception $ e ) {
3838+ $ this ->assertEquals (
3839+ 'woocommerce_payments ' ,
3840+ $ order ->get_meta ( '_delayed_update_payment_method_all ' ),
3841+ 'Order metadata for delayed payment method update was not set correctly '
3842+ );
3843+ }
3844+ }
3845+
37603846 /**
37613847 * Sets up the expectation for a certain factor for the new payment
37623848 * process to be either set or unset.
0 commit comments