get_option( 'api_username' ); $sandbox_api_username = $this->get_option( 'sandbox_api_username' ); $needs_creds = empty( $api_username ); $needs_sandbox_creds = empty( $sandbox_api_username ); $enable_ips = wc_gateway_ppec()->ips->is_supported(); if ( $enable_ips && $needs_creds ) { $ips_button = '' . __( 'Setup or link an existing PayPal account', 'woocommerce-gateway-paypal-express-checkout' ) . ''; $api_creds_text = sprintf( __( '%s or click here to toggle manual API credential input.', 'woocommerce-gateway-paypal-express-checkout' ), $ips_button ); } else { $reset_link = add_query_arg( array( 'reset_ppec_api_credentials' => 'true', 'environment' => 'live', 'reset_nonce' => wp_create_nonce( 'reset_ppec_api_credentials' ), ), wc_gateway_ppec()->get_admin_setting_link() ); $api_creds_text = sprintf( __( 'To reset current credentials and use other account click here.', 'woocommerce-gateway-paypal-express-checkout' ), $reset_link, __( 'Reset current credentials', 'woocommerce-gateway-paypal-express-checkout' ) ); } if ( $enable_ips && $needs_sandbox_creds ) { $sandbox_ips_button = '' . __( 'Setup or link an existing PayPal Sandbox account', 'woocommerce-gateway-paypal-express-checkout' ) . ''; $sandbox_api_creds_text = sprintf( __( '%s or click here to toggle manual API credential input.', 'woocommerce-gateway-paypal-express-checkout' ), $sandbox_ips_button ); } else { $reset_link = add_query_arg( array( 'reset_ppec_api_credentials' => 'true', 'environment' => 'sandbox', 'reset_nonce' => wp_create_nonce( 'reset_ppec_api_credentials' ), ), wc_gateway_ppec()->get_admin_setting_link() ); $sandbox_api_creds_text = sprintf( __( 'Your account setting is set to sandbox, no real charging takes place. To accept live payments, switch your environment to live and connect your PayPal account. To reset current credentials and use other sandbox account click here.', 'woocommerce-gateway-paypal-express-checkout' ), $reset_link, __( 'Reset current sandbox credentials', 'woocommerce-gateway-paypal-express-checkout' ) ); } $credit_enabled_label = __( 'Enable PayPal Credit', 'woocommerce-gateway-paypal-express-checkout' ); if ( ! wc_gateway_ppec_is_credit_supported() ) { $credit_enabled_label .= '
' . __( 'This option is disabled. Currently PayPal Credit only available for U.S. merchants using USD currency.', 'woocommerce-gateway-paypal-express-checkout' ) . '
'; } $credit_enabled_description = __( 'This enables PayPal Credit, which displays a PayPal Credit button next to the primary PayPal Checkout button. PayPal Checkout lets you give customers access to financing through PayPal Credit® - at no additional cost to you. You get paid up front, even though customers have more time to pay. A pre-integrated payment button shows up next to the PayPal Button, and lets customers pay quickly with PayPal Credit®. (Should be unchecked for stores involved in Real Money Gaming.)', 'woocommerce-gateway-paypal-express-checkout' ); wc_enqueue_js( " jQuery( function( $ ) { var ppec_mark_fields = '#woocommerce_ppec_paypal_title, #woocommerce_ppec_paypal_description'; var ppec_live_fields = '#woocommerce_ppec_paypal_api_username, #woocommerce_ppec_paypal_api_password, #woocommerce_ppec_paypal_api_signature, #woocommerce_ppec_paypal_api_certificate, #woocommerce_ppec_paypal_api_subject'; var ppec_sandbox_fields = '#woocommerce_ppec_paypal_sandbox_api_username, #woocommerce_ppec_paypal_sandbox_api_password, #woocommerce_ppec_paypal_sandbox_api_signature, #woocommerce_ppec_paypal_sandbox_api_certificate, #woocommerce_ppec_paypal_sandbox_api_subject'; var enable_toggle = $( 'a.ppec-toggle-settings' ).length > 0; var enable_sandbox_toggle = $( 'a.ppec-toggle-sandbox-settings' ).length > 0; $( '#woocommerce_ppec_paypal_environment' ).change(function(){ $( ppec_sandbox_fields + ',' + ppec_live_fields ).closest( 'tr' ).hide(); if ( 'live' === $( this ).val() ) { $( '#woocommerce_ppec_paypal_api_credentials, #woocommerce_ppec_paypal_api_credentials + p' ).show(); $( '#woocommerce_ppec_paypal_sandbox_api_credentials, #woocommerce_ppec_paypal_sandbox_api_credentials + p' ).hide(); if ( ! enable_toggle ) { $( ppec_live_fields ).closest( 'tr' ).show(); } } else { $( '#woocommerce_ppec_paypal_api_credentials, #woocommerce_ppec_paypal_api_credentials + p' ).hide(); $( '#woocommerce_ppec_paypal_sandbox_api_credentials, #woocommerce_ppec_paypal_sandbox_api_credentials + p' ).show(); if ( ! enable_sandbox_toggle ) { $( ppec_sandbox_fields ).closest( 'tr' ).show(); } } }).change(); $( '#woocommerce_ppec_paypal_enabled' ).change(function(){ if ( $( this ).is( ':checked' ) ) { $( ppec_mark_fields ).closest( 'tr' ).show(); } else { $( ppec_mark_fields ).closest( 'tr' ).hide(); } }).change(); $( '#woocommerce_ppec_paypal_paymentaction' ).change(function(){ if ( 'sale' === $( this ).val() ) { $( '#woocommerce_ppec_paypal_instant_payments' ).closest( 'tr' ).show(); } else { $( '#woocommerce_ppec_paypal_instant_payments' ).closest( 'tr' ).hide(); } }).change(); if ( enable_toggle ) { $( document ).off( 'click', '.ppec-toggle-settings' ); $( document ).on( 'click', '.ppec-toggle-settings', function( e ) { $( ppec_live_fields ).closest( 'tr' ).toggle( 'fast' ); e.preventDefault(); } ); } if ( enable_sandbox_toggle ) { $( document ).off( 'click', '.ppec-toggle-sandbox-settings' ); $( document ).on( 'click', '.ppec-toggle-sandbox-settings', function( e ) { $( ppec_sandbox_fields ).closest( 'tr' ).toggle( 'fast' ); e.preventDefault(); } ); } $( '.woocommerce_ppec_paypal_button_layout' ).change( function( event ) { if ( ! $( '#woocommerce_ppec_paypal_use_spb' ).is( ':checked' ) ) { return; } // Show settings that pertain to selected layout in same section var isVertical = 'vertical' === $( event.target ).val(); var table = $( event.target ).closest( 'table' ); table.find( '.woocommerce_ppec_paypal_vertical' ).closest( 'tr' ).toggle( isVertical ); table.find( '.woocommerce_ppec_paypal_horizontal' ).closest( 'tr' ).toggle( ! isVertical ); // Disable 'small' button size option in vertical layout only var button_size = table.find( '.woocommerce_ppec_paypal_button_size' ); var button_size_option = button_size.find( 'option[value=\"small\"]' ); if ( button_size_option.prop( 'disabled' ) !== isVertical ) { button_size.removeClass( 'enhanced' ) button_size_option.prop( 'disabled', isVertical ); $( document.body ).trigger( 'wc-enhanced-select-init' ); ! button_size.val() && button_size.val( 'responsive' ).change(); } } ).change(); // Hide default layout and size settings if they'll be overridden anyway. function showHideDefaultButtonSettings() { var display = $( '#woocommerce_ppec_paypal_cart_checkout_enabled' ).is( ':checked' ) || ( $( '#woocommerce_ppec_paypal_checkout_on_single_product_enabled' ).is( ':checked' ) && ! $( '#woocommerce_ppec_paypal_single_product_settings_toggle' ).is( ':checked' ) ) || ( $( '#woocommerce_ppec_paypal_mark_enabled' ).is( ':checked' ) && ! $( '#woocommerce_ppec_paypal_mark_settings_toggle' ).is( ':checked' ) ); $( '#woocommerce_ppec_paypal_button_layout, #woocommerce_ppec_paypal_button_size, #woocommerce_ppec_paypal_hide_funding_methods, #woocommerce_ppec_paypal_credit_enabled' ).closest( 'tr' ).toggle( display ); display && $( '#woocommerce_ppec_paypal_button_layout' ).change(); } // Toggle mini-cart section based on whether checkout on cart page is enabled $( '#woocommerce_ppec_paypal_cart_checkout_enabled' ).change( function( event ) { if ( ! $( '#woocommerce_ppec_paypal_use_spb' ).is( ':checked' ) ) { return; } var checked = $( event.target ).is( ':checked' ); $( '#woocommerce_ppec_paypal_mini_cart_settings_toggle, .woocommerce_ppec_paypal_mini_cart' ) .closest( 'tr' ) .add( '#woocommerce_ppec_paypal_mini_cart_settings' ) // Select title. .next( 'p' ) // Select description if present. .addBack() .toggle( checked ); checked && $( '#woocommerce_ppec_paypal_mini_cart_settings_toggle' ).change(); showHideDefaultButtonSettings(); } ).change(); $( '#woocommerce_ppec_paypal_mini_cart_settings_toggle' ).change( function( event ) { // Only show settings specific to mini-cart if configured to override global settings. var checked = $( event.target ).is( ':checked' ); $( '.woocommerce_ppec_paypal_mini_cart' ).closest( 'tr' ).toggle( checked ); checked && $( '#woocommerce_ppec_paypal_mini_cart_button_layout' ).change(); showHideDefaultButtonSettings(); } ).change(); $( '#woocommerce_ppec_paypal_checkout_on_single_product_enabled, #woocommerce_ppec_paypal_single_product_settings_toggle' ).change( function( event ) { if ( ! $( '#woocommerce_ppec_paypal_use_spb' ).is( ':checked' ) ) { return; } if ( ! $( '#woocommerce_ppec_paypal_checkout_on_single_product_enabled' ).is( ':checked' ) ) { // If product page button is disabled, hide remaining settings in section. $( '#woocommerce_ppec_paypal_single_product_settings_toggle, .woocommerce_ppec_paypal_single_product' ).closest( 'tr' ).hide(); } else if ( ! $( '#woocommerce_ppec_paypal_single_product_settings_toggle' ).is( ':checked' ) ) { // If product page button is enabled but not configured to override global settings, hide remaining settings in section. $( '#woocommerce_ppec_paypal_single_product_settings_toggle' ).closest( 'tr' ).show(); $( '.woocommerce_ppec_paypal_single_product' ).closest( 'tr' ).hide(); } else { // Show all settings in section. $( '#woocommerce_ppec_paypal_single_product_settings_toggle, .woocommerce_ppec_paypal_single_product' ).closest( 'tr' ).show(); $( '#woocommerce_ppec_paypal_single_product_button_layout' ).change(); } showHideDefaultButtonSettings(); } ).change(); $( '#woocommerce_ppec_paypal_mark_enabled, #woocommerce_ppec_paypal_mark_settings_toggle' ).change( function() { if ( ! $( '#woocommerce_ppec_paypal_use_spb' ).is( ':checked' ) ) { return; } if ( ! $( '#woocommerce_ppec_paypal_mark_enabled' ).is( ':checked' ) ) { // If checkout page button is disabled, hide remaining settings in section. $( '#woocommerce_ppec_paypal_mark_settings_toggle, .woocommerce_ppec_paypal_mark' ).closest( 'tr' ).hide(); } else if ( ! $( '#woocommerce_ppec_paypal_mark_settings_toggle' ).is( ':checked' ) ) { // If checkout page button is enabled but not configured to override global settings, hide remaining settings in section. $( '#woocommerce_ppec_paypal_mark_settings_toggle' ).closest( 'tr' ).show(); $( '.woocommerce_ppec_paypal_mark' ).closest( 'tr' ).hide(); } else { // Show all settings in section. $( '#woocommerce_ppec_paypal_mark_settings_toggle, .woocommerce_ppec_paypal_mark' ).closest( 'tr' ).show(); $( '#woocommerce_ppec_paypal_mark_button_layout' ).change(); } showHideDefaultButtonSettings(); } ).change(); // Make sure handlers are only attached once if script is loaded multiple times. $( '#woocommerce_ppec_paypal_use_spb' ).off( 'change' ); $( '#woocommerce_ppec_paypal_use_spb' ).change( function( event ) { var checked = $( event.target ).is( ':checked' ); // Show settings specific to Smart Payment Buttons only if enabled. $( '.woocommerce_ppec_paypal_spb' ).not( 'h3 ').closest( 'tr' ).toggle( checked ); $( '.woocommerce_ppec_paypal_spb' ).filter( 'h3' ).next( 'p' ).addBack().toggle( checked ); if ( checked ) { // Trigger all logic that controls visibility of other settings. $( '.woocommerce_ppec_paypal_visibility_toggle' ).change(); } else { // If non-SPB mode is enabled, show all settings that may have been hidden. $( '#woocommerce_ppec_paypal_button_size, #woocommerce_ppec_paypal_credit_enabled' ).closest( 'tr' ).show(); } // Hide 'Responsive' button size option in SPB mode, and make sure to show 'Small' option. var button_size = $( '#woocommerce_ppec_paypal_button_size' ).removeClass( 'enhanced' ); button_size.find( 'option[value=\"responsive\"]' ).prop( 'disabled', ! checked ); ! checked && button_size.find( 'option[value=\"small\"]' ).prop( 'disabled', false ); $( document.body ).trigger( 'wc-enhanced-select-init' ); } ).change(); // Reset button size values to default when switching modes. $( '#woocommerce_ppec_paypal_use_spb' ).change( function( event ) { if ( $( event.target ).is( ':checked' ) ) { // In SPB mode, set to recommended 'Responsive' value so it is not missed. $( '#woocommerce_ppec_paypal_button_size' ).val( 'responsive' ).change(); } else if ( ! $( '#woocommerce_ppec_paypal_button_size' ).val() ) { // Set back to original default for non-SPB mode. $( '#woocommerce_ppec_paypal_button_size' ).val( 'large' ).change(); } } ); }); " ); /** * Settings for PayPal Gateway. */ $settings = array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'checkbox', 'label' => __( 'Enable PayPal Checkout', 'woocommerce-gateway-paypal-express-checkout' ), 'description' => __( 'This enables PayPal Checkout which allows customers to checkout directly via PayPal from your cart page.', 'woocommerce-gateway-paypal-express-checkout' ), 'desc_tip' => true, 'default' => 'yes', ), 'title' => array( 'title' => __( 'Title', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'text', 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => __( 'PayPal', 'woocommerce-gateway-paypal-express-checkout' ), 'desc_tip' => true, ), 'description' => array( 'title' => __( 'Description', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'text', 'desc_tip' => true, 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => __( 'Pay via PayPal; you can pay with your credit card if you don\'t have a PayPal account.', 'woocommerce-gateway-paypal-express-checkout' ), ), 'account_settings' => array( 'title' => __( 'Account Settings', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'title', 'description' => '', ), 'environment' => array( 'title' => __( 'Environment', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'select', 'class' => 'wc-enhanced-select', 'description' => __( 'This setting specifies whether you will process live transactions, or whether you will process simulated transactions using the PayPal Sandbox.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => 'live', 'desc_tip' => true, 'options' => array( 'live' => __( 'Live', 'woocommerce-gateway-paypal-express-checkout' ), 'sandbox' => __( 'Sandbox', 'woocommerce-gateway-paypal-express-checkout' ), ), ), 'api_credentials' => array( 'title' => __( 'API Credentials', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'title', 'description' => $api_creds_text, ), 'api_username' => array( 'title' => __( 'Live API Username', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'text', 'description' => __( 'Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => '', 'desc_tip' => true, ), 'api_password' => array( 'title' => __( 'Live API Password', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'password', 'description' => __( 'Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => '', 'desc_tip' => true, ), 'api_signature' => array( 'title' => __( 'Live API Signature', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'text', 'description' => __( 'Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => '', 'desc_tip' => true, 'placeholder' => __( 'Optional if you provide a certificate below', 'woocommerce-gateway-paypal-express-checkout' ), ), 'api_certificate' => array( 'title' => __( 'Live API Certificate', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'file', 'description' => $this->get_certificate_info( $this->get_option( 'api_certificate' ) ), 'default' => '', ), 'api_subject' => array( 'title' => __( 'Live API Subject', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'text', 'description' => __( 'If you\'re processing transactions on behalf of someone else\'s PayPal account, enter their email address or Secure Merchant Account ID (also known as a Payer ID) here. Generally, you must have API permissions in place with the other account in order to process anything other than "sale" transactions for them.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => '', 'desc_tip' => true, 'placeholder' => __( 'Optional', 'woocommerce-gateway-paypal-express-checkout' ), ), 'sandbox_api_credentials' => array( 'title' => __( 'Sandbox API Credentials', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'title', 'description' => $sandbox_api_creds_text, ), 'sandbox_api_username' => array( 'title' => __( 'Sandbox API Username', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'text', 'description' => __( 'Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => '', 'desc_tip' => true, ), 'sandbox_api_password' => array( 'title' => __( 'Sandbox API Password', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'password', 'description' => __( 'Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => '', 'desc_tip' => true, ), 'sandbox_api_signature' => array( 'title' => __( 'Sandbox API Signature', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'text', 'description' => __( 'Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => '', 'desc_tip' => true, ), 'sandbox_api_certificate' => array( 'title' => __( 'Sandbox API Certificate', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'file', 'description' => __( 'Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => '', 'desc_tip' => true, ), 'sandbox_api_subject' => array( 'title' => __( 'Sandbox API Subject', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'text', 'description' => __( 'If you\'re processing transactions on behalf of someone else\'s PayPal account, enter their email address or Secure Merchant Account ID (also known as a Payer ID) here. Generally, you must have API permissions in place with the other account in order to process anything other than "sale" transactions for them.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => '', 'desc_tip' => true, 'placeholder' => __( 'Optional', 'woocommerce-gateway-paypal-express-checkout' ), ), 'paypal_hosted_settings' => array( 'title' => __( 'PayPal-hosted Checkout Settings', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'title', 'description' => __( 'Customize the appearance of PayPal Checkout on the PayPal side.', 'woocommerce-gateway-paypal-express-checkout' ), ), 'brand_name' => array( 'title' => __( 'Brand Name', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'text', 'description' => __( 'A label that overrides the business name in the PayPal account on the PayPal hosted checkout pages.', 'woocommerce-gateway-paypal-express-checkout' ), 'default' => get_bloginfo( 'name', 'display' ), 'desc_tip' => true, ), 'logo_image_url' => array( 'title' => __( 'Logo Image (190×60)', 'woocommerce-gateway-paypal-express-checkout' ), 'type' => 'image', 'description' => __( 'If you want PayPal to co-brand the checkout page with your logo, enter the URL of your logo image here.