• 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 
<?php
defined( 'ABSPATH' ) || exit();

if ( ! class_exists( 'WC_Braintree_Payment_Gateway' ) ) {
    return;
}

/**
 *
 * @since 3.0.0
 * @package Braintree/Classes/Gateways
 *
 */
class WC_Braintree_PayPal_Payment_Gateway extends WC_Braintree_Payment_Gateway {

    protected $has_digital_wallet = true;

    protected $line_item_validations = array(
        'commodityCode'  => 12,
        'description'    => 127,
        'discountAmount' => 2,
        'name'           => 127,
        'productCode'    => 127,
        'taxAmount'      => 2,
        'totalAmount'    => 2,
        'unitAmount'     => 2,
        'unitOfMeasure'  => 12,
        'unitTaxAmount'  => 2,
    );

    /**
     * @var string
     * @since 3.2.5
     */
    protected $paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_CHECKOUT;

    private $sandbox_client_id = 'AZDxjDScFpQtjWTOUtWKbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6liB2CUXlkA59kJXE7M6R';

    public function __construct() {
        $this->id                 = 'braintree_paypal';
        $this->deprecated_id      = 'braintree_paypal_payments';
        $this->token_type         = 'PayPal';
        $this->template           = 'paypal.php';
        $this->method_title       = __( 'Braintree PayPal Gateway', 'woo-payment-gateway' );
        $this->tab_title          = __( 'PayPal', 'woo-payment-gateway' );
        $this->method_description = __( 'Gateway that integrates your PayPal account with Braintree.', 'woo-payment-gateway' );
        $this->icon               = braintree()->assets_path() . 'img/paypal/paypal_long.svg';
        parent::__construct();
    }

