• 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  376  377  378  379  380  381  382  383  384  385  386  387  388  389  390  391  392  393  394  395  396  397  398  399  400  401  402  403  404  405  406  407  408  409  410  411  412  413  414  415  416  417  418  419  420  421  422  423  424  425  426  427  428  429  430  431  432  433  434  435  436  437  438  439  440  441  442  443  444  445  446  447  448  449  450  451  452  453  454  455  456  457  458  459  460  461  462  463  464  465  466  467  468  469  470  471  472  473  474  475  476  477  478  479  480  481  482  483  484  485  486  487  488  489  490  491  492  493  494  495  496  497  498  499  500  501  502  503  504  505  506  507  508  509  510  511  512  513  514  515  516  517  518  519  520  521  522  523  524  525  526  527  528  529  530  531  532  533  534  535  536  537  538  539  540  541  542  543  544  545  546  547  548  549  550  551  552  553  554  555  556  557  558  559  560  561  562  563  564  565  566  567  568  569  570  571  572  573  574  575  576  577  578  579  580  581  582  583  584  585  586  587  588  589  590  591  592  593  594  595  596  597  598  599  600  601  602  603  604  605  606  607  608  609  610  611  612  613  614  615  616  617  618  619  620  621  622  623  624  625  626  627  628  629  630  631  632  633  634  635  636  637  638  639  640  641  642  643  644  645  646  647  648  649  650  651  652  653  654  655  656  657  658  659  660  661  662  663  664  665  666  667  668  669  670  671  672  673  674  675  676  677  678  679  680  681  682  683  684  685  686  687  688  689  690  691  692  693  694  695  696  697  698  699  700  701  702  703  704  705  706  707  708  709  710  711  712  713  714  715  716  717  718  719  720  721  722  723  724  725  726  727  728  729  730  731  732  733  734  735  736  737  738  739  740  741  742  743  744  745  746  747  748  749  750  751  752  753  754  755  756  757  758  759  760  761  762  763  764  765  766  767  768  769  770  771  772  773  774  775  776  777  778  779  780  781  782  783  784  785  786  787  788  789  790  791  792  793  794  795  796  797  798  799  800  801  802  803  804  805  806  807  808  809  810  811  812  813  814  815  816  817  818  819  820  821  822  823  824  825  826  827  828  829  830  831  832  833  834  835  836  837  838  839  840  841  842  843  844  845  846  847  848  849  850  851  852  853  854  855  856  857  858  859  860  861  862  863  864  865  866  867  868  869  870  871  872  873  874  875  876  877  878  879  880  881  882  883  884  885  886  887  888  889  890  891  892  893  894  895  896  897  898  899  900  901  902  903  904  905  906  907  908  909  910  911  912  913  914  915  916  917  918  919  920  921  922  923  924  925  926  927  928  929  930  931  932  933  934  935  936  937  938  939  940  941  942  943  944  945  946  947  948  949  950  951  952  953  954  955  956  957  958  959  960  961  962  963  964  965  966  967  968  969  970  971  972  973  974  975  976  977  978  979  980  981  982  983  984  985  986  987  988  989  990  991  992  993  994  995  996  997  998  999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 
<?php

defined( 'ABSPATH' ) || exit();

use \PaymentPlugins\WC_Braintree_Constants as Constants;

/**
 * Functions related to WC.
 *
 * @since 3.0.0
 */

/**
 *
 * @param string $template_name
 * @param array  $args
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_get_template( $template_name, $args = array() ) {
    return wc_get_template( $template_name, $args, braintree()->template_path(), braintree()->plugin_path() . 'templates/' );
}

/**
 *
 * @param string $template_name
 * @param array  $args
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_get_template_html( $template_name, $args = array() ) {
    return wc_get_template_html( $template_name, $args, braintree()->template_path(), braintree()->plugin_path() . 'templates/' );
}

/**
 *
 * @param string $env
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_private_key( $env = '' ) {
    $env = empty( $env ) ? wc_braintree_environment() : $env;

    return braintree()->api_settings->get_option( "{$env}_private_key" );
}

/**
 *
 * @param string $env
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_public_key( $env = '' ) {
    $env = empty( $env ) ? wc_braintree_environment() : $env;

    return braintree()->api_settings->get_option( "{$env}_public_key" );
}

/**
 *
 * @param string $env
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_merchant_id( $env = '' ) {
    $env = empty( $env ) ? wc_braintree_environment() : $env;

    return braintree()->api_settings->get_option( "{$env}_merchant_id" );
}

/**
 * Return an array of connection values used to establish connection with Braintree.
 *
 * @param string $env
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_connection_settings( $env = '' ) {
    return apply_filters(
        'wc_braintree_connection_settings',
        array(
            'environment' => empty( $env ) ? wc_braintree_environment() : $env,
            'merchantId'  => wc_braintree_merchant_id( $env ),
            'publicKey'   => wc_braintree_public_key( $env ),
            'privateKey'  => wc_braintree_private_key( $env ),
        )
    );
}

/**
 * Return the currently active environment.
 * Possible values are production or sandbox.
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_environment() {
    return apply_filters( 'wc_braintree_environment', braintree()->api_settings->get_option( 'environment' ) );
}

/**
 * Return true of Production is currently active.
 *
 * @since 3.0.0
 * @return boolean
 * @package Braintree/Functions
 */
function wc_braintree_production_active() {
    return wc_braintree_environment() === 'production';
}

