2021-03-25 10:21:28 +02:00
< ? php
/**
* Register and configure assets provided by this module .
2021-03-25 13:55:43 +02:00
*
* @ package WooCommerce\PayPalCommerce\WcGateway\Assets
2021-03-25 10:21:28 +02:00
*/
declare ( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Assets ;
2024-02-15 16:05:56 +01:00
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint ;
2024-10-03 10:10:50 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencyGetter ;
2025-02-03 13:34:30 +01:00
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment ;
2023-12-12 17:30:55 +00:00
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\RefreshFeatureStatusEndpoint ;
2023-10-17 16:29:56 +02:00
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper ;
2021-04-29 17:40:41 +02:00
2021-03-25 13:55:43 +02:00
/**
* Class SettingsPageAssets
*/
2021-03-25 13:45:57 +02:00
class SettingsPageAssets {
2021-03-25 10:21:28 +02:00
/**
2021-03-25 13:55:43 +02:00
* The URL of this module .
*
2021-03-25 10:21:28 +02:00
* @ var string
*/
private $module_url ;
2021-04-29 17:40:41 +02:00
2021-03-25 14:29:56 +02:00
/**
2022-02-17 18:51:24 +02:00
* The assets version .
2021-03-25 14:29:56 +02:00
*
* @ var string
*/
2022-02-17 18:51:24 +02:00
private $version ;
2021-03-25 10:21:28 +02:00
2022-09-02 12:59:53 +02:00
/**
* The subscription helper .
*
* @ var SubscriptionHelper
*/
protected $subscription_helper ;
2022-10-19 11:38:49 +03:00
/**
* The PayPal SDK client ID .
*
* @ var string
*/
private $client_id ;
/**
2024-10-03 10:10:50 +03:00
* The getter of the 3 - letter currency code of the shop .
2022-10-19 11:38:49 +03:00
*
2024-10-03 10:10:50 +03:00
* @ var CurrencyGetter
2022-10-19 11:38:49 +03:00
*/
2024-10-03 10:10:50 +03:00
private CurrencyGetter $currency ;
2022-10-19 11:38:49 +03:00
/**
* 2 - letter country code of the shop .
*
* @ var string
*/
private $country ;
2023-02-14 11:25:23 +02:00
/**
* The environment object .
*
* @ var Environment
*/
private $environment ;
2022-11-02 17:36:08 +04:00
/**
* Whether Pay Later button is enabled either for checkout , cart or product page .
*
* @ var bool
*/
protected $is_pay_later_button_enabled ;
2022-11-10 15:16:35 +04:00
/**
* The list of disabled funding sources .
*
* @ var array
*/
protected $disabled_sources ;
2022-11-17 16:58:58 +04:00
/**
* The list of all existing funding sources .
*
* @ var array
*/
protected $all_funding_sources ;
2023-08-11 10:35:50 +01:00
/**
* Whether it ' s a settings page of this plugin .
*
* @ var bool
*/
private $is_settings_page ;
2023-11-08 09:46:52 +02:00
/**
* Whether the ACDC gateway is enabled .
*
* @ var bool
*/
private $is_acdc_enabled ;
2024-02-15 16:05:56 +01:00
/**
* Billing Agreements endpoint .
*
* @ var BillingAgreementsEndpoint
*/
private $billing_agreements_endpoint ;
2024-06-13 11:35:05 +02:00
/**
* Whether we 're on a settings page for our plugin' s payment methods .
*
* @ var bool
*/
private $is_paypal_payment_method_page ;
2021-03-25 10:21:28 +02:00
/**
* Assets constructor .
2021-03-25 13:45:57 +02:00
*
2024-02-15 16:05:56 +01:00
* @ param string $module_url The url of this module .
* @ param string $version The assets version .
* @ param SubscriptionHelper $subscription_helper The subscription helper .
* @ param string $client_id The PayPal SDK client ID .
2024-10-03 10:10:50 +03:00
* @ param CurrencyGetter $currency The getter of the 3 - letter currency code of the shop .
2024-02-15 16:05:56 +01:00
* @ param string $country 2 - letter country code of the shop .
* @ param Environment $environment The environment object .
* @ param bool $is_pay_later_button_enabled Whether Pay Later button is enabled either for checkout , cart or product page .
* @ param array $disabled_sources The list of disabled funding sources .
* @ param array $all_funding_sources The list of all existing funding sources .
* @ param bool $is_settings_page Whether it ' s a settings page of this plugin .
* @ param bool $is_acdc_enabled Whether the ACDC gateway is enabled .
* @ param BillingAgreementsEndpoint $billing_agreements_endpoint Billing Agreements endpoint .
2024-06-13 11:35:05 +02:00
* @ param bool $is_paypal_payment_method_page Whether we 're on a settings page for our plugin' s payment methods .
2021-03-25 10:21:28 +02:00
*/
2022-10-19 11:38:49 +03:00
public function __construct (
string $module_url ,
string $version ,
SubscriptionHelper $subscription_helper ,
string $client_id ,
2024-10-03 10:10:50 +03:00
CurrencyGetter $currency ,
2022-11-02 17:36:08 +04:00
string $country ,
2023-02-14 11:25:23 +02:00
Environment $environment ,
2022-11-10 15:16:35 +04:00
bool $is_pay_later_button_enabled ,
2022-11-17 16:58:58 +04:00
array $disabled_sources ,
2023-08-11 10:35:50 +01:00
array $all_funding_sources ,
2023-11-08 09:46:52 +02:00
bool $is_settings_page ,
2024-02-15 16:05:56 +01:00
bool $is_acdc_enabled ,
2024-06-13 11:35:05 +02:00
BillingAgreementsEndpoint $billing_agreements_endpoint ,
bool $is_paypal_payment_method_page
2022-10-19 11:38:49 +03:00
) {
2024-06-13 11:35:05 +02:00
$this -> module_url = $module_url ;
$this -> version = $version ;
$this -> subscription_helper = $subscription_helper ;
$this -> client_id = $client_id ;
$this -> currency = $currency ;
$this -> country = $country ;
$this -> environment = $environment ;
$this -> is_pay_later_button_enabled = $is_pay_later_button_enabled ;
$this -> disabled_sources = $disabled_sources ;
$this -> all_funding_sources = $all_funding_sources ;
$this -> is_settings_page = $is_settings_page ;
$this -> is_acdc_enabled = $is_acdc_enabled ;
$this -> billing_agreements_endpoint = $billing_agreements_endpoint ;
$this -> is_paypal_payment_method_page = $is_paypal_payment_method_page ;
2021-03-25 10:21:28 +02:00
}
/**
* Register assets provided by this module .
2023-08-11 16:15:10 +01:00
*
* @ return void
2021-03-25 10:21:28 +02:00
*/
2023-08-11 16:15:10 +01:00
public function register_assets () : void {
2024-11-25 15:39:38 +01:00
if ( ! is_admin () || wp_doing_ajax () ) {
return ;
}
2021-04-01 13:22:06 +03:00
2024-11-25 15:39:38 +01:00
if ( $this -> is_settings_page ) {
$this -> register_admin_assets ();
}
if ( $this -> is_paypal_payment_method_page ) {
$this -> register_paypal_admin_assets ();
}
2021-04-01 13:22:06 +03:00
}
2021-03-25 10:21:28 +02:00
/**
2023-08-11 10:35:50 +01:00
* Register assets for PayPal admin pages .
2021-03-25 10:21:28 +02:00
*/
2023-08-11 10:35:50 +01:00
private function register_paypal_admin_assets () : void {
2022-10-19 11:38:49 +03:00
wp_enqueue_style (
'ppcp-gateway-settings' ,
trailingslashit ( $this -> module_url ) . 'assets/css/gateway-settings.css' ,
array (),
$this -> version
);
2021-04-01 13:22:06 +03:00
wp_enqueue_script (
'ppcp-gateway-settings' ,
trailingslashit ( $this -> module_url ) . 'assets/js/gateway-settings.js' ,
array (),
2022-02-17 18:51:24 +02:00
$this -> version ,
2021-04-01 13:22:06 +03:00
true
2021-03-25 13:45:57 +02:00
);
2022-09-02 12:59:53 +02:00
2022-10-19 11:38:49 +03:00
/**
* Psalm cannot find it for some reason .
*
* @ psalm - suppress UndefinedConstant
*/
2022-09-02 12:59:53 +02:00
wp_localize_script (
'ppcp-gateway-settings' ,
'PayPalCommerceGatewaySettings' ,
2023-09-21 11:58:51 +01:00
apply_filters (
'woocommerce_paypal_payments_admin_gateway_settings' ,
array (
'is_subscriptions_plugin_active' => $this -> subscription_helper -> plugin_is_active (),
'client_id' => $this -> client_id ,
2024-10-03 10:10:50 +03:00
'currency' => $this -> currency -> get (),
2023-09-21 11:58:51 +01:00
'country' => $this -> country ,
'environment' => $this -> environment -> current_environment (),
'integration_date' => PAYPAL_INTEGRATION_DATE ,
'is_pay_later_button_enabled' => $this -> is_pay_later_button_enabled ,
2023-11-08 09:46:52 +02:00
'is_acdc_enabled' => $this -> is_acdc_enabled ,
2023-09-21 11:58:51 +01:00
'disabled_sources' => $this -> disabled_sources ,
'all_funding_sources' => $this -> all_funding_sources ,
'components' => array ( 'buttons' , 'funding-eligibility' , 'messages' ),
2023-12-12 17:30:55 +00:00
'ajax' => array (
'refresh_feature_status' => array (
'endpoint' => \WC_AJAX :: get_endpoint ( RefreshFeatureStatusEndpoint :: ENDPOINT ),
'nonce' => wp_create_nonce ( RefreshFeatureStatusEndpoint :: nonce () ),
'button' => '.ppcp-refresh-feature-status' ,
2024-01-04 15:23:01 +00:00
'messages' => array (
'waiting' => __ ( 'Checking features...' , 'woocommerce-paypal-payments' ),
'success' => __ ( 'Feature status refreshed.' , 'woocommerce-paypal-payments' ),
),
2023-12-12 17:30:55 +00:00
),
),
2024-02-15 16:05:56 +01:00
'reference_transaction_enabled' => $this -> billing_agreements_endpoint -> reference_transaction_enabled (),
2024-02-15 16:23:19 +01:00
'vaulting_must_enable_advanced_wallet_message' => sprintf (
2024-02-15 16:05:56 +01:00
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
2024-05-14 12:33:21 +02:00
esc_html__ ( 'Your PayPal account must be eligible to %1$ssave PayPal and Venmo payment methods%2$s to enable PayPal Vaulting.' , 'woocommerce-paypal-payments' ),
2024-02-15 16:05:56 +01:00
'<a href="/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=ppcp-connection#field-credentials_feature_onboarding_heading">' ,
'</a>'
),
2023-09-21 11:58:51 +01:00
)
2022-09-02 12:59:53 +02:00
)
);
2021-03-25 10:21:28 +02:00
}
2023-08-11 10:35:50 +01:00
/**
* Register assets for PayPal admin pages .
*/
private function register_admin_assets () : void {
2023-09-14 17:48:46 +01:00
wp_enqueue_style (
'ppcp-admin-common' ,
trailingslashit ( $this -> module_url ) . 'assets/css/common.css' ,
array (),
$this -> version
);
2023-08-11 10:35:50 +01:00
wp_enqueue_script (
'ppcp-admin-common' ,
trailingslashit ( $this -> module_url ) . 'assets/js/common.js' ,
array (),
$this -> version ,
true
);
}
2021-03-25 13:45:57 +02:00
}