Skip to content

Commit

Permalink
Merge pull request woocommerce#1828 from woocommerce/PCP-2257-chrome-…
Browse files Browse the repository at this point in the history
…browser-detected-as-eligible-for-apple-pay

Chrome browser detected as eligible for Apple Pay (2257)
  • Loading branch information
Dinamiko authored Nov 15, 2023
2 parents aec5e64 + 206db76 commit a477770
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions modules/ppcp-applepay/extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
}

// Device eligibility.
$device_eligibility_text = __( 'Your current browser/device does not seem to support Apple Pay ❌.', 'woocommerce-paypal-payments' );
$device_eligibility_text = __( 'Status: Your current browser/device does not seem to support Apple Pay ❌', 'woocommerce-paypal-payments' );
$device_eligibility_notes = sprintf(
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
__( 'Though the button may display in previews, it won\'t appear in the shop. For details, refer to the %1$sApple Pay requirements%2$s.', 'woocommerce-paypal-payments' ),
'<a href="https://woo.com/document/woocommerce-paypal-payments/#apple-pay" target="_blank">',
'</a>'
);
if ( $container->get( 'applepay.is_browser_supported' ) ) {
$device_eligibility_text = __( 'Your browser/device supports Apple Pay ✔️.', 'woocommerce-paypal-payments' );
$device_eligibility_text = __( 'Status: Your current browser/device seems to support Apple Pay ✔️', 'woocommerce-paypal-payments' );
$device_eligibility_notes = __( 'The Apple Pay button will be visible both in previews and below the PayPal buttons in the shop.', 'woocommerce-paypal-payments' );
}

Expand Down
24 changes: 21 additions & 3 deletions modules/ppcp-applepay/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,29 @@
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$user_agent = wp_unslash( $_SERVER['HTTP_USER_AGENT'] ?? '' );
if ( $user_agent ) {
foreach ( PropertiesDictionary::ALLOWED_USER_AGENTS as $allowed_agent ) {
if ( strpos( $user_agent, $allowed_agent ) !== false ) {
return true;
foreach ( PropertiesDictionary::DISALLOWED_USER_AGENTS as $disallowed_agent ) {
if ( strpos( $user_agent, $disallowed_agent ) !== false ) {
return false;
}
}

$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;
},
Expand Down
10 changes: 9 additions & 1 deletion modules/ppcp-applepay/src/Assets/PropertiesDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
* Class PropertiesDictionary
*/
class PropertiesDictionary {
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';

Expand Down

0 comments on commit a477770

Please sign in to comment.