• Namespace
  • Class
  • Tree
  • Deprecated
  • Hook Reference

Namespaces

  • None
  • PaymentPlugins

Classes

  • Braintree_Gateway_Manager
  • PaymentPlugins\WC_Braintree_Admin_Meta_Box_Product_Data
  • PaymentPlugins\WC_Braintree_Constants
  • WC_Braintree_3ds_Validation
  • WC_Braintree_Admin_Assets
  • WC_Braintree_Admin_List_Table_Subscriptions
  • WC_Braintree_Admin_Menus
  • WC_Braintree_Admin_Order_Metaboxes
  • WC_Braintree_Admin_Settings
  • WC_Braintree_Admin_User_Edit
  • WC_Braintree_Advanced_Fraud_Settings
  • WC_Braintree_Advanced_Settings_API
  • WC_Braintree_Alipay_Payment_Gateway
  • WC_Braintree_API_Settings
  • WC_Braintree_ApplePay_Payment_Gateway
  • WC_Braintree_Bancontact_Payment_Gateway
  • WC_Braintree_CC_Payment_Gateway
  • WC_Braintree_Condition_Evaluator
  • WC_Braintree_Context_Stack
  • WC_Braintree_Controller_3ds
  • WC_Braintree_Controller_ApplePay
  • WC_Braintree_Controller_Cart
  • WC_Braintree_Controller_Checkout
  • WC_Braintree_Controller_Client_Token
  • WC_Braintree_Controller_Data_Migration
  • WC_Braintree_Controller_Frontend
  • WC_Braintree_Controller_GooglePay
  • WC_Braintree_Controller_Kount
  • WC_Braintree_Controller_Local_Payment
  • WC_Braintree_Controller_Merchant_Accounts
  • WC_Braintree_Controller_Order_Actions
  • WC_Braintree_Controller_Payment_Tokens
  • WC_Braintree_Controller_PayPal
  • WC_Braintree_Controller_Plan
  • WC_Braintree_Controller_Product
  • WC_Braintree_Controller_Settings
  • WC_Braintree_Controller_Webhook
  • WC_Braintree_Customer_Manager
  • WC_Braintree_Deprecated_Filter_Hooks
  • WC_Braintree_Descriptor_Settings
  • WC_Braintree_EPS_Payment_Gateway
  • WC_Braintree_Fee_Settings
  • WC_Braintree_Field_Manager
  • WC_Braintree_Form_Handler
  • WC_Braintree_Frontend_Scripts
  • WC_Braintree_Giropay_Payment_Gateway
  • WC_Braintree_GooglePay_Payment_Gateway
  • WC_Braintree_IDEAL_Payment_Gateway
  • WC_Braintree_Install
  • WC_Braintree_Local_Payment_Gateway
  • WC_Braintree_Manager
  • WC_Braintree_Merchant_Account_Settings
  • WC_Braintree_Meta_Box_Coupons
  • WC_Braintree_Meta_Box_Subscription_Order_Data
  • WC_Braintree_MyBank_Payment_Gateway
  • WC_Braintree_P24_Payment_Gateway
  • WC_Braintree_Payment_Gateway
  • WC_Braintree_Payment_Method_Conversion
  • WC_Braintree_PayPal_Payment_Gateway
  • WC_Braintree_Post_Types
  • WC_Braintree_Product_Gateway_Option
  • WC_Braintree_Query
  • WC_Braintree_Rest_API
  • WC_Braintree_Rest_Controller
  • WC_Braintree_Rest_Webook_Authentication
  • WC_Braintree_Sepa_Payment_Gateway
  • WC_Braintree_Settings_API
  • WC_Braintree_Shortcode_Payment_Buttons
  • WC_Braintree_Shortcodes
  • WC_Braintree_Sofort_Payment_Gateway
  • WC_Braintree_Subscription
  • WC_Braintree_Subscription_Data_Store_CPT
  • WC_Braintree_Subscription_Settings
  • WC_Braintree_Subscriptions_Cart
  • WC_Braintree_Subscriptions_Checkout
  • WC_Braintree_Update
  • WC_Braintree_Venmo_Payment_Gateway
  • WC_Braintree_WeChat_Payment_Gateway
  • WC_Meta_Box_Braintree_Subscription_Data
  • WC_Payment_Token_Braintree
  • WC_Payment_Token_Braintree_ApplePay
  • WC_Payment_Token_Braintree_CC
  • WC_Payment_Token_Braintree_GooglePay
  • WC_Payment_Token_Braintree_Local_Payment
  • WC_Payment_Token_Braintree_PayPal
  • WC_Payment_Token_Braintree_Venmo
  • WC_Product_Braintree_Subscription
  • WC_Product_Braintree_Subscription_Variation
  • WC_Product_Braintree_Variable_Subscription
  • WCS_Braintree_Subscription_Controller