/**
 * Log the provided message in the WC logs directory.
 *
 * @param int    $level
 * @param string $message
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_log( $level, $message ) {
    if ( braintree()->api_settings->is_active( 'debug' ) ) {
        $log = wc_get_logger();
        $log->log( $level, $message, array( 'source' => 'wc-braintree' ) );
    }
}

/**
 *
 * @param string $message
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_log_error( $message ) {
    wc_braintree_log( WC_Log_Levels::ERROR, $message );
}

/**
 *
 * @param string $message
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_log_info( $message ) {
    wc_braintree_log( WC_Log_Levels::INFO, $message );
}

/**
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_custom_form_options() {
    return apply_filters(
        'wc_braintree_custom_form_options',
        array(
            'bootstrap_form'         => array(
                'label'          => __( 'Bootstrap Form', 'woo-payment-gateway' ),
                'template'       => 'custom-forms/bootstrap-form.php',
                'css'            => WC_BRAINTREE_ASSETS . 'css/custom-forms/bootstrap-form.css',
                'external_css'   => '',
                'javascript'     => WC_BRAINTREE_ASSETS . 'js/frontend/custom-forms/bootstrap-form.js',
                'default_styles' => '{"input":{"font-size":"16px", "font-family":"helvetica, tahoma, calibri, sans-serif"}, "@media screen and (max-width: 375px)":{"input":{"font-size":"14px"}}}',
            ),
            'google_material_design' => array(
                'label'          => __( 'Material Design', 'woo-payment-gateway' ),
                'template'       => 'custom-forms/google-material-form.php',
                'css'            => WC_BRAINTREE_ASSETS . 'css/custom-forms/google-material-design.css',
                'external_css'   => '',
                'javascript'     => WC_BRAINTREE_ASSETS . 'js/frontend/custom-forms/google-material-design.js',
                'default_styles' => '{"input":{"font-size":"16px", "font-family":"roboto, verdana, sans-serif"}, "@media screen and (max-width: 375px)":{"input":{"font-size":"14px"}}}',
            ),
            'dynamic_card_form'      => array(
                'label'          => __( 'Dynamic Card Design', 'woo-payment-gateway' ),
                'template'       => 'custom-forms/dynamic-card-form.php',
                'css'            => WC_BRAINTREE_ASSETS . 'css/custom-forms/dynamic-card-form.css',
                'external_css'   => '',
                'javascript'     => WC_BRAINTREE_ASSETS . 'js/frontend/custom-forms/dynamic-card-form.js',
                'default_styles' => '{"input":{"font-size":"16px"}, "input.invalid":{"color":"#E53A40"}, "@media screen and (max-width: 375px)":{"input":{"font-size":"14px"}}}',
            ),
            'classic_form'           => array(
                'label'          => __( 'Classic Form', 'woo-payment-gateway' ),
                'template'       => 'custom-forms/classic-form.php',
                'css'            => WC_BRAINTREE_ASSETS . 'css/custom-forms/classic-form.css',
                'external_css'   => '',
                'javascript'     => WC_BRAINTREE_ASSETS . 'js/frontend/custom-forms/classic-form.js',
                'default_styles' => '{"input":{"font-size":"16px"}, ".invalid":{"color":"#D0021B"}, "@media screen and (max-width: 375px)":{"input":{"font-size":"14px"}}}',
            ),
            'simple_form'            => array(
                'label'          => __( 'Simple Form', 'woo-payment-gateway' ),
                'template'       => 'custom-forms/simple-form.php',
                'css'            => WC_BRAINTREE_ASSETS . 'css/custom-forms/simple-form.css',
                'external_css'   => '',
                'javascript'     => WC_BRAINTREE_ASSETS . 'js/frontend/custom-forms/simple-form.js',
                'default_styles' => '{"input":{"font-size":"16px", "font-family":"courier, monospace"}, ".valid":{"color":"rgb(94, 189, 128)"}, "@media screen and (max-width: 375px)":{"input":{"font-size":"14px"}}}',
            ),
            'card_shape_form'        => array(
                'label'          => __( 'Card Shape Form', 'woo-payment-gateway' ),
                'template'       => 'custom-forms/card-shape-form.php',
                'css'            => WC_BRAINTREE_ASSETS . 'css/custom-forms/card-shape-form.css',
                'external_css'   => '',
                'javascript'     => WC_BRAINTREE_ASSETS . 'js/frontend/custom-forms/card-shape-form.js',
                'default_styles' => '{"input":{"font-size":"16px", "font-family":"courier, monospace", "font-weight":"500"}}',
            ),
        )
    );
}

/**
 *
 * @param string $key
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_get_custom_form( $key ) {
    return wc_braintree_custom_form_options()[ $key ];
}

/**
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_card_loader_options() {
    return apply_filters(
        'wc_braintree_card_loader_options',
        array(
            'circular-loader.php'  => 'circular-loader',
            'hour-glass.php'       => 'hour-glass',
            'loading.php'          => 'loading',
            'pacman.php'           => 'pacman',
            'ping-pong.php'        => 'ping-pong',
            'processing-plain.php' => 'processing-plain',
            'rotating-gears.php'   => 'rotating-gears',
            'simple-dots.php'      => 'simple-dots',
            'stairs-loader.php'    => 'stairs-loader',
        )
    );
}

/**
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_payment_method_formats() {
    return apply_filters(
        'wc_braintree_payment_method_formats',
        array(
            \Braintree\PaymentInstrumentType::CREDIT_CARD      => array(
                'type_ending_in'          => array(
                    'label'   => __( 'Type Ending In', 'woo-payment-gateway' ),
                    'example' => 'Visa ending in 1111',
                    'format'  => __( '{card_type} ending in {last4}', 'woo-payment-gateway' ),
                ),
                'type_masked_number'      => array(
                    'label'   => __( 'Type Masked Number', 'woo-payment-gateway' ),
                    'example' => 'Visa 4111********1111',
                    'format'  => '{card_type} {masked_number}',
                ),
                'type_dash_masked_number' => array(
                    'label'   => __( 'Type Dash Masked Number', 'woo-payment-gateway' ),
                    'example' => 'Visa - 4111********1111',
                    'format'  => '{card_type} - {masked_number}',
                ),
                'type_last4'              => array(
                    'label'   => __( 'Type Last 4', 'woo-payment-gateway' ),
                    'example' => 'Visa 1111',
                    'format'  => '{card_type} {last4}',
                ),
                'type_dash_last4'         => array(
                    'label'   => __( 'Type Dash & Last 4', 'woo-payment-gateway' ),
                    'example' => 'Visa - 1111',
                    'format'  => '{card_type} - {last4}',
                ),
                'masked_number'           => array(
                    'label'   => __( 'Masked Number', 'woo-payment-gateway' ),
                    'example' => '4111********1111',
                    'format'  => '{masked_number}',
                ),
                'last4'                   => array(
                    'label'   => __( 'Last Four', 'woo-payment-gateway' ),
                    'example' => '1111',
                    'format'  => '{last4}',
                ),
                'card_type'               => array(
                    'label'   => __( 'Card Type', 'woo-payment-gateway' ),
                    'example' => 'Visa',
                    'format'  => '{card_type}',
                ),
            ),
            \Braintree\PaymentInstrumentType::PAYPAL_ACCOUNT   => array(
                'paypal_and_email' => array(
                    'label'   => __( 'PayPal & Email', 'woo-payment-gateway' ),
                    'example' => 'PayPal - [email protected]',
                    'format'  => 'PayPal - {email}',
                ),
                'email'            => array(
                    'label'   => __( 'Email', 'woo-payment-gateway' ),
                    'example' => '[email protected]',
                    'format'  => '{email}',
                ),
                'paypal'           => array(
                    'label'   => __( 'PayPal', 'woo-payment-gateway' ),
                    'example' => 'PayPal',
                    'format'  => __( 'PayPal', 'woo-payment-gateway' ),
                ),
            ),
            \Braintree\PaymentInstrumentType::APPLE_PAY_CARD   => array(
                'apple_type_last4' => array(
                    'label'   => __( 'Type and Last Four', 'woo-payment-gateway' ),
                    'example' => 'Apple Pay - Discover 2928',
                    'format'  => 'Apple Pay - {payment_instrument_name}',
                ),
                'type_last4'       => array(
                    'label'   => __( 'Type and Last Four', 'woo-payment-gateway' ),
                    'example' => 'Discover 2928',
                    'format'  => '{payment_instrument_name}',
                ),
            ),
            \Braintree\PaymentInstrumentType::ANDROID_PAY_CARD => array(
                'type_ending_in'    => array(
                    'label'   => __( 'Type Ending In', 'woo-payment-gateway' ),
                    'example' => 'Visa ending in 1111',
                    'format'  => __( '{card_type} ending in {last4}', 'woo-payment-gateway' ),
                ),
                'google_type_last4' => array(
                    'label'   => __( 'Type and Last Four', 'woo-payment-gateway' ),
                    'example' => 'Google Pay - Visa 1111',
                    'format'  => 'Google Pay - {card_type} {last4}',
                ),
                'type_last4'        => array(
                    'label'   => __( 'Type and Last Four', 'woo-payment-gateway' ),
                    'example' => 'Visa 1111',
                    'format'  => '{card_type} {last4}',
                ),
            ),
            \Braintree\PaymentInstrumentType::VENMO_ACCOUNT    => array(
                'type_and_user'      => array(
                    'label'   => __( 'Type and User ID', 'woo-payment-gateway' ),
                    'example' => 'Venmo - john.smith1990',
                    'format'  => __( 'Venmo - {username}', 'woo-payment-gateway' ),
                ),
                'source_description' => array(
                    'label'   => __( 'Account Description', 'woo-payment-gateway' ),
                    'example' => 'Venmo Account: john.smith1990',
                    'format'  => '{sourceDescription}',
                ),
            ),
            'local_payment'                                    => array(
                'source_and_payer' => array(
                    'label'   => __( 'Type and Payer Id', 'woo-payment-gateway' ),
                    'example' => 'iDEAL - XF-d647tg',
                    'format'  => '{funding_source} - {payer_id}',
                ),
            ),
        )
    );
}

/**
 *
 * @param \Braintree\Base|\Braintree\Instance $payment_method
 *
 * @since 3.0.0
 * @return WC_Payment_Token
 * @package Braintree/Functions
 */
