Merge pull request #1821 from woocommerce/PCP-2132-apple-pay-domain-registration-browser-eligibility-check

Apple Pay domain registration & browser eligibility check (2132)
This commit is contained in:
Emili Castells 2023-11-06 09:24:29 +01:00 committed by GitHub
commit b9d659dd1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 7 deletions

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Applepay;
use WooCommerce\PayPalCommerce\Applepay\Assets\PropertiesDictionary;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\WcGateway\Helper\DisplayManager;
@ -37,6 +38,34 @@ return array(
$display_manager = $container->get( 'wcgateway.display-manager' );
assert( $display_manager instanceof DisplayManager );
// Domain registration.
$env = $container->get( 'onboarding.environment' );
assert( $env instanceof Environment );
$domain_registration_url = 'https://www.paypal.com/uccservicing/apm/applepay';
if ( $env->current_environment_is( Environment::SANDBOX ) ) {
$domain_registration_url = 'https://www.sandbox.paypal.com/uccservicing/apm/applepay';
}
// Domain validation.
$domain_validation_text = __( 'Status: Domain validation failed ❌', 'woocommerce-paypal-payments' );
if ( $container->get( 'applepay.is_validated' ) ) {
$domain_validation_text = __( 'Status: Domain successfully validated ✔️', 'woocommerce-paypal-payments' );
}
// Device eligibility.
$device_eligibility_text = __( '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_notes = __( 'The Apple Pay button will be visible both in previews and below the PayPal buttons in the shop.', 'woocommerce-paypal-payments' );
}
// Connection tab fields.
$fields = $insert_after(
$fields,
@ -100,7 +129,7 @@ return array(
$fields,
'allow_card_button_gateway',
array(
'applepay_button_enabled' => array(
'applepay_button_enabled' => array(
'title' => __( 'Apple Pay Button', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Enable Apple Pay button', 'woocommerce-paypal-payments' )
@ -122,6 +151,9 @@ return array(
$display_manager
->rule()
->condition_element( 'applepay_button_enabled', '1' )
->action_visible( 'applepay_button_domain_registration' )
->action_visible( 'applepay_button_domain_validation' )
->action_visible( 'applepay_button_device_eligibility' )
->action_visible( 'applepay_button_color' )
->action_visible( 'applepay_button_type' )
->action_visible( 'applepay_button_language' )
@ -130,7 +162,66 @@ return array(
),
),
),
'applepay_button_type' => array(
'applepay_button_domain_registration' => array(
'title' => str_repeat( '&nbsp;', 6 ) . __( 'Domain Registration', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-text',
'text' =>
'<a href="' . $domain_registration_url . '" class="button" target="_blank">'
. __( 'Manage Domain Registration', 'woocommerce-paypal-payments' )
. '</a>'
. '<p class="description">'
. __( 'Any (sub)domain names showing an Apple Pay button must be registered on the PayPal website. If the domain displaying the Apple Pay button isn\'t registered, the payment method won\'t work.', 'woocommerce-paypal-payments' )
. '</p>',
'desc_tip' => true,
'description' => __(
'Registering the website domain on the PayPal site is mandated by Apple. Payments will fail if the Apple Pay button is used on an unregistered domain.',
'woocommerce-paypal-payments'
),
'class' => array(),
'screens' => array( State::STATE_ONBOARDED ),
'gateway' => 'paypal',
'requirements' => array(),
),
'applepay_button_domain_validation' => array(
'title' => str_repeat( '&nbsp;', 6 ) . __( 'Domain Validation', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-text',
'text' => $domain_validation_text
. '<p class="description">'
. sprintf(
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
__( '<strong>Note:</strong> PayPal Payments automatically presents the %1$sdomain association file%2$s for Apple to validate your registered domain.', 'woocommerce-paypal-payments' ),
'<a href="/.well-known/apple-developer-merchantid-domain-association" target="_blank">',
'</a>'
)
. '</p>',
'desc_tip' => true,
'description' => __(
'Apple requires the website domain to be registered and validated. PayPal Payments automatically presents your domain association file for Apple to validate the manually registered domain.',
'woocommerce-paypal-payments'
),
'class' => array(),
'screens' => array( State::STATE_ONBOARDED ),
'gateway' => 'paypal',
'requirements' => array(),
),
'applepay_button_device_eligibility' => array(
'title' => str_repeat( '&nbsp;', 6 ) . __( 'Device Eligibility', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-text',
'text' => $device_eligibility_text
. '<p class="description">'
. $device_eligibility_notes
. '</p>',
'desc_tip' => true,
'description' => __(
'Apple Pay demands certain Apple devices for secure payment execution. This helps determine if your current device is compliant.',
'woocommerce-paypal-payments'
),
'class' => array(),
'screens' => array( State::STATE_ONBOARDED ),
'gateway' => 'paypal',
'requirements' => array(),
),
'applepay_button_type' => array(
'title' => str_repeat( '&nbsp;', 6 ) . __( 'Button Label', 'woocommerce-paypal-payments' ),
'type' => 'select',
'desc_tip' => true,
@ -146,7 +237,7 @@ return array(
'gateway' => 'paypal',
'requirements' => array(),
),
'applepay_button_color' => array(
'applepay_button_color' => array(
'title' => str_repeat( '&nbsp;', 6 ) . __( 'Button Color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'desc_tip' => true,
@ -163,7 +254,7 @@ return array(
'gateway' => 'paypal',
'requirements' => array(),
),
'applepay_button_language' => array(
'applepay_button_language' => array(
'title' => str_repeat( '&nbsp;', 6 ) . __( 'Button Language', 'woocommerce-paypal-payments' ),
'type' => 'select',
'desc_tip' => true,

View file

@ -15,6 +15,7 @@ use WooCommerce\PayPalCommerce\Applepay\Assets\ApplePayButton;
use WooCommerce\PayPalCommerce\Applepay\Assets\AppleProductStatus;
use WooCommerce\PayPalCommerce\Applepay\Assets\DataToAppleButtonScripts;
use WooCommerce\PayPalCommerce\Applepay\Assets\BlocksPaymentMethod;
use WooCommerce\PayPalCommerce\Applepay\Assets\PropertiesDictionary;
use WooCommerce\PayPalCommerce\Applepay\Helper\ApmApplies;
use WooCommerce\PayPalCommerce\Applepay\Helper\AvailabilityNotice;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
@ -56,11 +57,16 @@ return array(
$container->get( 'wcgateway.is-ppcp-settings-page' ),
$container->get( 'applepay.available' ) || ( ! $container->get( 'applepay.is_referral' ) ),
$container->get( 'applepay.server_supported' ),
$settings->has( 'applepay_validated' ) ? $settings->get( 'applepay_validated' ) === true : false,
$container->get( 'applepay.is_validated' ),
$container->get( 'applepay.button' )
);
},
'applepay.is_validated' => static function ( ContainerInterface $container ): bool {
$settings = $container->get( 'wcgateway.settings' );
return $settings->has( 'applepay_validated' ) ? $settings->get( 'applepay_validated' ) === true : false;
},
'applepay.apple-product-status' => static function( ContainerInterface $container ): AppleProductStatus {
return new AppleProductStatus(
$container->get( 'wcgateway.settings' ),
@ -83,6 +89,18 @@ return array(
'applepay.server_supported' => static function ( ContainerInterface $container ): bool {
return ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off';
},
'applepay.is_browser_supported' => static function ( ContainerInterface $container ): bool {
// 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;
}
}
}
return false;
},
'applepay.url' => static function ( ContainerInterface $container ): string {
$path = realpath( __FILE__ );
if ( false === $path ) {

View file

@ -13,6 +13,7 @@ namespace WooCommerce\PayPalCommerce\Applepay\Assets;
* Class PropertiesDictionary
*/
class PropertiesDictionary {
public const ALLOWED_USER_AGENTS = array( 'Safari', 'Macintosh', 'iPhone', 'iPad', 'iPod' );
public const BILLING_CONTACT_INVALID = 'billing Contact Invalid';