Fix ApplePay device detection for edge cases.

This commit is contained in:
Pedro Silva 2023-11-14 16:33:19 +00:00
parent 5bcb047e3a
commit 206db76887
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
2 changed files with 25 additions and 5 deletions

View file

@ -98,11 +98,24 @@ return array(
return false;
}
}
foreach ( PropertiesDictionary::ALLOWED_USER_AGENTS as $allowed_agent ) {
if ( strpos( $user_agent, $allowed_agent ) !== false ) {
return true;
$browser_allowed = false;
foreach ( PropertiesDictionary::ALLOWED_USER_BROWSERS as $allowed_browser ) {
if ( strpos( $user_agent, $allowed_browser ) !== false ) {
$browser_allowed = true;
break;
}
}
$device_allowed = false;
foreach ( PropertiesDictionary::ALLOWED_USER_DEVICES as $allowed_devices ) {
if ( strpos( $user_agent, $allowed_devices ) !== false ) {
$device_allowed = true;
break;
}
}
return $browser_allowed && $device_allowed;
}
return false;
},

View file

@ -13,8 +13,15 @@ namespace WooCommerce\PayPalCommerce\Applepay\Assets;
* Class PropertiesDictionary
*/
class PropertiesDictionary {
public const DISALLOWED_USER_AGENTS = array( 'Chrome' );
public const ALLOWED_USER_AGENTS = array( 'Safari', 'Macintosh', 'iPhone', 'iPad', 'iPod' );
public const DISALLOWED_USER_AGENTS = array(
'Chrome/',
'CriOS/', // Chrome on iOS.
'Firefox/',
'OPR/', // Opera.
'Edg/', // Edge.
);
public const ALLOWED_USER_BROWSERS = array( 'Safari' );
public const ALLOWED_USER_DEVICES = array( 'Macintosh', 'iPhone', 'iPad', 'iPod' );
public const BILLING_CONTACT_INVALID = 'billing Contact Invalid';