function wc_braintree_create_payment_token( $method, $gateway_id, $user_id = 0, $environment = '' ) {
    $token = null;
    if ( $method instanceof \Braintree\CreditCard || $method instanceof \Braintree\Transaction\CreditCardDetails ) {
        $token = new WC_Payment_Token_Braintree_CC();
        $token->set_method_type( str_replace( ' ', '', $method->cardType ) );
        $token->set_card_type( $method->cardType );
        $token->set_expiry_month( $method->expirationMonth );
        $token->set_expiry_year( $method->expirationYear );
        $token->set_expiry_date( $method->expirationDate );
        $token->set_card_holder( $method->cardholderName );
        $token->set_bin( $method->bin );
        $token->set_last4( $method->last4 );
        $token->set_masked_number( $method->maskedNumber );
        $token->set_payment_instrument_type( \Braintree\PaymentInstrumentType::CREDIT_CARD );
    }
    if ( $method instanceof \Braintree\PayPalAccount || $method instanceof \Braintree\Transaction\PayPalDetails ) {
        $token = new WC_Payment_Token_Braintree_PayPal();
        $token->set_method_type( 'PayPal' );
        if ( $method instanceof \Braintree\Transaction\PayPalDetails ) {
            $token->set_email( $method->payerEmail );
            $token->set_first_name( $method->payerFirstName );
            $token->set_last_name( $method->payerLastName );
        } else {
            $token->set_email( $method->email );
        }
        $token->set_payment_instrument_type( \Braintree\PaymentInstrumentType::PAYPAL_ACCOUNT );
    }
    if ( $method instanceof \Braintree\ApplePayCard || $method instanceof \Braintree\Transaction\ApplePayCardDetails ) {
        $token = new WC_Payment_Token_Braintree_ApplePay();
        $token->set_card_type( $method->cardType );
        $token->set_method_type( 'ApplePay' );
        $token->set_expiry_month( $method->expirationMonth );
        $token->set_expiry_year( $method->expirationYear );
        $token->set_card_holder( $method->cardholderName );
        $token->set_bin( $method->bin );
        $token->set_last4( $method->last4 );
        $token->set_masked_number( $token->get_bin() . '******' . $token->get_last4() );
        $token->set_payment_instrument_name( $method->paymentInstrumentName );
        $token->set_payment_instrument_type( \Braintree\PaymentInstrumentType::APPLE_PAY_CARD );
    }
    if ( $method instanceof \Braintree\AndroidPayCard || $method instanceof \Braintree\Transaction\AndroidPayCardDetails ) {
        $token = new WC_Payment_Token_Braintree_GooglePay();
        $token->set_card_type( $method->sourceCardType );
        $token->set_method_type( 'GooglePay' );
        $token->set_expiry_month( $method->expirationMonth );
        $token->set_expiry_year( $method->expirationYear );
        $token->set_bin( $method->bin );
        $token->set_last4( $method->sourceCardLast4 );
        $token->set_source_description( $method->sourceDescription );
        $token->set_virtual_card_type( $method->virtualCardType );
        $token->set_virtual_last4( $method->virtualCardLast4 );
        $token->set_masked_number( $token->get_bin() . '******' . $token->get_last4() );
        $token->set_payment_instrument_type( \Braintree\PaymentInstrumentType::ANDROID_PAY_CARD );
    }
    if ( $method instanceof \Braintree\VenmoAccount || $method instanceof \Braintree\Transaction\VenmoAccountDetails ) {
        $token = new WC_Payment_Token_Braintree_Venmo();
        $token->set_source_description( $method->sourceDescription );
        $token->set_username( $method->username );
        $token->set_venmo_user_id( $method->venmoUserId );
        $token->set_method_type( 'Venmo' );
        $token->set_payment_instrument_type( \Braintree\PaymentInstrumentType::VENMO_ACCOUNT );
    }
    if ( 'braintree_ideal' === $gateway_id && is_array( $method ) ) {
        $method = (object) $method;
        $token  = new WC_Payment_Token_Braintree_Local_Payment();
        $token->set_funding_source( $method->fundingSource );
        $token->set_payer_id( $method->payerId );
        $token->set_payment_id( $method->paymentId );
        $token->set_payment_instrument_type( 'local_payment' );
    }
    $token->set_token( $method->token );
    $token->set_gateway_id( $gateway_id );
    $token->set_user_id( ! $user_id ? get_current_user_id() : $user_id );
    $token->set_format( wc_braintree_get_payment_method_format( $gateway_id ) );
    $token->set_environment( empty( $environment ) ? wc_braintree_environment() : $environment );

    return $token;
}

/**
 *
 * @param string $gateway_id
 *
 * @return string
 * @version 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_get_payment_method_format( $gateway_id ) {
    $gateway = WC()->payment_gateways()->payment_gateways()[ $gateway_id ];

    return apply_filters( 'wc_braintree_get_payment_method_format', $gateway->get_option( 'method_format' ), $gateway );
}

/**
 * Return an array of payment gateways that support wc_braintree_fee
 *
 * @since 3.0.0
 * @return WC_Braintree_Payment_Gateway[]
 * @package Braintree/Functions
 */
