diff --git a/changelog.txt b/changelog.txt index 8af240d68c2..bdb711c54a3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,8 @@ *** WooCommerce Payments Changelog *** += 2.8.3 - 2021-xx-xx = +* Fix - Fix for payment request buttons when the new payment methods gateway is enabled. + = 2.8.2 - 2021-08-05 = * Fix - If account is disconnected or not set up do not display onboarding task and UPE inbox note. * Fix - Fix for the site acting as disconnected after the account cache expires. diff --git a/includes/payment-methods/class-upe-payment-gateway.php b/includes/payment-methods/class-upe-payment-gateway.php index ec28f4cd8bf..8cad4580a17 100644 --- a/includes/payment-methods/class-upe-payment-gateway.php +++ b/includes/payment-methods/class-upe-payment-gateway.php @@ -302,13 +302,13 @@ public function create_setup_intent() { } /** - * Create and confirm payment intent. Saved payment methods do not follow UPE workflow. + * Create and confirm payment intent. Function used to route any payments that do not use the UPE flow through the parent process payment. * * @param int $order_id Order ID to process the payment for. * * @return array|null An array with result of payment and redirect URL, or nothing. */ - public function process_payment_using_saved_method( $order_id ) { + public function parent_process_payment( $order_id ) { return parent::process_payment( $order_id ); } @@ -344,8 +344,8 @@ public function process_payment( $order_id ) { $selected_upe_payment_type ); } - } elseif ( $token ) { - return $this->process_payment_using_saved_method( $order_id ); + } else { + return $this->parent_process_payment( $order_id ); } return [ diff --git a/readme.txt b/readme.txt index c5cb4bb34e7..e72dad46f90 100644 --- a/readme.txt +++ b/readme.txt @@ -98,6 +98,9 @@ Please note that our support for the checkout block is still experimental and th == Changelog == += 2.8.3 - 2021-xx-xx = +* Fix - Fix for payment request buttons when the new payment methods gateway is enabled. + = 2.8.2 - 2021-08-05 = * Fix - If account is disconnected or not set up do not display onboarding task and UPE inbox note. * Fix - Fix for the site acting as disconnected after the account cache expires. diff --git a/tests/unit/payment-methods/test-class-upe-payment-gateway.php b/tests/unit/payment-methods/test-class-upe-payment-gateway.php index 3cf24b26ee4..73e555cf24b 100644 --- a/tests/unit/payment-methods/test-class-upe-payment-gateway.php +++ b/tests/unit/payment-methods/test-class-upe-payment-gateway.php @@ -194,7 +194,7 @@ public function setUp() { [ 'get_return_url', 'manage_customer_details_for_order', - 'process_payment_using_saved_method', + 'parent_process_payment', ] ) ->getMock(); @@ -208,7 +208,7 @@ public function setUp() { ); $this->mock_upe_gateway ->expects( $this->any() ) - ->method( 'process_payment_using_saved_method' ) + ->method( 'parent_process_payment' ) ->will( $this->returnValue( $this->mock_payment_result ) ); @@ -429,13 +429,16 @@ public function test_create_setup_intent_no_customer() { } public function test_process_payment_returns_correct_redirect_url() { - $order = WC_Helper_Order::create_order(); - $order_id = $order->get_id(); + $order = WC_Helper_Order::create_order(); + $order_id = $order->get_id(); + $_POST['wc_payment_intent_id'] = 'pi_abc123'; $this->set_cart_contains_subscription_items( false ); $result = $this->mock_upe_gateway->process_payment( $order->get_id() ); + unset( $_POST['wc_payment_intent_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing + $this->assertEquals( 'success', $result['result'] ); $this->assertEquals( true, $result['payment_needed'] ); $this->assertRegExp( "/order_id=$order_id/", $result['redirect_url'] ); @@ -447,15 +450,17 @@ public function test_process_payment_passes_save_payment_method() { $order = WC_Helper_Order::create_order(); $order_id = $order->get_id(); - $gateway_id = UPE_Payment_Gateway::GATEWAY_ID; - $save_payment_param = "wc-$gateway_id-new-payment-method"; - $_POST[ $save_payment_param ] = 'yes'; + $gateway_id = UPE_Payment_Gateway::GATEWAY_ID; + $save_payment_param = "wc-$gateway_id-new-payment-method"; + $_POST[ $save_payment_param ] = 'yes'; + $_POST['wc_payment_intent_id'] = 'pi_abc123'; $this->set_cart_contains_subscription_items( false ); $result = $this->mock_upe_gateway->process_payment( $order->get_id() ); - unset( $_POST[ $save_payment_param ] );// phpcs:ignore WordPress.Security.NonceVerification.Missing + unset( $_POST[ $save_payment_param ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing + unset( $_POST['wc_payment_intent_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing $this->assertEquals( 'success', $result['result'] ); $this->assertRegExp( "/order_id=$order_id/", $result['redirect_url'] ); @@ -470,6 +475,25 @@ public function test_process_payment_returns_correct_redirect_when_using_saved_p $this->set_cart_contains_subscription_items( false ); $result = $this->mock_upe_gateway->process_payment( $order->get_id() ); + + $this->mock_upe_gateway + ->expects( $this->never() ) + ->method( 'manage_customer_details_for_order' ); + $this->assertEquals( 'success', $result['result'] ); + $this->assertRegExp( '/key=mock_order_key/', $result['redirect'] ); + } + + public function test_process_payment_returns_correct_redirect_when_using_payment_request() { + $order = WC_Helper_Order::create_order(); + $_POST['payment_request_type'] = 'google_pay'; + + $this->set_cart_contains_subscription_items( false ); + + $result = $this->mock_upe_gateway->process_payment( $order->get_id() ); + + $this->mock_upe_gateway + ->expects( $this->never() ) + ->method( 'manage_customer_details_for_order' ); $this->assertEquals( 'success', $result['result'] ); $this->assertRegExp( '/key=mock_order_key/', $result['redirect'] ); }