2023-07-17 14:17:50 +02:00
< ? php
/**
* The Applepay module extensions .
*
* @ package WooCommerce\PayPalCommerce\Applepay
*/
declare ( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\Applepay ;
2023-09-05 09:14:20 +02:00
use WooCommerce\PayPalCommerce\Applepay\Assets\PropertiesDictionary ;
2023-11-02 15:12:20 +00:00
use WooCommerce\PayPalCommerce\Onboarding\Environment ;
2023-07-17 14:17:50 +02:00
use WooCommerce\PayPalCommerce\Onboarding\State ;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface ;
2023-09-15 17:32:00 +01:00
use WooCommerce\PayPalCommerce\WcGateway\Helper\DisplayManager ;
2023-10-12 15:27:55 +01:00
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings ;
2023-07-17 14:17:50 +02:00
return array (
2023-09-08 16:58:32 +02:00
'wcgateway.settings.fields' => function ( ContainerInterface $container , array $fields ) : array {
2023-10-12 15:27:55 +01:00
// Eligibility check.
if ( ! $container -> has ( 'applepay.eligible' ) || ! $container -> get ( 'applepay.eligible' ) ) {
return $fields ;
}
2023-10-19 11:32:12 +01:00
$is_available = $container -> get ( 'applepay.available' );
2023-10-12 15:27:55 +01:00
$is_referral = $container -> get ( 'applepay.is_referral' );
2023-09-08 16:58:32 +02:00
$insert_after = function ( array $array , string $key , array $new ) : array {
$keys = array_keys ( $array );
$index = array_search ( $key , $keys , true );
$pos = false === $index ? count ( $array ) : $index + 1 ;
2023-09-05 09:14:20 +02:00
2023-09-08 16:58:32 +02:00
return array_merge ( array_slice ( $array , 0 , $pos ), $new , array_slice ( $array , $pos ) );
2023-09-05 09:14:20 +02:00
};
2023-09-19 12:22:08 +02:00
$display_manager = $container -> get ( 'wcgateway.display-manager' );
assert ( $display_manager instanceof DisplayManager );
2023-09-05 09:14:20 +02:00
2023-11-02 15:39:42 +00:00
// Domain registration.
2023-11-02 15:12:20 +00:00
$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' ;
}
2023-11-02 15:39:42 +00:00
// Domain validation.
2023-11-02 15:12:20 +00:00
$domain_validation_text = __ ( 'Status: Domain validation failed ❌' , 'woocommerce-paypal-payments' );
2023-12-12 10:14:49 +00:00
if ( ! $container -> get ( 'applepay.has_validated' ) ) {
$domain_validation_text = __ ( 'The domain has not yet been validated. Use the Apple Pay button to validate the domain ❌' , 'woocommerce-paypal-payments' );
} elseif ( $container -> get ( 'applepay.is_validated' ) ) {
2023-11-02 15:12:20 +00:00
$domain_validation_text = __ ( 'Status: Domain successfully validated ✔️' , 'woocommerce-paypal-payments' );
}
2023-11-02 15:39:42 +00:00
// Device eligibility.
2023-11-08 14:38:07 +00:00
$device_eligibility_text = __ ( 'Status: Your current browser/device does not seem to support Apple Pay ❌' , 'woocommerce-paypal-payments' );
2023-11-02 15:12:20 +00:00
$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' ) ) {
2023-11-08 14:38:07 +00:00
$device_eligibility_text = __ ( 'Status: Your current browser/device seems to support Apple Pay ✔️' , 'woocommerce-paypal-payments' );
2023-11-02 15:12:20 +00:00
$device_eligibility_notes = __ ( 'The Apple Pay button will be visible both in previews and below the PayPal buttons in the shop.' , 'woocommerce-paypal-payments' );
}
2023-10-12 15:27:55 +01:00
// Connection tab fields.
$fields = $insert_after (
$fields ,
2024-01-16 14:24:34 +00:00
'ppcp_reference_transactions_status' ,
2023-10-12 15:27:55 +01:00
array (
'applepay_status' => array (
'title' => __ ( 'Apple Pay Payments' , 'woocommerce-paypal-payments' ),
'type' => 'ppcp-text' ,
'text' => $container -> get ( 'applepay.settings.connection.status-text' ),
'screens' => array (
State :: STATE_ONBOARDED ,
),
'requirements' => array (),
'gateway' => Settings :: CONNECTION_TAB_ID ,
),
)
);
if ( ! $is_available && $is_referral ) {
2023-09-18 17:36:40 +02:00
$connection_url = admin_url ( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=ppcp-connection#field-credentials_feature_onboarding_heading' );
2023-10-16 17:06:55 +01:00
$connection_link = '<a href="' . $connection_url . '" style="pointer-events: auto">' ;
2023-09-18 17:36:40 +02:00
return $insert_after (
$fields ,
'allow_card_button_gateway' ,
array (
2023-09-18 17:52:17 +02:00
'applepay_button_enabled' => array (
2023-10-12 15:27:55 +01:00
'title' => __ ( 'Apple Pay Button' , 'woocommerce-paypal-payments' ),
'type' => 'checkbox' ,
'class' => array ( 'ppcp-grayed-out-text' ),
'input_class' => array ( 'ppcp-disabled-checkbox' ),
'label' => __ ( 'Enable Apple Pay button' , 'woocommerce-paypal-payments' )
2023-09-18 17:36:40 +02:00
. '<p class="description">'
. sprintf (
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
2023-09-18 17:52:17 +02:00
__ ( 'Your PayPal account %1$srequires additional permissions%2$s to enable Apple Pay.' , 'woocommerce-paypal-payments' ),
2023-09-18 17:36:40 +02:00
$connection_link ,
'</a>'
)
. '</p>' ,
2023-10-12 15:27:55 +01:00
'default' => 'yes' ,
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'paypal' ,
'requirements' => array (),
'custom_attributes' => array (
'data-ppcp-display' => wp_json_encode (
array (
$display_manager
-> rule ()
-> condition_is_true ( false )
-> action_enable ( 'applepay_button_enabled' )
-> to_array (),
)
),
),
2023-09-18 17:52:17 +02:00
),
)
);
2023-09-18 17:36:40 +02:00
}
2023-09-14 17:48:46 +01:00
2023-09-05 09:14:20 +02:00
return $insert_after (
$fields ,
'allow_card_button_gateway' ,
array (
2023-11-02 15:39:42 +00:00
'applepay_button_enabled' => array (
2023-09-08 16:58:32 +02:00
'title' => __ ( 'Apple Pay Button' , 'woocommerce-paypal-payments' ),
'type' => 'checkbox' ,
2023-09-12 14:07:30 +02:00
'label' => __ ( 'Enable Apple Pay button' , 'woocommerce-paypal-payments' )
. '<p class="description">'
. sprintf (
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
2023-09-12 15:35:32 +02:00
__ ( 'Buyers can use %1$sApple Pay%2$s to make payments on the web using the Safari web browser or an iOS device.' , 'woocommerce-paypal-payments' ),
2023-09-12 14:07:30 +02:00
'<a href="https://woocommerce.com/document/woocommerce-paypal-payments/#apple-pay" target="_blank">' ,
'</a>'
)
. '</p>' ,
2023-09-08 16:58:32 +02:00
'default' => 'yes' ,
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'paypal' ,
'requirements' => array (),
2023-09-05 09:14:20 +02:00
'custom_attributes' => array (
2023-09-14 17:48:46 +01:00
'data-ppcp-display' => wp_json_encode (
2023-09-05 09:14:20 +02:00
array (
2023-09-15 17:32:00 +01:00
$display_manager
2023-09-14 17:48:46 +01:00
-> rule ()
2023-09-15 17:32:00 +01:00
-> condition_element ( 'applepay_button_enabled' , '1' )
2023-11-02 15:12:20 +00:00
-> action_visible ( 'applepay_button_domain_registration' )
-> action_visible ( 'applepay_button_domain_validation' )
-> action_visible ( 'applepay_button_device_eligibility' )
2023-09-15 17:32:00 +01:00
-> action_visible ( 'applepay_button_color' )
-> action_visible ( 'applepay_button_type' )
-> action_visible ( 'applepay_button_language' )
2023-12-04 14:06:51 +00:00
-> action_visible ( 'applepay_checkout_data_mode' )
2023-09-14 17:48:46 +01:00
-> to_array (),
2023-09-05 09:14:20 +02:00
)
),
),
2023-08-17 09:42:45 +02:00
),
2023-11-09 17:50:57 +00:00
'applepay_button_domain_registration' => array (
2023-11-08 18:07:19 +00:00
'title' => __ ( 'Domain Registration' , 'woocommerce-paypal-payments' ),
2023-11-02 15:12:20 +00:00
'type' => 'ppcp-text' ,
2023-11-02 15:39:42 +00:00
'text' =>
2023-11-02 15:12:20 +00:00
'<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'
),
2023-11-09 17:50:57 +00:00
'classes' => array ( 'ppcp-field-indent' ),
2023-11-02 15:12:20 +00:00
'class' => array (),
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'paypal' ,
'requirements' => array (),
),
2023-11-09 17:50:57 +00:00
'applepay_button_domain_validation' => array (
2023-11-08 18:07:19 +00:00
'title' => __ ( 'Domain Validation' , 'woocommerce-paypal-payments' ),
2023-11-02 15:12:20 +00:00
'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'
),
2023-11-09 17:50:57 +00:00
'classes' => array ( 'ppcp-field-indent' ),
2023-11-02 15:12:20 +00:00
'class' => array (),
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'paypal' ,
'requirements' => array (),
),
2023-11-09 17:50:57 +00:00
'applepay_button_device_eligibility' => array (
2023-11-08 18:07:19 +00:00
'title' => __ ( 'Device Eligibility' , 'woocommerce-paypal-payments' ),
2023-11-02 15:12:20 +00:00
'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'
),
2023-11-09 17:50:57 +00:00
'classes' => array ( 'ppcp-field-indent' ),
2023-11-02 15:12:20 +00:00
'class' => array (),
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'paypal' ,
'requirements' => array (),
),
2023-11-09 17:50:57 +00:00
'applepay_button_type' => array (
2023-11-08 18:07:19 +00:00
'title' => __ ( 'Button Label' , 'woocommerce-paypal-payments' ),
2023-09-08 16:58:32 +02:00
'type' => 'select' ,
2023-09-12 14:07:30 +02:00
'desc_tip' => true ,
'description' => __ (
'This controls the label of the Apple Pay button.' ,
'woocommerce-paypal-payments'
),
2023-11-09 17:50:57 +00:00
'classes' => array ( 'ppcp-field-indent' ),
2023-09-08 16:58:32 +02:00
'class' => array (),
2023-09-12 14:07:30 +02:00
'input_class' => array ( 'wc-enhanced-select' ),
'default' => 'pay' ,
'options' => PropertiesDictionary :: button_types (),
2023-09-08 16:58:32 +02:00
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'paypal' ,
2023-09-05 09:14:20 +02:00
'requirements' => array (),
),
2023-11-09 17:50:57 +00:00
'applepay_button_color' => array (
2023-11-08 18:07:19 +00:00
'title' => __ ( 'Button Color' , 'woocommerce-paypal-payments' ),
2023-09-08 16:58:32 +02:00
'type' => 'select' ,
2023-09-12 14:07:30 +02:00
'desc_tip' => true ,
'description' => __ (
2023-09-12 15:35:32 +02:00
'The Apple Pay Button may appear as a black button with white lettering, white button with black lettering, or a white button with black lettering and a black outline.' ,
2023-09-12 14:07:30 +02:00
'woocommerce-paypal-payments'
),
'label' => '' ,
2023-09-08 16:58:32 +02:00
'input_class' => array ( 'wc-enhanced-select' ),
2023-11-09 17:50:57 +00:00
'classes' => array ( 'ppcp-field-indent' ),
2023-09-12 14:07:30 +02:00
'class' => array (),
'default' => 'black' ,
'options' => PropertiesDictionary :: button_colors (),
2023-09-08 16:58:32 +02:00
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'paypal' ,
2023-09-05 09:14:20 +02:00
'requirements' => array (),
),
2023-11-09 17:50:57 +00:00
'applepay_button_language' => array (
2023-11-08 18:07:19 +00:00
'title' => __ ( 'Button Language' , 'woocommerce-paypal-payments' ),
2023-09-08 16:58:32 +02:00
'type' => 'select' ,
2023-09-12 14:07:30 +02:00
'desc_tip' => true ,
'description' => __ (
2023-09-12 15:35:32 +02:00
'The language and region used for the displayed Apple Pay button. The default value is the current language and region setting in a browser.' ,
2023-09-12 14:07:30 +02:00
'woocommerce-paypal-payments'
),
2023-11-09 17:50:57 +00:00
'classes' => array ( 'ppcp-field-indent' ),
2023-09-08 16:58:32 +02:00
'class' => array (),
'input_class' => array ( 'wc-enhanced-select' ),
'default' => 'en' ,
'options' => PropertiesDictionary :: button_languages (),
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'paypal' ,
2023-09-05 09:14:20 +02:00
'requirements' => array (),
),
2023-11-09 17:50:57 +00:00
'applepay_checkout_data_mode' => array (
2023-11-08 18:07:19 +00:00
'title' => __ ( 'Send checkout billing and shipping data to Apple Pay' , 'woocommerce-paypal-payments' ),
'type' => 'select' ,
2023-11-09 17:50:57 +00:00
'classes' => array ( 'ppcp-field-indent' ),
2023-11-08 18:07:19 +00:00
'class' => array (),
'input_class' => array ( 'wc-enhanced-select' ),
'desc_tip' => true ,
'description' => __ ( 'Using the WC form data increases convenience for the customers, but can cause issues if Apple Pay details do not match the billing and shipping data in the checkout form.' , 'woocommerce-paypal-payments' ),
'default' => PropertiesDictionary :: BILLING_DATA_MODE_DEFAULT ,
'options' => PropertiesDictionary :: billing_data_modes (),
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'paypal' ,
'requirements' => array (),
),
2023-09-05 09:14:20 +02:00
)
2023-08-17 09:42:45 +02:00
);
2023-07-17 14:17:50 +02:00
},
);