function wc_braintree_get_fee_gateways() {
    $gateways = WC()->payment_gateways()->payment_gateways();
    foreach ( $gateways as $id => $gateway ) {
        if ( ! $gateway->supports( 'wc_braintree_fees' ) ) {
            unset( $gateways[ $id ] );
        }
    }

    return apply_filters( 'wc_braintree_get_fee_gateways', $gateways );
}

/**
 * Return true if the WooCommerce Subscriptions plugin is active.
 *
 * @since 3.0.0
 * @return boolean
 * @package Braintree/Functions
 */
function wcs_braintree_active() {
    return function_exists( 'wcs_is_subscription' );
}

/**
 * Return true if the Braintree plugin's subscription functionality is active.
 *
 * @since 3.0.0
 * @return boolean
 * @package Braintree/Functions
 */
function wc_braintree_subscriptions_active() {
    $options = get_option( 'woocommerce_braintree_subscription_settings', array( 'enabled' => 'no' ) );
    if ( empty( $options['enabled'] ) ) {
        $options['enabled'] = 'no';
    }

    return ! wcs_braintree_active() && $options['enabled'] === 'yes';
}

/**
 *
 * @since 3.0.0
 * @return boolean
 * @package Braintree/Functions
 */
function wc_braintree_custom_form_active() {
    return braintree()->payment_gateways()->credit_card->get_option( 'form_type' ) === 'custom_form';
}

/**
 * Echo an input field for a braintree payment_method_nonce.
 *
 * @param WC_Braintree_Payment_Gateway $gateway
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_nonce_field( $gateway, $value = '' ) {
    wc_braintree_hidden_field( $gateway->nonce_key, 'wc-braintree-payment-nonce' );
}

/**
 *
 * @param WC_Braintree_Payment_Gateway $gateway
 * @param string                       $token
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_payment_token_field( $gateway, $token = '' ) {
    wc_braintree_hidden_field( $gateway->token_key, 'wc-braintree-payment-token' );
}

/**
 *
 * @param WC_Braintree_Payment_Gateway $gateway
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_device_data_field( $gateway ) {
    wc_braintree_hidden_field( $gateway->device_data_key, 'wc-braintree-device-data' );
}

/**
 *
 * @param string $key
 * @param string $class
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_hidden_field( $key, $class = '' ) {
    printf( '<input type="hidden" id="%1$s" name="%1$s" class="%2$s"/>', $key, $class );
}

/**
 *
 * @since 3.1.5
 * @package Braintree/Functions
 */
function wc_braintree_spam_bot_field() {
    if ( braintree()->WC_BRAINTREE_SPAM_COUNT == 0 ) {
        printf( '<input type="checkbox" value="1" name="braintree_customer_email" style="display: none" autocomplete="off" tabindex="-1"/>' );
        braintree()->WC_BRAINTREE_SPAM_COUNT ++;
    }
}

/**
 *
 * @return boolean
 * @package Braintree/Functions
 * @version 3.0.0
 */
function wc_braintree_save_cc_enabled() {
    global $wp;
    if ( wcs_braintree_active() ) {
        if ( WC_Subscriptions_Cart::cart_contains_subscription() || wcs_cart_contains_renewal() ) {
            return false;
        }
        if ( WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment ) {
            return false;
        }
    }
    if ( wc_braintree_subscriptions_active() ) {
        if ( wcs_braintree_cart_contains_subscription() ) {
            return false;
        }
        if ( wcs_braintree_is_change_payment_method_request() ) {
            return false;
        }
        if ( ! empty( $wp->query_vars['order-pay'] ) ) {
            return ! wcs_braintree_order_contains_subscription( absint( $wp->query_vars['order-pay'] ) );
        }
    }
    // added 3.1.10
    if ( wc_braintree_pre_orders_active() && WC_Pre_Orders_Cart::cart_contains_pre_order() ) {
        return ! WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() );
    }

    return apply_filters(
        'wc_braintree_save_cc_enabled',
        is_user_logged_in() && is_checkout() && WC()->payment_gateways()->payment_gateways()['braintree_cc']->is_active( 'save_card_enabled' )
    );
}

/**
 *
 * @param WC_Payment_Token_Braintree $method
 * @param string                     $format
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_payment_method_title( $method, $format_key = '' ) {
    $format = wc_braintree_payment_method_formats()[ $method->get_payment_instrument_type() ][ $format_key ]['format'];
    $data   = $method->get_props_data();

    return apply_filters( 'wc_braintree_payment_method_title', str_replace( array_keys( $data ), $data, $format ), $method, $format_key );
}

/**
 *
 * @param array $classes
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_add_body_class( $classes ) {
    $classes[] = 'wc-braintree-body';

    return $classes;
}

/**
 * Return the merchant account based on WC currency.
 *
 * @param string $currency
 * @param string $env
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_get_merchant_account( $currency = '', $env = '' ) {
    $accounts = wc_braintree_get_merchant_accounts( $env );
    $currency = empty( $currency ) ? get_woocommerce_currency() : $currency;

    $account = isset( $accounts[ $currency ] ) ? $accounts[ $currency ] : '';

    /**
     * @param string $account
     * @param string $currency
     *
     * @since 3.2.1
     */
    return apply_filters( 'wc_braintree_get_merchant_account', $account, $currency );
}

/**
 * Return all merchant accounts for the given environment.
 * If no env is provided then active
 * environment is used.
 *
 * @param string $env
 *
 * @since 3.0.0
 * @return array
 * @package Braintree/Functions
 */
function wc_braintree_get_merchant_accounts( $env = '' ) {
    $env = empty( $env ) ? wc_braintree_environment() : $env;

    /**
     * @since 3.2.1
     */
    return apply_filters( 'wc_braintree_get_merchant_accounts', braintree()->merchant_settings->get_option( "{$env}_merchant_accounts" ), $env );
}

/**
 * @param        $user_id
 * @param string $env
 *
 * @since 3.0.0
 * @return mixed|boolean|string|unknown
 * @package Braintree/Functions
 */
function wc_braintree_get_customer_id( $user_id = '', $env = '' ) {
    // if the user id is zero, then a non logged in user was passed to the function.
    if ( $user_id === 0 ) {
        return '';
    }
    $user_id = empty( $user_id ) ? get_current_user_id() : $user_id;
    $env     = empty( $env ) ? wc_braintree_environment() : $env;

    return apply_filters( 'wc_braintree_get_customer_id', get_user_option( "braintree_{$env}_vault_id", $user_id ), $user_id, $env );
}