    public function add_hooks() {
        parent::add_hooks();
        add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'payment_methods_list_item' ), 10, 2 );
        add_filter( 'wc_braintree_after_checkout_validation_notice', array( $this, 'after_checkout_validation_notice' ), 10, 2 );
        add_filter( 'wc_braintree_mini_cart_deps', array( $this, 'get_mini_cart_dependencies' ), 10, 2 );
        add_filter( 'script_loader_tag', array( $this, 'add_partner_attribution_id' ), 10, 3 );
    }

    public function enqueue_admin_scripts() {
        wp_register_script( 'wc-braintree-paypal-objects', sprintf( 'https://www.paypal.com/sdk/js?client-id=%s&components=buttons', $this->sandbox_client_id ), array(), null, true );
        wp_enqueue_script( 'wc-braintree-paypal-settings', braintree()->assets_path() . 'js/admin/paypal-settings.js', array(
            'wc-braintree-admin-settings',
            'wc-braintree-paypal-objects',
            'jquery-ui-slider'
        ), braintree()->version, true );
    }

    public function set_supports() {
        parent::set_supports();
        $this->supports[] = 'wc_braintree_cart_checkout';
        $this->supports[] = 'wc_braintree_banner_checkout';
        $this->supports[] = 'wc_braintree_product_checkout';
        $this->supports[] = 'wc_braintree_mini_cart';
    }

    /**
     *
     * @param array $item
     * @param WC_Payment_Token $payment_token
     */
    public function payment_methods_list_item( $item, $payment_token ) {
        if ( 'Braintree_PayPal' !== $payment_token->get_type() ) {
            return $item;
        }
        $item['method']['brand']     = $payment_token->get_payment_method_title( $this->get_option( 'method_format' ) );
        $item['expires']             = __( 'N/A', 'woo-payment-gateway' );
        $item['method_type']         = $payment_token->get_method_type();
        $item['wc_braintree_method'] = true;

        return $item;
    }

    /**
     *
     * {@inheritDoc}
     *
     * @see WC_Braintree_Payment_Gateway::enqueue_checkout_scripts()
     */
    public function enqueue_checkout_scripts( $scripts ) {
        $this->register_paypal_script( $scripts );
        $scripts->enqueue_script(
            'paypal',
            $scripts->assets_url( 'js/frontend/paypal.js' ),
            array(
                $scripts->get_handle( 'client-manager' ),
                $scripts->get_handle( 'data-collector-v3' ),
                $scripts->get_handle( 'paypal-checkout-v3' ),
                $scripts->get_handle( 'paypal-checkout' ),
            )
        );
        $scripts->localize_script( 'paypal', $this->get_localized_standard_params() );
    }

    /**
     *
     * {@inheritDoc}
     *
     * @see WC_Braintree_Payment_Gateway::enqueue_cart_scripts()
     */
    public function enqueue_cart_scripts( $scripts ) {
        $this->register_paypal_script( $scripts );
        $scripts->enqueue_script(
            'paypal-cart',
            $scripts->assets_url( 'js/frontend/paypal-cart.js' ),
            array(
                $scripts->get_handle( 'client-manager' ),
                $scripts->get_handle( 'paypal-checkout' ),
                $scripts->get_handle( 'data-collector-v3' ),
                $scripts->get_handle( 'paypal-checkout-v3' ),
            )
        );
        $scripts->localize_script( 'paypal-cart', $this->get_localized_standard_params() );
    }

    /**
     *
     * {@inheritDoc}
     *
     * @see WC_Braintree_Payment_Gateway::enqueue_product_scripts()
     */
    public function enqueue_product_scripts( $scripts ) {
        $this->register_paypal_script( $scripts );
        $scripts->enqueue_script(
            'paypal-product',
            $scripts->assets_url( 'js/frontend/paypal-product.js' ),
            array(
                $scripts->get_handle( 'client-manager' ),
                $scripts->get_handle( 'paypal-checkout' ),
                $scripts->get_handle( 'data-collector-v3' ),
                $scripts->get_handle( 'paypal-checkout-v3' ),
            )
        );
        $params = $this->get_localized_standard_params();
        $params = wp_parse_args( array(
            'button_style'  => array(
                'label'  => $this->product_gateway_option->get_option( 'smartbutton_label' ),
                'color'  => $this->product_gateway_option->get_option( 'smartbutton_color' ),
                'shape'  => $this->product_gateway_option->get_option( 'smartbutton_shape' ),
                'height' => intval( $this->get_option( 'button_height' ) ),
            ),
            'credit_button' => array( 'color' => $this->product_gateway_option->get_option( 'credit_button_color' ) ),
            'bnpl'          => array(
                'enabled'   => $this->product_gateway_option->is_active( 'bnpl_enabled' ),
                'button'    => array( 'color' => $this->product_gateway_option->get_option( 'bnpl_button_color' ) ),
                'msg'       => array(
                    'enabled' => $this->product_gateway_option->is_active( 'pay_later_msg_enabled' ) && $this->can_show_bnpl_msg()
                ),
                'txt_color' => $this->product_gateway_option->get_option( 'pay_later_txt_color' )
            ),
            'display_type'  => "paypal-{$this->product_gateway_option->get_option( 'display_type' )}",
        ), $params );
        $scripts->localize_script( 'paypal-product', $params );
    }

    public function get_localized_standard_params() {
        $data = array_merge_recursive(
            parent::get_localized_standard_params(),
            array(
                'button_style'      => $this->get_button_options(),
                'card_icons'        => $this->is_active( 'smartbutton_cards' ),
                'tokenize_response' => WC()->session ? WC()->session->get( $this->id . '_tokenized_response' ) : null,
                'banner_enabled'    => $this->banner_checkout_enabled(),
                'options'           => array(
                    'flow'        => $this->get_paypal_flow(),
                    'intent'      => $this->get_option( 'charge_type' ),
                    'currency'    => $this->get_checkout_currency(),
                    'displayName' => $this->get_option( 'display_name' )
                ),
                'credit_button'     => array(
                    'color' => $this->get_option( 'credit_button_color' )
                ),
                'bnpl'              => array(
                    'enabled'   => $this->is_active( 'bnpl_enabled' ),
                    'button'    => array(
                        'color' => $this->get_option( 'bnpl_button_color' )
                    ),
                    'sections'  => $this->get_credit_sections(),
                    'msg'       => array(
                        'can_show' => $this->can_show_bnpl_msg() && $this->is_active( 'bnpl_enabled' ),
                        'sections' => $this->get_pay_later_sections()
                    ),
                    'txt_color' => $this->get_option( 'pay_later_txt_color' )
                ),
                'card_button'       => array(
                    'color' => $this->get_option( 'card_button_color' )
                ),
                'button_sorting'    => array(
                    'paypal',
                    'credit',
                    'paylater',
                    'card'
                ),
                'routes'            => array(
                    'paypal_shipping' => WC_Braintree_Rest_API::get_endpoint( braintree()->rest_api->paypal->rest_uri() . '/shipping' )
                )
            )
        );

        return apply_filters( 'wc_braintree_localized_paypal_params', $data );
    }

    public function localize_paypal_params() {
        return $this->get_localized_standard_params();
    }

    /**
     * @return array
     */
    public function get_button_options() {
        $options = array(
            'label'  => $this->get_option( 'smartbutton_label' ),
            'color'  => $this->get_option( 'smartbutton_color' ),
            'shape'  => $this->get_option( 'smartbutton_shape' ),
            'height' => intval( $this->get_option( 'button_height' ) ),
        );

        /**
         * @param array $options
         * @param WC_Braintree_Payment_Gateway $this
         *
         * @since 3.2.4
         */
        return apply_filters( 'wc_braintree_paypal_button_options', $options, $this );
    }

    /**
     * @return bool
     * @deprecated 3.2.8
     */
    public function is_paypal_credit_active() {
        return $this->is_active( 'credit_enabled' ) && wc_braintree_evaluate_condition( $this->get_option( 'credit_conditions', '' ) );
    }

    /**
     * @return bool
     * @since 3.2.8
     */
    public function is_bnpl_active() {
        return $this->is_active( 'bnpl_enabled' );
    }

    /**
     * Returns either "checkout" or "vault" depending on conditions such as if the cart contains
     * subscriptions etc.
     *
     * @param string $page
     *
     * @return string
     */
    public function get_paypal_flow( $page = '' ) {
        if ( in_array( $page, array( 'cart', 'checkout' ) ) || is_checkout() || is_cart() ) {
            global $wp;
            if ( ! empty( $wp->query_vars['order-pay'] ) ) {
                $order = wc_get_order( absint( $wp->query_vars['order-pay'] ) );
                if ( wcs_braintree_active() ) {
                    if ( WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment || wcs_order_contains_subscription( $order ) ) {
                        $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
                    }
                } elseif ( wc_braintree_subscriptions_active() && wcs_braintree_order_contains_subscription( $order ) ) {
                    $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
                } elseif ( wc_braintree_pre_orders_active() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) {
                    $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
                }
            } else {
                if ( wcs_braintree_active() && ( WC_Subscriptions_Cart::cart_contains_subscription() || wcs_cart_contains_renewal() ) ) {
                    $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
                } elseif ( wc_braintree_subscriptions_active() && wcs_braintree_cart_contains_subscription() ) {
                    $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
                } elseif ( wc_braintree_pre_orders_active() && WC_Pre_Orders_Cart::cart_contains_pre_order() ) {
                    $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
                }
            }
        } elseif ( 'product' === $page || is_product() ) {
            // first check if the cart requires vault. If not, check if product requires vault.
            if ( \PaymentPlugins\WC_Braintree_Constants::PAYPAL_CHECKOUT === $this->get_paypal_flow( 'cart' ) ) {
                global $product;
                if ( wcs_braintree_active() && is_a( $product, 'WC_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) {
                    $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
                } elseif ( wc_braintree_subscriptions_active() && is_a( $product, 'WC_Product' ) && wcs_braintree_product_is_subscription( $product ) ) {
                    $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
                } elseif ( wc_braintree_pre_orders_active() && is_a( $product, 'WC_Product' ) && WC_Pre_Orders_Product::product_can_be_pre_ordered( $product ) ) {
                    $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
                }
            }
        } elseif ( $this->is_change_payment_request() ) {
            $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
        } elseif ( is_add_payment_method_page() ) {
            $this->paypal_flow = \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT;
        } else {
            // if no matches then resort to what's in cart to determine flow.
            return $this->get_paypal_flow( 'cart' );
        }

        return apply_filters( 'wc_braintree_get_paypal_flow', $this->paypal_flow, $this, $page );
    }

    public function remove_session_checkout_vars() {
        unset( WC()->session->{$this->id . '_tokenized_response'} );
    }

    /**
     *
     * {@inheritDoc}
     *
     * @see WC_Braintree_Payment_Gateway::get_payment_method_from_transaction()
     */
    public function get_payment_method_from_transaction( $transaction ) {
        return $transaction->paypalDetails;
    }

    /**
     * Method that adds to the validation notice when the selected payment method is PayPal.
     *
     * @param string $notice
     * @param array $data
     */
    public function after_checkout_validation_notice( $notice, $data ) {
        if ( $this->id === $data['payment_method'] ) {
            if ( current_user_can( 'administrator' ) ) {
                $notice .= sprintf(
                    ' ' .
                    __( 'Admin Notice: For virtual products, PayPal must send back the billing address. Click %1$shere%2$s to read how to enable this functionality.', 'woo-payment-gateway' ),
                    '<a target="_blank" href="https://docs.paymentplugins.com/wc-braintree/config/#/braintree_paypal?id=enable-billing-address">',
                    '</a>'
                );
            }
        }

        return $notice;
    }

    /**
     * Returns an array of locales supported by the PayPal smartbuttons.
     *
     * @since 3.0.2
     * @deprecated
     */
    public function get_supported_locales() {
        return apply_filters( 'wc_braintree_paypal_supported_locales', array() );
    }

    /**
     * Determine the user's locale based on their browser settings.
     *
     * @since 3.0.4
     * @deprecated
     */
    public function get_user_locale() {
        $this->get_option( 'locale' );
    }

    /**
     * Decorate the response with data specific to PayPal.
     *
     * @param array $data
     *
     * @retun array
     */
    public function update_shipping_method_response( $data ) {
        $data['cart_totals'] = wc_braintree_get_template_html( 'paypal-cart-totals.php', array( 'gateway' => $this ) );

        return $data;
    }

    protected function add_order_line_items( &$args, $order, &$items = array() ) {
        /**
         * @since 3.2.28 - only allow lines items if this filter returns true. The line item validation on the PayPal side
         * is prone to errors and it's best to disable it by default.
         */
        if ( apply_filters( 'wc_braintree_paypal_order_line_items_enabled', false, $args, $order, $this ) ) {
            /**
             * @since 3.2.21 - added a check for prices including tax because there are issues mapping
             * Braintree fields to PayPal when prices include tax and PayPal fails validation.
             *
             * An example is in the patch call, if prices include tax, then the tax_amount field is set to $0 since
             * all other line items have tax. When the Braintree transaction is processed, tax amount is not $0 and PayPal
             * fails validation since the patch had $0 tax.
             *
             * It's easier to just bypass line items given that scenario.
             */
            if ( ! wc_braintree_display_prices_including_tax() ) {
                parent::add_order_line_items( $args, $order, $items );


                if ( isset( $args['lineItems'] ) ) {
                    // calculate the sum of all the totals.
                    $total = array_sum( array_map( function ( $totals ) {
                        return $totals['subtotal'];
                    }, $this->order_totals ) );

                    // Unset the lineItems if totals do not equal order total. This will prevent validation errors.
                    // In some cases, the line item totals won't equal the order total because of rounding performed
                    // by the plugin to ensure decimal restrictions imposed by PayPal aren't violated.
                    // Other settings like, round at subtotal vs line item could affect this to.
                    if ( abs( $total - $order->get_total() ) > 0.00001 ) {
                        unset( $args['lineItems'] );
                    }
                }
            }
        }

        return $this;
    }

    /**
     * @param WC_Braintree_Frontend_Scripts $scripts
     */
    private function register_paypal_script( $scripts ) {
        if ( $scripts->client_token ) {
            // If flow is vault and script has already been enqueued, then skip. Vault always takes precedence.
            if ( wp_script_is( $scripts->get_handle( 'paypal-checkout' ), 'registered' ) ) {
                if ( $this->paypal_flow === \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT ) {
                    return;
                } else {
                    // de-register so the latest script will be used.
                    wp_deregister_script( $scripts->get_handle( 'paypal-checkout' ) );
                }
            }
            $query_args = array(
                'client-id'  => $scripts->client_token->paypal->clientId,
                'components' => 'buttons,messages',
                'currency'   => wc_braintree_get_currency(),
                'vault'      => $this->get_paypal_flow() === 'vault' ? 'true' : 'false'
            );
            if ( is_checkout() && WC()->cart && WC()->cart->needs_shipping() ) {
                $query_args['commit'] = 'false';
            }
            /* Only add intent arg if this is a checkout flow.
             * https://github.com/paypal/paypal-checkout-components/issues/1290
             */
            if ( $query_args['vault'] === 'false' ) {
                $query_args['intent'] = $this->get_option( 'charge_type' );
            } else {
                $query_args['intent'] = 'tokenize';
            }

            wp_register_script( $scripts->get_handle( 'paypal-checkout' ), add_query_arg( $query_args, 'https://www.paypal.com/sdk/js' ), array(), null, true );
        }
    }

    /**
     * @param array $data
     * @param WP_REST_Request $request
     *
     * @return array
     * @throws Exception
     */
    public function update_shipping_response( $data, $request ) {
        $incl_tax         = wc_braintree_display_prices_including_tax();
        $shipping_options = $this->get_formatted_shipping_methods();
        if ( ! $shipping_options ) {
            throw new Exception( __( 'No shipping methods for provided address', 'woo-payment-gateway' ) );
        }
        $currency = get_woocommerce_currency();
        $decimals = ( ( $decimals = wc_get_price_decimals() ) < 2 ? $decimals : 2 );
        function get_fee_tax() {
            return array_sum( array_map( function ( $fee ) {
                return $fee->tax;
            }, WC()->cart->get_fees() ) );
        }

        $totals     = array(
            'item_total' => wc_format_decimal( $incl_tax ? WC()->cart->subtotal + WC()->cart->fee_total + get_fee_tax() : WC()->cart->subtotal_ex_tax + WC()->cart->fee_total, $decimals ),
            'shipping'   => wc_format_decimal( $incl_tax ? WC()->cart->shipping_total + WC()->cart->shipping_tax_total : WC()->cart->shipping_total, $decimals ),
            'tax_total'  => wc_format_decimal( $incl_tax ? 0 : WC()->cart->get_taxes_total(), $decimals ),
            'discount'   => wc_format_decimal( $incl_tax ? WC()->cart->discount_cart + WC()->cart->discount_cart_tax : WC()->cart->discount_cart, $decimals )
        );
        $cart_total = wc_format_decimal( WC()->cart->total, $decimals );

        $response = array(
            'patch' => array(
                array(
                    'op'    => 'replace',
                    'path'  => '/purchase_units/@reference_id==\'default\'/amount',
                    'value' => array(
                        'currency_code' => $currency,
                        'value'         => $cart_total,
                        'breakdown'     => array(
                            'item_total' => array(
                                'currency_code' => $currency,
                                'value'         => $totals['item_total']
                            ),
                            'shipping'   => array(
                                'currency_code' => $currency,
                                'value'         => $totals['shipping']
                            ),
                            'tax_total'  => array(
                                'currency_code' => $currency,
                                'value'         => $totals['tax_total']
                            ),
                            'discount'   => array(
                                'currency_code' => $currency,
                                'value'         => $totals['discount']
                            )
                        )
                    )
                ),
                array(
                    'op'    => ! $request->get_param( 'shipping_method' ) ? 'add' : 'replace',
                    'path'  => '/purchase_units/@reference_id==\'default\'/shipping/options',
                    'value' => $this->get_formatted_shipping_methods()
                )
            ),
            'html'  => wc_braintree_get_template_html(
                'paypal-shipping-methods.php',
                array(
                    'gateway'                 => $this,
                    'packages'                => $this->get_shipping_packages(),
                    'chosen_shipping_methods' => WC()->session->get(
                        'chosen_shipping_methods',
                        array()
                    ),
                )
            )
        );

        // if breakdown doesn't match amount, don't include it.
        $breakdown_total = array_sum( $totals );
        if ( $breakdown_total != $cart_total ) {
            unset( $response['patch'][0]['value']['breakdown'] );
        }

        $data[ $this->id ] = $response;

        return $data;
    }

    /**
     * @param WC_Shipping_Rate $method
     * @param int $index
     * @param bool $selected
     * @param float $amount
     * @param int $decimals
     *
     * @return array
     */
    public function get_formatted_shipping_method( $method, $index, $selected, $amount, $decimals ) {
        /**
         * @since 3.2.9 use the $method->cost since that's the before tax amount.
         */
        return array(
            'id'       => $this->get_shipping_method_id( $method, $index ),
            'label'    => $method->get_label(),
            'type'     => 'SHIPPING',
            'selected' => $selected,
            'amount'   => array(
                'value'         => wc_format_decimal( $amount, $decimals ),
                'currency_code' => get_woocommerce_currency()
            )
        );
    }

    /**
     * @param array $deps
     * @param WC_Braintree_Frontend_Scripts $scripts
     */
    public function get_mini_cart_dependencies( $deps, $scripts ) {
        if ( $this->mini_cart_enabled() ) {
            $this->register_paypal_script( $scripts );
            $deps[] = $scripts->get_handle( 'paypal-checkout' );
            $deps[] = $scripts->get_handle( 'paypal-checkout-v3' );
        }

        return $deps;
    }

    public function add_partner_attribution_id( $tag, $handle, $src ) {
        if ( 'wc-braintree-paypal-checkout' === $handle ) {
            $tag = str_replace( 'src', 'data-partner-attribution-id="' . braintree()->partner_code . '" src', $tag );
        }

        return $tag;
    }

    /**
     * @return array
     * @since 3.2.7
     */
    private function get_pay_later_sections() {
        return $this->get_option( 'pay_later_msg' );
    }

    /**
     * @return array
     * @since 3.2.7
     */
    private function get_credit_sections() {
        return $this->get_option( 'bnpl_sections' );
    }


    /**
     *
     * @return bool
     * @since 3.2.7
     */
    private function can_show_bnpl_msg() {
        // Can't show Pay Later messaging if the merchant is not selling in USD or sells subscription products.
        /*if ( wcs_braintree_active() || wc_braintree_subscriptions_active() ) {
            return false;
        }*/
        if ( \PaymentPlugins\WC_Braintree_Constants::PAYPAL_VAULT === $this->get_paypal_flow() ) {
            return false;
        }
        if ( ! is_admin() && ! in_array( get_woocommerce_currency(), array( 'USD', 'GBP', 'AUD', 'EUR' ) ) ) {
            return false;
        }

        return true;
    }

    public function get_product_admin_options() {
        $args                                   = wp_parse_args( array(
            'smartbutton_color'     => $this->form_fields['smartbutton_color'],
            'smartbutton_shape'     => $this->form_fields['smartbutton_shape'],
            'smartbutton_label'     => $this->form_fields['smartbutton_label'],
            'pay_later'             => $this->form_fields['pay_later'],
            'bnpl_enabled'          => $this->form_fields['bnpl_enabled'],
            'bnpl_button_color'     => $this->form_fields['bnpl_button_color'],
            'display_type'          => array(
                'title'       => __( 'Display type', 'woo-payment-gateway' ),
                'type'        => 'select',
                'class'       => 'wc-enhanced-select',
                'default'     => 'vertical',
                'options'     => array(
                    'inline'   => __( 'Inline', 'woo-payment-gateway' ),
                    'vertical' => __( 'Vertical', 'woo-payment-gateway' )
                ),
                'desc_tip'    => true,
                'description' => __( 'This option determines if the PayPal button and Credit button are side by side or vertical.', 'woo-payment-gateway' )
            ),
            'pay_later_msg_enabled' => array(
                'title'       => __( 'Enable Pay Later Msg', 'woo-payment-gateway' ),
                'type'        => 'checkbox',
                'default'     => wc_bool_to_string( in_array( 'product', $this->get_pay_later_sections() ) ),
                'value'       => 'yes',
                'desc_tip'    => true,
                'description' => '',
            ),
            'pay_later_txt_color'   => $this->form_fields['pay_later_txt_color']
        ), parent::get_product_admin_options() );
        $args['bnpl_enabled']['default']        = wc_bool_to_string( $this->is_active( 'bnpl_enabled' ) && in_array( 'product', $this->get_credit_sections() ) );
        $args['smartbutton_color']['default']   = $this->get_option( 'smartbutton_color' );
        $args['smartbutton_shape']['default']   = $this->get_option( 'smartbutton_shape' );
        $args['pay_later_txt_color']['default'] = $this->get_option( 'pay_later_txt_color' );

        /*if ( is_admin() && ! $this->can_show_bnpl_msg() ) {
            unset( $args['pay_later'], $args['pay_later_msg_enabled'] );
            $args['no_pay_later'] = array(
                'title' => __( 'Enable Pay Later Msg', 'woo-payment-gateway' ),
                'type'  => 'paragraph',
                'text'  => __( 'Pay Later Messaging cannot be offered on sites that sell subscriptions due to payment regulations.', 'woo-payment-gateway' )
            );
        }*/

        return $args;
    }

    /**
     * @param WC_Braintree_Product_Gateway_Option $product_option
     */
    public function init_product_gateway_settings( $product_option ) {
        // if the credit enabled setting exists then it hasn't been converted to bnpl
        if ( isset( $product_option->settings['credit_enabled'] ) ) {
            $product_option->settings['bnpl_enabled'] = $this->settings['credit_enabled'];

            // unset credit_enabled so we know next time that the settings have been converted to use bnpl
            unset( $product_option->settings['credit_enabled'] );
            $product_option->save();
        }
    }

    public function has_enqueued_scripts( $scripts, $context = 'checkout' ) {
        switch ( $context ) {
            case 'checkout':
                return wp_script_is( $scripts->get_handle( 'paypal' ) );
        }
    }
}
Braintree API documentation generated by ApiGen