Traits

  • WC_Braintree_Controller_Cart_Trait
  • WC_Braintree_Settings_Trait

Functions

  • bfwc_add_body_class
  • bfwc_billing_periods_string
  • bfwc_can_delete_payment_method
  • bfwc_copy_address_from_order
  • bfwc_error_code_type_nicename
  • bfwc_get_combined_error_messages
  • bfwc_get_error_message
  • bfwc_get_error_messages
  • bfwc_get_gateway_timezone
  • bfwc_get_product_descriptors
  • bfwc_get_subscription_status_name
  • bfwc_get_subscription_statuses
  • bfwc_get_template
  • bfwc_get_timezones
  • bfwc_register_subscription_status
  • bfwc_subscription_length_string
  • bfwc_subscription_user_actions
  • bfwcs_billing_interval_string
  • bfwcs_billing_intervals
  • bfwcs_calculate_end_date
  • bfwcs_calculate_first_payment_date
  • bfwcs_calculate_next_payment_date
  • bfwcs_calculate_order_total
  • bfwcs_calculate_start_date
  • bfwcs_can_combine_subscriptions
  • bfwcs_cart_contains_subscriptions
  • bfwcs_cart_formatted_date
  • bfwcs_cart_recurring_total_html
  • bfwcs_cart_shipping_total
  • bfwcs_cart_subtotal_string
  • bfwcs_cart_tax_total_html
  • bfwcs_copy_order_meta
  • bfwcs_create_order_from_subscription
  • bfwcs_create_renewal_order
  • bfwcs_create_subscription
  • bfwcs_frontend_interval_string
  • bfwcs_get_currency_symbol
  • bfwcs_get_interval_string
  • bfwcs_get_length_string
  • bfwcs_get_period_string
  • bfwcs_get_plan_from_product
  • bfwcs_get_price_string
  • bfwcs_get_product_price_html
  • bfwcs_get_related_orders
  • bfwcs_get_subscription
  • bfwcs_get_subscription_actions
  • bfwcs_get_subscription_statuses
  • bfwcs_get_subscriptions_for_order
  • bfwcs_get_subscriptions_for_user
  • bfwcs_is_change_payment_method
  • bfwcs_is_pay_for_subscription_request
  • bfwcs_order_contains_subscription
  • bfwcs_order_is_subscription
  • bfwcs_product_is_subscription
  • bfwcs_subscription_link_active
  • braintree
  • braintree_delete_user_payment_method
  • braintree_delete_user_payment_methods
  • braintree_device_data_field
  • braintree_get_customer_id
  • braintree_get_default_method
  • braintree_get_method_uris
  • braintree_get_method_url
  • braintree_get_payment_method_formats
  • braintree_get_payment_method_from_token
  • braintree_get_payment_method_title_from_array
  • braintree_get_payment_method_title_from_method
  • braintree_get_payment_method_title_from_method_details
  • braintree_get_payment_method_title_from_transaction
  • braintree_get_payment_title_from_token
  • braintree_get_payment_token_from_transaction
  • braintree_get_user_payment_methods
  • braintree_hidden_field
  • braintree_nonce_field
  • braintree_payment_method_to_array
  • braintree_payment_token_field
  • braintree_save_payment_method_from_transaction
  • braintree_save_user_payment_method
  • braintree_save_user_payment_methods
  • bt_manager
  • bwc_3ds_no_action_needed
  • bwc_3ds_verify_vaulted_methods
  • bwc_add_allowed_html
  • bwc_add_notice
  • bwc_applepay_cart_checkout_enabled
  • bwc_applepay_checkout_banner_enabled
  • bwc_applepay_get_line_items
  • bwc_applepay_product_checkout_enabled
  • bwc_calculate_fee
  • bwc_can_refund_order
  • bwc_card_payments_enabled
  • bwc_custom_form_text
  • bwc_cvv_field_enabled
  • bwc_display_icons_on_payment_methods_page
  • bwc_display_save_payment_method
  • bwc_dropin_v2_enabled
  • bwc_dropin_v3_enabled
  • bwc_enable_signup_from_checkout
  • bwc_execute_conditional_statement
  • bwc_fail_on_duplicate
  • bwc_fee_enabled_for_gateway
  • bwc_fees_enabled
  • bwc_get_3_0_0_deprecated_order_prop
  • bwc_get_3_0_0_updated_props
  • bwc_get_3ds_modal_html
  • bwc_get_billing_agreement_desc
  • bwc_get_comma_separated_product_names
  • bwc_get_conditional_values
  • bwc_get_custom_form
  • bwc_get_custom_form_fields
  • bwc_get_custom_forms
  • bwc_get_default_method
  • bwc_get_enclosed_icon_url
  • bwc_get_fees_for_gateway
  • bwc_get_gateway_fees
  • bwc_get_gateway_id
  • bwc_get_googlepay_methods
  • bwc_get_loader_file
  • bwc_get_merchant_account
  • bwc_get_merchant_accounts
  • bwc_get_option_text
  • bwc_get_order_property
  • bwc_get_payment_gateways
  • bwc_get_paypal_button
  • bwc_get_paypal_credit_button
  • bwc_get_paypal_credit_html
  • bwc_get_paypal_html
  • bwc_get_product_property
  • bwc_get_save_method_template
  • bwc_get_smartbutton_style
  • bwc_get_template
  • bwc_get_template_html
  • bwc_get_user_applepay_payment_methods
  • bwc_get_user_payment_methods
  • bwc_get_user_paypal_payment_methods
  • bwc_googlepay_enabled
  • bwc_is_3ds_active
  • bwc_is_3ds_enabled
  • bwc_is_admin_webhook_request
  • bwc_is_advanced_fraud_tools
  • bwc_is_applepay_enabled
  • bwc_is_checkout
  • bwc_is_custom_form
  • bwc_is_descriptors_enabled
  • bwc_is_dynamic_card_display
  • bwc_is_paypal_enabled
  • bwc_is_wc_3_0_0_or_more
  • bwc_kount_enabled
  • bwc_kount_send_processing_email
  • bwc_locate_template
  • bwc_output_checkout_error
  • bwc_payment_icons_enclosed_type
  • bwc_payment_icons_outside
  • bwc_payment_icons_type
  • bwc_payment_loader_enabled
  • bwc_payment_method_token_field
  • bwc_payment_token_field
  • bwc_paypal_cart_checkout_enabled
  • bwc_paypal_checkout_banner_enabled
  • bwc_paypal_checkout_flow
  • bwc_paypal_credit_active
  • bwc_paypal_credit_conditions
  • bwc_paypal_credit_enabled
  • bwc_paypal_credit_send_shipping
  • bwc_paypal_send_shipping
  • bwc_postal_code_enabled
  • bwc_refresh_payment_fragments
  • bwc_saved_payment_method_style
  • bwc_saved_payment_methods_list
  • bwc_set_checkout_error
  • bwc_smart_buttons_enabled
  • bwc_use_admin_text_for_custom_form
  • bwcs_braintree_subscriptions_active
  • bwcs_calculate_order_total
  • bwcs_can_combine_subscriptions
  • bwcs_can_delete_payment_method
  • bwcs_cart_item_contains_subscription
  • bwcs_get_cart_item_key
  • bwcs_get_current_date_time
  • bwcs_get_num_of_billing_cycles
  • bwcs_get_plan_from_product
  • bwcs_get_product_from_subscription
  • bwcs_get_start_date_in_utc
  • bwcs_get_subscription_date
  • bwcs_is_braintree_subscription
  • bwcs_is_change_payment_method
  • bwcs_is_paid_for_failed_renewal_request
  • bwcs_is_woocommerce_change_payment
  • bwcs_order_contains_subscription
  • bwcs_order_has_coupon
  • bwcs_order_is_subscription
  • bwcs_product_is_subscription
  • bwcs_retry_after_exception
  • bwcs_start_date_in_site_timezone
  • bwcs_subscription_has_trial
  • bwcs_subscription_is_synched
  • bwcs_subscriptions_active
  • wc_braintree_add_allowed_html
  • wc_braintree_add_body_class
  • wc_braintree_banner_checkout_template
  • wc_braintree_card_loader_options
  • wc_braintree_cart_checkout_template
  • wc_braintree_connection_settings
  • wc_braintree_create_payment_token
  • wc_braintree_create_payment_token_from_transaction
  • wc_braintree_custom_form_active
  • wc_braintree_custom_form_options
  • wc_braintree_delete_customer
  • wc_braintree_deprecated_template_check
  • wc_braintree_device_data_field
  • wc_braintree_display_prices_including_tax
  • wc_braintree_enqueue_local_payments
  • wc_braintree_environment
  • wc_braintree_errors_from_object
  • wc_braintree_evaluate_condition
  • wc_braintree_filter_customer_payment_tokens
  • wc_braintree_filter_payment_tokens
  • wc_braintree_generate_client_token
  • wc_braintree_get_3ds_actions
  • wc_braintree_get_card_type_icons
  • wc_braintree_get_checkout_fields
  • wc_braintree_get_conditional_values
  • wc_braintree_get_currency
  • wc_braintree_get_custom_form
  • wc_braintree_get_customer_id
  • wc_braintree_get_error_messages
  • wc_braintree_get_fee_gateways
  • wc_braintree_get_file_data
  • wc_braintree_get_local_gateways
  • wc_braintree_get_merchant_account
  • wc_braintree_get_merchant_accounts
  • wc_braintree_get_order_environment
  • wc_braintree_get_order_for_payment_id
  • wc_braintree_get_payment_method_format
  • wc_braintree_get_payment_tokens
  • wc_braintree_get_products_for_conditions
  • wc_braintree_get_response_code_message
  • wc_braintree_get_template
  • wc_braintree_get_template_html
  • wc_braintree_hidden_field
  • wc_braintree_local_payment_completed
  • wc_braintree_local_payment_params
  • wc_braintree_log
  • wc_braintree_log_error
  • wc_braintree_log_info
  • wc_braintree_merchant_id
  • wc_braintree_merge_order_statuses
  • wc_braintree_move_translations
  • wc_braintree_nonce_field
  • wc_braintree_order_statuses
  • wc_braintree_order_statuses_for_registration
  • wc_braintree_output_checkout_error
  • wc_braintree_parse_xml_contents
  • wc_braintree_payment_complete_order_status
  • wc_braintree_payment_gateways
  • wc_braintree_payment_method_formats
  • wc_braintree_payment_method_title
  • wc_braintree_payment_token_field
  • wc_braintree_pre_orders_active
  • wc_braintree_private_key
  • wc_braintree_process_scheduled_local_payment
  • wc_braintree_production_active
  • wc_braintree_public_key
  • wc_braintree_save_cc_enabled
  • wc_braintree_save_customer
  • wc_braintree_set_checkout_error
  • wc_braintree_show_product_checkout_gateways
  • wc_braintree_spam_bot_field
  • wc_braintree_subscriptions_active
  • wc_braintree_update_customer_location
  • wc_braintree_webhook_check
  • wc_braintree_woocommerce_payment_token_deleted
  • wcs_braintree_account_menu_items
  • wcs_braintree_active
  • wcs_braintree_before_delete_order_item
  • wcs_braintree_billing_interval_string
  • wcs_braintree_billing_intervals
  • wcs_braintree_billing_periods
  • wcs_braintree_billing_periods_string
  • wcs_braintree_calculate_end_date
  • wcs_braintree_calculate_first_payment_date
  • wcs_braintree_calculate_next_payment_date
  • wcs_braintree_calculate_start_date
  • wcs_braintree_cart_contains_subscription
  • wcs_braintree_cart_formatted_date
  • wcs_braintree_cart_recurring_tax_html
  • wcs_braintree_cart_recurring_total_html
  • wcs_braintree_cart_shipping_total
  • wcs_braintree_cart_subtotal_string
  • wcs_braintree_cart_tax_total_html
  • wcs_braintree_cart_totals_coupon_html
  • wcs_braintree_change_payment_method_template
  • wcs_braintree_copy_address_from_order
  • wcs_braintree_copy_order_meta
  • wcs_braintree_create_order_from_subscription
  • wcs_braintree_create_renewal_order
  • wcs_braintree_create_subscription
  • wcs_braintree_frontend_interval_string
  • wcs_braintree_get_billing_schedule_string
  • wcs_braintree_get_interval_string
  • wcs_braintree_get_length_string
  • wcs_braintree_get_period_string
  • wcs_braintree_get_plan_from_product
  • wcs_braintree_get_plan_options
  • wcs_braintree_get_plans
  • wcs_braintree_get_price_string
  • wcs_braintree_get_product_price_html
  • wcs_braintree_get_recurring_cart_key
  • wcs_braintree_get_recurring_total_text
  • wcs_braintree_get_related_orders
  • wcs_braintree_get_subscription
  • wcs_braintree_get_subscription_actions
  • wcs_braintree_get_subscription_from_recurring_cart_key
  • wcs_braintree_get_subscription_status_name
  • wcs_braintree_get_subscription_statuses
  • wcs_braintree_get_subscription_statuses_for_registration
  • wcs_braintree_get_subscriptions_for_order
  • wcs_braintree_get_subscriptions_for_user
  • wcs_braintree_is_change_payment_method_request
  • wcs_braintree_localize_scripts
  • wcs_braintree_order_contains_subscription
  • wcs_braintree_order_details
  • wcs_braintree_product_is_subscription
  • wcs_braintree_subscription_cancelled
  • wcs_braintree_subscription_length_string
  • wcs_braintree_subscription_user_actions
  • wcs_braintree_subscriptions_template
  • wcs_braintree_sync_subscription_with_gateway
  • wcs_braintree_view_subscription_template
  • wcs_braintree_webhook_subscription_cancelled
  • wcs_braintree_webhook_subscription_charged_successfully
  • wcs_braintree_webhook_subscription_expired
  • wcs_braintree_webhook_subscription_past_due
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 
<?php
defined( 'ABSPATH' ) || exit();