/**
 *
 * @param int    $user_id
 * @param int    $vault_id
 * @param string $env
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_save_customer( $user_id, $vault_id, $env = '' ) {
    $env = empty( $env ) ? wc_braintree_environment() : $env;
    update_user_option( $user_id, "braintree_{$env}_vault_id", apply_filters( 'wc_braintree_save_customer_id', $vault_id ) );
}

function wc_braintree_delete_customer( $user_id, $env = '', $global = false ) {
    $env = empty( $env ) ? wc_braintree_environment() : $env;
    delete_user_option( $user_id, "braintree_{$env}_vault_id", $global );
}

/**
 *
 * @param \Braintree\Result $response
 *
 * @since 3.0.0
 * @noinspection PhpSingleStatementWithBracesInspection
 * @package Braintree/Functions
 */
function wc_braintree_errors_from_object( $response ) {
    $message  = '';
    $messages = wc_braintree_get_error_messages();
    if ( $response instanceof \Braintree\Exception ) {
        if ( isset( $messages[ get_class( $response ) ] ) ) {
            $message = $messages[ get_class( $response ) ];
        }
    } elseif ( $response instanceof \Braintree\Result\Error ) {
        if ( $response->errors->count() > 0 ) {
            foreach ( $response->errors->deepAll() as $error ) {
                if ( isset( $messages[ $error->code ] ) ) {
                    $message = apply_filters( 'wc_braintree_errors_from_collection', $messages[ $error->code ], $error );
                }
                if ( empty( $message ) ) {
                    $message = $error->message;
                }
                if ( substr( $message, - 1 ) !== '.' ) {
                    $message .= '.';
                }
                $message .= ' ';
            }
        } elseif ( $response->message ) {
            // added in 3.1.10
            $key = strtolower( str_replace( ' ', '_', $response->message ) );
            if ( isset( $messages[ $key ] ) ) {
                $message = $messages[ $key ];
            } else {
                $message = apply_filters( 'wc_braintree_result_error_message', $response->message );
            }
        }
    }
    if ( is_string( $response ) ) {
        $message = $response;
    }

    return apply_filters( 'wc_braintree_errors_from_object', $message, $response );
}

/**
 *
 * @param \Braintree\Transaction $transaction
 *
 * @return WC_Payment_Token_Braintree
 * @package Braintree/Functions
 */
function wc_braintree_create_payment_token_from_transaction( $transaction, $gateway_id, $user_id = 0 ) {
    $payment_details = null;
    switch ( $transaction->paymentInstrumentType ) {
        case \Braintree\PaymentInstrumentType::CREDIT_CARD:
            $payment_details = $transaction->creditCardDetails;
            break;
        case \Braintree\PaymentInstrumentType::PAYPAL_ACCOUNT:
            $payment_details = $transaction->paypalDetails;
            break;
        case \Braintree\PaymentInstrumentType::APPLE_PAY_CARD:
            $payment_details = $transaction->applePayCardDetails;
            break;
        case \Braintree\PaymentInstrumentType::ANDROID_PAY_CARD:
            $payment_details = $transaction->androidPayCardDetails;
            break;
        case \Braintree\PaymentInstrumentType::VENMO_ACCOUNT:
            $payment_details = $transaction->venmoAccountDetails;
            break;
        case 'local_payment':
            $payment_details = $transaction->localPayment;
            break;
    }

    return wc_braintree_create_payment_token( $payment_details, $gateway_id, $user_id );
}

/**
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_set_checkout_error() {
    add_action( 'woocommerce_after_template_part', 'wc_braintree_output_checkout_error' );
}

/**
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_output_checkout_error( $template_name ) {
    if ( $template_name === 'notices/error.php' && is_ajax() ) {
        echo '<input type="hidden" id="wc_braintree_checkout_error" value="true"/>';
        remove_action( 'woocommerce_after_template_part', 'wc_braintree_output_checkout_error' );
        add_filter( 'wp_kses_allowed_html', 'wc_braintree_add_allowed_html', 10, 2 );
    }
}

/**
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_add_allowed_html( $tags, $context ) {
    if ( $context === 'post' ) {
        $tags['input'] = array(
            'id'    => true,
            'type'  => true,
            'value' => true,
        );
    }

    return $tags;
}

/**
 *
 * @param int              $token_id
 * @param WC_Payment_Token $token
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_woocommerce_payment_token_deleted( $token_id, $token ) {
    if ( ! did_action( 'woocommerce_payment_gateways' ) ) {
        WC_Payment_Gateways::instance();
    }
    do_action( 'wc_braintree_payment_token_deleted_' . $token->get_gateway_id(), $token_id, $token );
}

/**
 * Filter Braintree payment tokens based on the current environment.
 * You wouldn't want to show sandbox
 * payment tokens when the current environment is production.
 *
 * @param WC_Payment_Token[] $tokens
 * @param int                $user_id
 * @param string             $gateway_id
 *
 * @since 3.0.0
 * @deprecated
 *
 * @package Braintree/Functions
 */
function wc_braintree_filter_customer_payment_tokens( $tokens, $user_id, $gateway_id ) {
    foreach ( $tokens as $i => $token ) {
        if ( strpos( $token->get_type(), 'Braintree_' ) !== false ) {
            $env = wc_braintree_environment();
            if ( $env !== $token->get_meta( 'environment' ) ) {
                unset( $tokens[ $i ] );
            }
        }
    }

    return $tokens;
}

/**
 * Filter payment tokens based on the current environment.
 *
 * @param WC_Payment_Token[] $tokens
 * @param int                $user_id
 * @param string             $gateway_id
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_filter_payment_tokens( $tokens, $user_id, $gateway_id ) {
    $env = wc_braintree_environment();
    foreach ( $tokens as $i => $token ) {
        if ( $token instanceof WC_Payment_Token_Braintree ) {
            if ( $env !== $token->get_environment() ) {
                unset( $tokens[ $i ] );
            }
        }
    }

    return $tokens;
}

/**
 * Returns a list of Payment tokens and bypasses WordPress's number of posts retriction.
 *
 * @param int    $user_id
 * @param string $env
 *
 * @since 3.0.2
 * @return WC_Payment_Token_Braintree[]
 * @package Braintree/Functions
 */
function wc_braintree_get_payment_tokens( $user_id, $env = '' ) {
    global $wpdb;
    $tokens = array();
    if ( ! $user_id ) {
        return $tokens;
    }
    $results = $wpdb->get_results( $wpdb->prepare( "SELECT tokens.token_id FROM {$wpdb->prefix}woocommerce_payment_tokens as tokens WHERE tokens.user_id=%d AND tokens.gateway_id LIKE %s",
        $user_id,
        'braintree_%' ) );
    if ( $results ) {
        foreach ( $results as $result ) {
            $token                       = WC_Payment_Tokens::get( $result->token_id );
            $tokens[ $result->token_id ] = $token;
            if ( ! $token instanceof WC_Payment_Token_Braintree || ( $env && $env !== $token->get_environment() ) ) {
                unset( $tokens[ $result->token_id ] );
            }
        }
    }

    return $tokens;
}

