Skip to content

Commit

Permalink
Fix WooPay user registration in classic checkout (#9558)
Browse files Browse the repository at this point in the history
Co-authored-by: Danae Millan <[email protected]>
  • Loading branch information
malithsen and a-danae authored Oct 18, 2024
1 parent a35b00c commit 23ba546
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-woopay-user-creation-in-shortcode-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

WooPay user registration via classic checkout
22 changes: 17 additions & 5 deletions includes/woopay/class-woopay-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ public function should_save_platform_customer() {
$session_data = WC()->session->get( WooPay_Session::WOOPAY_SESSION_KEY );
}

return isset( $session_data['save_user_in_woopay'] ) && filter_var( $session_data['save_user_in_woopay'], FILTER_VALIDATE_BOOLEAN );
$save_user_in_woopay_post = isset( $_POST['save_user_in_woopay'] ) && filter_var( wp_unslash( $_POST['save_user_in_woopay'] ), FILTER_VALIDATE_BOOLEAN ); // phpcs:ignore WordPress.Security.NonceVerification
$save_user_in_woopay_session = isset( $session_data['save_user_in_woopay'] ) && filter_var( $session_data['save_user_in_woopay'], FILTER_VALIDATE_BOOLEAN );

return $save_user_in_woopay_post || $save_user_in_woopay_session;
}

/**
Expand Down Expand Up @@ -170,7 +173,9 @@ public static function is_store_country_available() {
public function get_woopay_phone() {
$session_data = WC()->session->get( WooPay_Session::WOOPAY_SESSION_KEY );

if ( ! empty( $session_data['woopay_user_phone_field']['full'] ) ) {
if ( ! empty( $_POST['woopay_user_phone_field']['full'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return wc_clean( wp_unslash( $_POST['woopay_user_phone_field']['full'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
} elseif ( ! empty( $session_data['woopay_user_phone_field']['full'] ) ) {
return $session_data['woopay_user_phone_field']['full'];
}

Expand All @@ -185,7 +190,9 @@ public function get_woopay_phone() {
public function get_woopay_source_url() {
$session_data = WC()->session->get( WooPay_Session::WOOPAY_SESSION_KEY );

if ( ! empty( $session_data['woopay_source_url'] ) ) {
if ( ! empty( $_POST['woopay_source_url'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return wc_clean( wp_unslash( $_POST['woopay_source_url'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
} elseif ( ! empty( $session_data['woopay_source_url'] ) ) {
return $session_data['woopay_source_url'];
}

Expand All @@ -200,7 +207,10 @@ public function get_woopay_source_url() {
public function get_woopay_is_blocks() {
$session_data = WC()->session->get( WooPay_Session::WOOPAY_SESSION_KEY );

return isset( $session_data['woopay_is_blocks'] ) && filter_var( $session_data['woopay_is_blocks'], FILTER_VALIDATE_BOOLEAN );
$woopay_is_blocks_post = isset( $_POST['woopay_is_blocks'] ) && filter_var( wp_unslash( $_POST['woopay_is_blocks'] ), FILTER_VALIDATE_BOOLEAN ); // phpcs:ignore WordPress.Security.NonceVerification
$woopay_is_blocks_session = isset( $session_data['woopay_is_blocks'] ) && filter_var( $session_data['woopay_is_blocks'], FILTER_VALIDATE_BOOLEAN );

return $woopay_is_blocks_post || $woopay_is_blocks_session;
}

/**
Expand All @@ -211,7 +221,9 @@ public function get_woopay_is_blocks() {
public function get_woopay_viewport() {
$session_data = WC()->session->get( WooPay_Session::WOOPAY_SESSION_KEY );

if ( ! empty( $session_data['woopay_viewport'] ) ) {
if ( ! empty( $_POST['woopay_viewport'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return wc_clean( wp_unslash( $_POST['woopay_viewport'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
} elseif ( ! empty( $session_data['woopay_viewport'] ) ) {
return $session_data['woopay_viewport'];
}

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/woopay/test-class-woopay-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use WCPay\WooPay\WooPay_Utilities;
use WCPay\WooPay\WooPay_Session;

/**
* WooPay_Utilities unit tests.
Expand Down Expand Up @@ -177,6 +178,19 @@ public function test_should_enable_woopay_on_cart_or_checkout_logged_out_guest_c
$this->clean_up_should_enable_woopay_tests();
}

/**
* WooPay user is saved to platform on classic checkout.
*
* @return void
*/
public function test_should_save_platform_customer_in_classic_checkout() {
$woopay_utilities = new WooPay_Utilities();

$_POST['save_user_in_woopay'] = 'true';
$this->assertTrue( $woopay_utilities->should_save_platform_customer() );
unset( $_POST['save_user_in_woopay'] );
}

private function clean_up_should_enable_woopay_tests() {
remove_filter( 'woocommerce_is_checkout', '__return_true' );
wp_set_current_user( 0 );
Expand Down

0 comments on commit 23ba546

Please sign in to comment.