/**
 *
 * @since 3.0.0
 * @package Braintree/Classes
 *
 */
class WC_Braintree_Frontend_Scripts {

    public $braintree_version;

    private $registered_scripts = array();

    private $registered_styles = array();

    private $enqueued_scripts = array();

    private $enqueued_styles = array();

    private $localized_scripts = array();

    private $update_payment_method_request;

    private $client_manager_enqueued = false;

    public $global_scripts = array(
        'hosted-fields-v3'   => 'https://js.braintreegateway.com/web/%1$s/js/hosted-fields.min.js',
        'dropin-v3-ext'      => 'https://js.braintreegateway.com/web/dropin/1.32.1/js/dropin.min.js',
        'client-v3'          => 'https://js.braintreegateway.com/web/%1$s/js/client.min.js',
        'data-collector-v3'  => 'https://js.braintreegateway.com/web/%1$s/js/data-collector.min.js',
        '3ds-v3'             => 'https://js.braintreegateway.com/web/%1$s/js/three-d-secure.min.js',
        'paypal-v3'          => 'https://js.braintreegateway.com/web/%1$s/js/paypal.min.js',
        'paypal-checkout-v3' => 'https://js.braintreegateway.com/web/%1$s/js/paypal-checkout.js',
        'googlepay-v3'       => 'https://js.braintreegateway.com/web//%1$s/js/google-payment.min.js',
        'googlepay-pay'      => 'https://pay.google.com/gp/p/js/pay.js',
        'applepay-v3'        => 'https://js.braintreegateway.com/web/%1$s/js/apple-pay.min.js',
        'venmo-v3'           => 'https://js.braintreegateway.com/web/%1$s/js/venmo.min.js',
        'local-payment-v3'   => 'https://js.braintreegateway.com/web/%1$s/js/local-payment.min.js',
    );