/**
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_get_card_type_icons() {
    $path       = braintree()->assets_path() . 'img/';
    $gateway    = WC()->payment_gateways()->payment_gateways()['braintree_cc'];
    $icon_style = $gateway ? $gateway->get_option( 'icon_style' ) : 'closed';

    return apply_filters(
        'wc_braintree_get_card_type_icons',
        array(
            'Visa'            => sprintf( '<img class="wc-braintree-method-icon %s visa" src="%s"/>',
                $icon_style,
                $path . "payment-methods/{$icon_style}/visa.svg" ),
            'MasterCard'      => sprintf(
                '<img class="wc-braintree-method-icon %s mastercard" src="%s"/>',
                $icon_style,
                $path .
                "payment-methods/{$icon_style}/master_card.svg"
            ),
            'AmericanExpress' => sprintf( '<img class="wc-braintree-method-icon %s amex" src="%s"/>',
                $icon_style,
                $path . "payment-methods/{$icon_style}/amex.svg" ),
            'Discover'        => sprintf(
                '<img class="wc-braintree-method-icon %s discover" src="%s"/>',
                $icon_style,
                $path .
                "payment-methods/{$icon_style}/discover.svg"
            ),
            'DinersClub'      => sprintf(
                '<img class="wc-braintree-method-icon %s diners" src="%s"/>',
                $icon_style,
                $path .
                "payment-methods/{$icon_style}/diners_club_international.svg"
            ),
            'JCB'             => sprintf( '<img class="wc-braintree-method-icon %s jcb" src="%s"/>',
                $icon_style,
                $path . "payment-methods/{$icon_style}/jcb.svg" ),
            'Maestro'         => sprintf( '<img class="wc-braintree-method-icon %s maestro" src="%s"/>',
                $icon_style,
                $path . "payment-methods/{$icon_style}/maestro.svg" ),
            'PayPal'          => sprintf( '<img class="wc-braintree-method-icon paypal" src="%s"/>', $path . 'payment-methods/paypal.svg' ),
            'GooglePay'       => sprintf( '<img class="wc-braintree-method-icon googlepay" src="%s"/>', $path . 'googlepay/google_pay_standard.svg' ),
            'UnionPay'        => sprintf(
                '<img class="wc-braintree-method-icon %s unionpay" src="%s"/>',
                $icon_style,
                $path .
                "payment-methods/{$icon_style}/china_union_pay.svg"
            ),
            'ApplePay'        => sprintf( '<img class="wc-braintree-method-icon applepay" src="%s"/>', $path . 'applepay/apple_pay_mark.svg' ),
            'Venmo'           => sprintf(
                '<img class="wc-braintree-method-icon venmo" src="%s"/>',
                $path . 'payment-methods/venmo.svg'
            ),
        )
    );
}

/**
 *
 * @param string $condition
 *
 * @since 3.0.0
 * @return boolean
 * @package Braintree/Functions
 */
function wc_braintree_evaluate_condition( $condition ) {
    if ( ! $condition ) {
        return true;
    }
    $evaluator = new WC_Braintree_Condition_Evaluator();

    return $evaluator->evaluate( $condition, wc_braintree_get_conditional_values() );
}

/**
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_get_conditional_values() {
    if ( ! WC()->cart ) {
        return array();
    }
    $values = array(
        '{amount}'    => WC()->cart->total,
        '{qty}'       => WC()->cart->get_cart_contents_count(),
        '{currency}'  => get_woocommerce_currency(),
        '{b_country}' => WC()->customer->get_billing_country(),
        '{s_country}' => WC()->customer->get_shipping_country(),
        '{products}'  => wc_braintree_get_products_for_conditions(),
    );

    return apply_filters( 'wc_braintree_get_conditional_values', $values );
}

/**
 *
 * @since 3.0.0
 * @return string
 * @package Braintree/Functions
 */
function wc_braintree_get_products_for_conditions() {
    global $wpdb;
    $products = array();
    $query    = $wpdb->prepare( "SELECT post_name FROM $wpdb->posts WHERE post_type = %s AND post_status = %s", 'product', 'publish' );
    $results  = $wpdb->get_results( $query );
    foreach ( $results as $result ) {
        $products[] = $result->post_name;
    }

    return implode( ',', $products );
}

/**
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_get_3ds_actions() {
    return apply_filters(
        'wc_braintree_get_3ds_actions',
        array(
            'no_action'      => __( 'No Action (Braintree will handle)', 'woo-payment-gateway' ),
            'authorize_only' => __( 'Authorize Amount', 'woo-payment-gateway' ),
            'reject'         => __( 'Reject Transaction', 'woo-payment-gateway' ),
            'accept'         => __(
                'Accept Transaction',
                'woo-payment-gateway'
            ),
        )
    );
}

/**
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_order_statuses_for_registration() {
    return apply_filters(
        'wc_braintree_order_statuses_for_registration',
        array(
            'wc-kount-review'   => array(
                'label'                     => _x( 'Kount review required', 'Order status', 'woo-payment-gateway' ),
                'public'                    => false,
                'exclude_from_search'       => false,
                'show_in_admin_all_list'    => true,
                'show_in_admin_status_list' => true,
                'label_count'               => _n_noop( 'Kount review required <span class="count">(%s)</span>',
                    'Kount review required <span class="count">(%s)</span>',
                    'woo-payment-gateway' ),
            ),
            'wc-kount-escalate' => array(
                'label'                     => _x( 'Kount escalate', 'Order status', 'woo-payment-gateway' ),
                'public'                    => false,
                'exclude_from_search'       => false,
                'show_in_admin_all_list'    => true,
                'show_in_admin_status_list' => true,
                'label_count'               => _n_noop(
                    'Kount escalate <span class="count">(%s)</span>',
                    'Kount escalate <span class="count">(%s)</span>',
                    'woo-payment-gateway'
                ),
            ),
        )
    );
}

/**
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_order_statuses() {
    return apply_filters(
        'wc_braintree_order_statuses',
        array(
            'wc-kount-review'   => __( 'Kount review required', 'woo-payment-gateway' ),
            'wc-kount-escalate' => __(
                'Kount escalate',
                'woo-payment-gateway'
            ),
        )
    );
}

/**
 *
 * @param array $statuses
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_merge_order_statuses( $statuses ) {
    if ( braintree()->fraud_settings ) {
        if ( braintree()->fraud_settings->is_active( 'kount_enabled' ) ) {
            $statuses = array_merge( $statuses, wc_braintree_order_statuses() );
        }
    }

    return $statuses;
}

/**
 *
 * @param string $xml
 * @param string $start
 * @param string $end
 * @param bool   $include_start_end
 *
 * @since 3.0.0
 * @return string
 * @package Braintree/Functions
 */
function wc_braintree_parse_xml_contents( $xml, $start, $end, $include_start_end = true ) {
    $strpos   = strpos( $xml, $start ) + strlen( $start ); // $start = $subscription
    $strpos2  = strrpos( $xml, $end ); // last occurance of $end
    $length   = absint( $strpos2 - $strpos );
    $contents = substr( $xml, $strpos, $length );

    return $include_start_end ? trim( sprintf( '%s%s%s', $start, $contents, $end ) ) : trim( $contents );
}

/**
 * Return the Braintree environment that this order was created for.
 * <ul>
 * <li>sandbox</li>
 * <li>production</li>
 * </ul>
 *
 * @param WC_Order $order
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_get_order_environment( $order ) {
    return $order->get_meta( Constants::ENVIRONMENT, true );
}

/**
 * Hooks in to woocommerce_payment_complete_order_status and updates the order status based
 * on gateway settings.
 *
 * @param string   $status
 * @param int      $id
 * @param WC_Order $order
 *
 * @since 3.0.0
 * @return mixed
 * @package Braintree/Functions
 */
function wc_braintree_payment_complete_order_status( $status, $id, $order = null ) {
    if ( did_action( 'woocommerce_pre_payment_complete' ) ) {
        if ( null === $order ) {
            $order = wc_get_order( $id );
        }
        $gateway_id = $order->get_payment_method();
        $gateways   = WC()->payment_gateways()->payment_gateways();
        if ( isset( $gateways[ $gateway_id ] ) ) {
            $gateway = $gateways[ $gateway_id ];
            if ( $gateway instanceof WC_Braintree_Payment_Gateway ) {
                if ( $gateway->get_option( 'order_status' ) !== 'default' ) {
                    $status = $gateway->get_option( 'order_status' );
                }
            }
        }
    }

    return $status;
}

/**
 * Hooked in to the webhook notification test
 *
 * @param \Braintree\WebhookNotification $notification
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_webhook_check( $notification ) {
    wc_braintree_log_info( sprintf( __( 'Webhook test notification received.', 'woo-payment-gateway' ) ) );
}

/**
 *
 * @param array $gateways
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_payment_gateways( $gateways ) {
    return array_merge( $gateways, braintree()->payment_gateways() );
}

/**
 * Given a Braintree transaction object, map the cvvResponseCode etc to human readable messages.
 *
 * @param \Braintree\Transaction $transaction
 *
 * @since 3.0.0
 * @package Braintree/Functions
 */
function wc_braintree_get_response_code_message( $code ) {
    $codes = array(
        'I' => 'Not provided (I)',
        'M' => 'Matches (M)',
        'N' => 'Does not match (N)',
        'U' => 'Not verified (U)',
        'S' => 'Issuer does not participate (S)',
        'A' => 'Not applicable (A)',
        'B' => 'Bypass (B)',
    );

    return $codes[ $code ];
}

/**
 * Returns an array of localized local payment gateway params used on the
 * checkout page.
 *
 * @param array  $data
 * @param string $handle
 *
 * @since 3.0.0
 * @return string[]|string[][]|NULL[]
 * @package Braintree\Functions
 */
function wc_braintree_local_payment_params( $data, $handle ) {
    global $wp;
    $data     = array();
    $gateways = wc_braintree_get_local_gateways();
    $data     = array(
        'gateways' => array_map(
            function ( $gateway ) {
                return $gateway->localize_script_params();
            },
            $gateways
        ),
    );
    if ( isset( $wp->query_vars['order-pay'] ) ) {
        $data['order_id']  = absint( $wp->query_vars['order-pay'] );
        $data['order_key'] = wc_get_order( $data['order_id'] )->get_order_key();
    }

    return $data;
}

/**
 *
 * @since 3.0.0
 * @return WC_Braintree_Local_Payment_Gateway[]
 * @package Braintree\Functions
 */
function wc_braintree_get_local_gateways() {
    return array_values(
        array_filter(
            WC()->payment_gateways()->get_available_payment_gateways(),
            function ( $gateway ) {
                return $gateway instanceof WC_Braintree_Local_Payment_Gateway;
            }
        )
    );
}

/**
 * Update the WC customer's address information using the provided address array.
 *
 * @param array $address
 *
 * @since 3.0.0
 * @throws Exception
 * @package Braintree\Functions
 */
function wc_braintree_update_customer_location( $address ) {
    // address validation for countries other than US is problematic when using responses from payment sources like
    // Apple Pay.
    if ( $address['postcode'] && $address['country'] === 'US' && ! WC_Validation::is_postcode( $address['postcode'], $address['country'] ) ) {
        throw new Exception( __( 'Please enter a valid postcode / ZIP.', 'woocommerce' ) );
    } elseif ( $address['postcode'] ) {
        $address['postcode'] = wc_format_postcode( $address['postcode'], $address['country'] );
    }

    if ( $address['country'] ) {
        WC()->customer->set_billing_location( $address['country'], $address['state'], $address['postcode'], $address['city'] );
        WC()->customer->set_shipping_location( $address['country'], $address['state'], $address['postcode'], $address['city'] );
        // set the customer's address if it's in the $address array
        if ( ! empty( $address['address_1'] ) ) {
            WC()->customer->set_shipping_address_1( wc_clean( $address['address_1'] ) );
        }
        if ( ! empty( $address['address_2'] ) ) {
            WC()->customer->set_shipping_address_2( wc_clean( $address['address_2'] ) );
        }
        if ( ! empty( $address['first_name'] ) ) {
            WC()->customer->set_shipping_first_name( $address['first_name'] );
        }
        if ( ! empty( $address['last_name'] ) ) {
            WC()->customer->set_shipping_last_name( $address['last_name'] );
        }
    } else {
        WC()->customer->set_billing_address_to_base();
        WC()->customer->set_shipping_address_to_base();
    }

    WC()->customer->set_calculated_shipping( true );
    WC()->customer->save();

    do_action( 'woocommerce_calculated_shipping' );
}

/**
 *
 * @since 3.0.2
 * @deprecated
 * @package Braintree/Functions
 */
function wc_braintree_enqueue_local_payments() {
    foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
        if ( $gateway instanceof WC_Braintree_Local_Payment_Gateway ) {
            $scripts = braintree()->scripts();
            if ( ! wp_script_is( $scripts->get_handle( 'local-payment' ) ) ) {
                $scripts->enqueue_script(
                    'local-payment',
                    $scripts->assets_url( 'js/frontend/local-payment.js' ),
                    array(
                        $scripts->get_handle( 'client-manager' ),
                        $scripts->get_handle( 'local-payment-v3' ),
                    ),
                    braintree()->version
                );
                $scripts->localize_script( 'local-payment', array() );

                return;
            }
        }
    }
}

/**
 *
 * @param \Braintree\WebhookNotification $notification
 * @param WP_REST_Request                $request
 *
 * @since 3.0.2
 * @package Braintree/Functions
 */