    public $prefix = 'wc-braintree-';

    /**
     * @var object
     * @since 3.2.4
     */
    public $client_token;

    public function __construct( $version ) {
        $this->braintree_version = $version;

        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
        add_action( 'wp_print_scripts', array( $this, 'print_scripts' ), 5 );
        add_action( 'wp_print_footer_scripts', array( $this, 'print_footer_scripts' ), 5 );
        add_action( 'woocommerce_subscriptions_pre_update_payment_method', array( $this, 'pre_update_payment_method' ) );
    }

    public function enqueue_scripts() {
        $this->register_scripts();
    }

    private function register_scripts() {
        $this->braintree_version = apply_filters( 'wc_braintree_global_script_version', $this->braintree_version );

        foreach ( $this->global_scripts as $key => $src ) {
            $this->register_script( $key, sprintf( $src, $this->braintree_version ), array(), null );
        }
        $js_path = braintree()->assets_path() . 'js/';
        $min     = $this->get_min();

        $this->register_style( 'styles', $this->assets_url( 'css/braintree' . $this->get_min() . '.css' ) );

        $this->register_script( 'payment-methods', $this->assets_url( 'js/frontend/payment-methods' . $this->get_min() . '.js' ), array(
            'jquery'
        ) );
        $this->register_script( 'message-handler', $this->assets_url( 'js/frontend/message-handler' . $this->get_min() . '.js' ),
            array(
                'jquery',
                'woocommerce',
            )
        );
        $this->register_script( 'form-handler', $this->assets_url( 'js/frontend/form-handler' . $this->get_min() . '.js' ), array( 'jquery' ) );
        $this->register_script( 'payment-method-icons', $this->assets_url( 'js/frontend/payment-method-icons.js' ), array( 'jquery' ) );
        $this->register_script( 'global', $this->assets_url( 'js/frontend/wc-braintree' . $this->get_min() . '.js' ), array( 'jquery' ) );

        $this->register_script(
            'client-manager',
            $js_path . 'frontend/client-manager' . $min . '.js',
            array(
                'jquery',
                $this->get_handle( 'client-v3' ),
                $this->get_handle( 'message-handler' ),
                $this->get_handle( 'payment-methods' ),
                $this->get_handle( 'form-handler' ),
                $this->get_handle( 'global' )
            )
        );

        $this->register_script( 'change-payment-method', $this->assets_url( 'js/frontend/change-payment-method' . $this->get_min() . '.js' ), array( 'jquery' ) );

        if ( function_exists( 'wp_add_inline_script' ) ) {
            wp_add_inline_script( $this->get_handle( 'client-manager' ), '(function(){
                if(window.navigator.userAgent.match(/MSIE|Trident/)){
                    var script = document.createElement(\'script\');
                    script.setAttribute(\'src\', \'' . $this->assets_url( 'js/frontend/promise-polyfill.js' ) . '\');
                    document.head.appendChild(script);
                }
            }());' );
        }
    }

    public function assets_url( $uri = '' ) {
        return untrailingslashit( braintree()->assets_path() . $uri );
    }

    public function get_min() {
        return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    }

    public function register_script( $handle, $src, $deps = array(), $version = false, $footer = true ) {
        $this->registered_scripts[] = $this->get_handle( $handle );
        $version                    = false === $version ? braintree()->version : $version;
        wp_register_script( $this->get_handle( $handle ), $src, $deps, $version, $footer );
    }

    public function register_style( $handle, $src, $deps = array() ) {
        $handle                    = $this->get_handle( $handle );
        $this->registered_styles[] = $handle;
        wp_register_style( $handle, $src, $deps, braintree()->version );
    }

    public function enqueue_style( $handle, $src = '', $deps = array() ) {
        $handle = $this->get_handle( $handle );
        if ( ! in_array( $handle, $this->registered_styles ) ) {
            $this->register_style( $handle, $src, $deps );
        }
        wp_enqueue_style( $handle, $src, $deps, braintree()->version );
    }

    /**
     * @param string $handle
     * @param string $src
     * @param array $deps
     * @param bool $version
     * @param bool $footer
     */
    public function enqueue_script( $handle, $src = '', $deps = array(), $version = false, $footer = true ) {
        $handle = $this->get_handle( $handle );
        if ( ! in_array( $handle, $this->registered_scripts ) ) {
            $this->register_script( $handle, $src, $deps, $version, $footer );
        }
        $this->enqueued_scripts[] = $handle;
        wp_enqueue_script( $handle );
    }

    public function localize_script( $handle, $data ) {
        $handle = $this->get_handle( $handle );
        if ( wp_script_is( $handle, 'registered' ) ) {
            $name = str_replace( $this->prefix, '', $handle );
            $data = apply_filters( 'wc_braintree_localize_script_' . $name, $data, $name );
            if ( $data ) {
                $this->localized_scripts[] = $handle;
                $object_name               = str_replace( '-', '_', $handle ) . '_params';
                wp_localize_script( $handle, $object_name, $data );
            }
        }
    }

    /**
     * Localize scripts registered by this plugin.
     */
    public function print_scripts() {
        if ( ( is_checkout() && ! is_order_received_page() ) || is_add_payment_method_page() || is_product() || is_cart() || is_account_page() ||
             apply_filters( 'wc_braintree_print_scripts', false ) ) {
            // check if page contains short code used by elementor
            $this->localize_frontend();
        }
        if ( is_add_payment_method_page() ) {
            $this->enqueue_script( 'payment-method-icons' );
            $this->localize_script( 'payment-method-icons', $this->localize_payment_method_icons() );
        }
        if ( ! is_checkout() && ! is_cart() ) {
            $this->enqueue_mini_cart();
        }
        if ( wc_braintree_subscriptions_active() && is_account_page() ) {
            global $wp;
            if ( ! empty( $wp->query_vars['view-subscription'] ) ) {
                $this->enqueue_script( 'view-subscription', $this->assets_url( 'js/frontend/view-subscription.js' ), array(
                    'jquery',
                    'jquery-ui-dialog'
                ), braintree()->version, true );
                wp_enqueue_style( 'wp-jquery-ui-dialog' );
                $this->localize_script( 'view-subscription', array() );
            }
            if ( wcs_braintree_is_change_payment_method_request() ) {
                $this->enqueue_script(
                    'change-payment-methods',
                    $this->assets_url( 'js/frontend/change-payment-method' . $this->get_min() . '.js' ),
                    array(
                        'jquery',
                    )
                );
            }
        }
    }

    /**
     * @since 3.2.8
     */
    public function print_footer_scripts() {

        /**
         * When things like coupons make the order total $0, then WC won't call $gateway->payment_fields()
         * which means scripts won't be enqueued. This code checks to see if any gateways haven't been enqueued
         * on the checkout page.
         */
        global $wp;
        if ( is_checkout() && ! isset( $wp->query_vars['order_pay'] ) && ! is_order_received_page() ) {
            $gateways = array_filter( WC()->payment_gateways()->payment_gateways(), function ( $gateway ) {
                if ( $gateway instanceof WC_Braintree_Payment_Gateway ) {
                    $is_available = function () {
                        return parent::is_available();
                    };
                    $is_available = $is_available->bindTo( $gateway, 'WC_Braintree_Payment_Gateway' );

                    return $is_available() && ! $gateway->has_enqueued_scripts( $this, 'checkout' );
                }

                return false;

            } );
            foreach ( $gateways as $gateway ) {
                /**
                 * @var WC_Braintree_Payment_Gateway $gateway
                 */
                $gateway->enqueue_checkout_scripts( $this );
                $gateway->output_display_items( 'checkout' );
            }
        }
        /**
         * If the client manager is enqueued but it hasn't been localized then we know some
         * functionality is including the gateways and so we need to localize here.
         */
        if ( wp_script_is( $this->get_handle( 'client-manager' ) ) && ! in_array( $this->get_handle( 'client-manager' ), $this->localized_scripts ) ) {
            $this->localize_frontend();
        }
    }

    public function get_handle( $handle ) {
        return strpos( $handle, $this->prefix ) === false ? $this->prefix . $handle : $handle;
    }

    public function localize_payment_methods() {
        $data['cards']      = array_keys( wc_braintree_get_card_type_icons() );
        $data['no_results'] = __( 'Not matches found', 'woo-payment-gateway' );

        return $data;
    }

    public function localize_message_handler() {
        $data['messages'] = wc_braintree_get_error_messages();

        return $data;
    }

    public function localize_payment_method_icons() {
        $data   = array(
            'tokens' => array(),
            'icons'  => wc_braintree_get_card_type_icons(),
        );
        $tokens = wc_get_customer_saved_methods_list( get_current_user_id() );
        $index  = 0;
        foreach ( $tokens as $type => $methods ) {
            foreach ( $methods as $method ) {
                if ( isset( $method['wc_braintree_method'] ) ) {
                    $data['tokens'][] = array(
                        'index'     => $index,
                        'card_type' => $method['method_type'],
                    );
                }
                $index ++;
            }
        }

        return $data;
    }

    public function localize_client_manager() {
        $currency = wc_braintree_get_currency();

        return array(
            'url'              => WC_Braintree_Rest_API::get_endpoint( braintree()->rest_api->client_token->rest_uri() . '/create' ),
            '_wpnonce'         => wp_create_nonce( 'wp_rest' ),
            'page_id'          => $this->get_page_id(),
            'currency'         => $currency,
            'merchant_account' => wc_braintree_get_merchant_account( $currency ),
            'version'          => braintree()->version
        );
    }

    public function pre_update_payment_method() {
        $this->update_payment_method_request = true;
    }

    private function get_page_id() {
        global $wp;
        if ( is_product() ) {
            return 'product';
        }
        if ( is_cart() ) {
            return 'cart';
        }
        if ( is_checkout() ) {
            if ( ! empty( $wp->query_vars['order-pay'] ) ) {
                return 'order_pay';
            }

            return 'checkout';
        }
        if ( is_add_payment_method_page() ) {
            return 'add_payment_method';
        }
        if ( wc_braintree_subscriptions_active() && wcs_braintree_is_change_payment_method_request() ) {
            return 'change_payment_method';
        }

        return '';
    }

    /**
     * @return array
     * @since 3.2.4
     */
    public function get_enqueued_scripts() {
        return $this->enqueued_scripts;
    }

    private function localize_frontend() {
        $this->enqueue_style( 'styles' );
        wp_style_add_data( $this->get_handle( 'styles' ), 'rtl', 'replace' );

        $this->localize_script( 'global', array( 'page' => $this->get_page_id() ) );

        wp_localize_script( $this->get_handle( 'global' ), 'wc_braintree_checkout_fields', wc_braintree_get_checkout_fields( $this->get_page_id() ) );

        $this->localize_script( 'client-manager', $this->localize_client_manager() );

        $this->localize_script( 'message-handler', $this->localize_message_handler() );

        $this->localize_script( 'payment-methods', $this->localize_payment_methods() );

        $client_token       = wc_braintree_generate_client_token();
        $this->client_token = json_decode( base64_decode( $client_token ) );

        wp_localize_script( $this->get_handle( 'client-manager' ), 'wc_braintree_client_token', empty( $client_token ) ? array() : (array) $client_token );

    }

    private function enqueue_mini_cart() {
        foreach ( WC()->payment_gateways()->get_available_payment_gateways() as $gateway ) {
            /**
             * @var WC_Braintree_Payment_Gateway $gateway
             */
            if ( $gateway instanceof WC_Braintree_Payment_Gateway && $gateway->supports( 'wc_braintree_mini_cart' ) && $gateway->mini_cart_enabled() ) {
                if ( ! wp_style_is( $this->get_handle( 'styles' ) ) ) {
                    $this->localize_frontend();
                }
                $gateway->enqueue_mini_cart_scripts( $this );
            }
        }
    }
}
Braintree API documentation generated by ApiGen