function wc_braintree_local_payment_completed( $notification, $request ) {
    $payment_id = $notification->localPaymentCompleted->paymentId;

    $order = wc_braintree_get_order_for_payment_id( $payment_id );
    if ( ! $order ) {
        wc_braintree_log_error( sprintf( 'Webhook error: no order found in your shop for paymentId %s', $payment_id ) );

        return;
    }
    $args = array( $payment_id, $notification->localPaymentCompleted->paymentMethodNonce, $order->get_id() );

    // schedule the payment action to run in 5 minutes time. This will give the client time to process
    // a payment. If the customer leaves the page, then payment will be processed via the scheduled action.
    if ( method_exists( WC(), 'queue' ) ) {
        WC()->queue()->schedule_single( time() + MINUTE_IN_SECONDS * 5, 'wc_braintree_process_scheduled_local_payment', $args );
    }
}

/**
 * @param string $payment_id
 * @param string $nonce
 * @param int    $order_id
 *
 * @since 3.2.1
 * @package Braintree/Functions
 */
function wc_braintree_process_scheduled_local_payment( $payment_id, $nonce, $order_id ) {
    $order = wc_get_order( $order_id );
    /**
     *
     * @var WC_Braintree_Local_Payment_Gateway $payment_method
     */
    $payment_method = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
    if ( ! $payment_method->has_order_lock( $order ) && $order->needs_payment() ) {
        // hack to load WC functions required in process_payment method
        if ( function_exists( 'wc_load_cart' ) ) {
            WC()->frontend_includes();
            wc_load_cart();
        } else {
            WC()->frontend_includes();
            include_once( WC_ABSPATH . 'includes/class-wc-session-handler.php' );
            WC()->cart    = new WC_Cart();
            WC()->session = new WC_Session_Handler();
        }
        $payment_method->set_payment_method_nonce( $nonce );
        $payment_method->process_payment( $order_id );
        wc_braintree_log_info( sprintf( 'Order %s processed via scheduled action.', $order_id ) );
    }
}

/**
 * Returns true of the WC Pre Order plugin is active.
 *
 * @since 3.0.6
 * @return boolean
 * @package Braintree/Functions
 */
function wc_braintree_pre_orders_active() {
    return class_exists( 'WC_Pre_Orders' );
}

/**
 *
 * @param string $payment_id
 *
 * @since 3.0.8
 * @return WC_Order|null
 * @package Braintree/Functions
 */
function wc_braintree_get_order_for_payment_id( $payment_id ) {
    global $wpdb;
    $result
        = $wpdb->get_row( $wpdb->prepare( "SELECT ID FROM $wpdb->posts as posts INNER JOIN $wpdb->postmeta as postmeta ON postmeta.post_id = posts.ID WHERE posts.post_type = 'shop_order' AND postmeta.meta_key = '_wc_braintree_payment_id' AND postmeta.meta_value = %s",
        $payment_id ) );
    if ( $result ) {
        $order_id = $result->ID;

        return wc_get_order( $order_id );
    }

    return null;
}

/**
 *
 * @since 3.1.8
 * @return boolean
 * @package Braintree/Functions
 */
function wc_braintree_display_prices_including_tax() {
    $cart = WC()->cart;
    if ( method_exists( $cart, 'display_prices_including_tax' ) ) {
        return $cart->display_prices_including_tax();
    }
    if ( is_callable( array( $cart, 'get_tax_price_display_mode' ) ) ) {
        return 'incl' == $cart->get_tax_price_display_mode() && ( WC()->customer && ! WC()->customer->is_vat_exempt() );
    }

    return 'incl' == $cart->tax_display_cart && ( WC()->customer && ! WC()->customer->is_vat_exempt() );
}

/**
 * Generates a client token used for setting up the Braintree SDK. The merchant account is passed
 * as an argument, so this method reliably determines which merchant account to use based on the
 * store's currency, the order's currency etc.
 *
 * @param string $env
 *
 * @since 3.2.4
 * @return string
 * @return string
 * @package Braintree/Functions
 */
function wc_braintree_generate_client_token( $env = '' ) {
    $client_token = '';
    try {
        $args = array();
        if ( ( $merchant_account = wc_braintree_get_merchant_account( wc_braintree_get_currency() ) ) ) {
            $args['merchantAccountId'] = $merchant_account;
        }
        $gateway      = new \Braintree\Gateway( wc_braintree_connection_settings( $env ) );
        $client_token = $gateway->clientToken()->generate( $args );
    } catch ( \Braintree\Exception $e ) {
        wc_braintree_log_error( sprintf( __( 'Error creating client token. Exception: %1$s', 'woo-payment-gateway' ), get_class( $e ) ) );
    }

    return $client_token;
}

/**
 * Returns the store's currency based on factors like if it's the checkout page, order pay page, etc.
 *
 * @since 3.2.4
 * @return string
 * @package Braintree/Functions
 */
function wc_braintree_get_currency() {
    global $wp;

    if ( is_checkout() ) {
        if ( ! empty( $wp->query_vars['order-pay'] ) ) {
            $order    = wc_get_order( absint( $wp->query_vars['order-pay'] ) );
            $currency = $order->get_currency();
        } else {
            $currency = get_woocommerce_currency();
        }
    } elseif ( is_cart() || is_product() || is_add_payment_method_page() ) {
        $currency = get_woocommerce_currency();
    } elseif ( wc_braintree_subscriptions_active() && wcs_braintree_is_change_payment_method_request() ) {
        $order    = wc_get_order( absint( $wp->query_vars['change-payment-method'] ) );
        $currency = $order->get_currency();
    } else {
        $currency = get_woocommerce_currency();
    }

    /**
     * @param string $currency
     */
    return apply_filters( 'wc_braintree_get_currency', $currency );
}

/**
 * @param string $page
 *
 * @since 3.2.5
 * @return array
 * @package Braintree/Functions
 */
function wc_braintree_get_checkout_fields( $page = '' ) {
    global $wp;
    $fields = array();
    $order  = null;
    foreach ( array( 'billing', 'shipping' ) as $type ) {
        if ( ( $field_set = WC()->checkout()->get_checkout_fields( $type ) ) ) {
            $fields = array_merge( $fields, $field_set );
        }
    }
    if ( 'order_pay' === $page ) {
        $order = wc_get_order( absint( $wp->query_vars['order-pay'] ) );
    }
    array_walk( $fields, function ( &$field, $key ) use ( $page, $order ) {
        if ( 'order_pay' === $page && null !== $order ) {
            if ( is_callable( array( $order, "get_{$key}" ) ) ) {
                $field['value'] = $order->{"get_{$key}"}();
            } else {
                $field['value'] = WC()->checkout()->get_value( $key );
            }
        } else {
            $field['value'] = WC()->checkout()->get_value( $key );
        }
        if ( isset( $field['required'] ) && ! is_bool( $field['required'] ) ) {
            $field['required'] = (bool) $field['required'];
        }
    } );

    /**
     * @param array  $fields
     * @param string $page
     */
    return apply_filters( 'wc_braintree_get_checkout_fields', $fields, $page );
}
Braintree API documentation generated by ApiGen