trim( $publishable_key ), 'isTestMode' => edd_is_test_mode() ? 'true' : 'false', 'elementsMode' => $elements_mode, 'is_ajaxed' => edd_is_ajax_enabled() ? 'true' : 'false', 'currency' => edd_get_currency(), // @todo Replace with country code derived from Stripe Account information if available. // @link https://github.com/easydigitaldownloads/edd-stripe/issues/654 'country' => edd_get_option( 'base_country', 'US' ), 'locale' => edds_get_stripe_checkout_locale(), 'is_zero_decimal' => edds_is_zero_decimal_currency() ? 'true' : 'false', 'checkout' => edd_get_option( 'stripe_checkout' ) ? 'true' : 'false', 'store_name' => ! empty( edd_get_option( 'entity_name' ) ) ? edd_get_option( 'entity_name' ) : get_bloginfo( 'name' ), 'submit_text' => edd_get_option( 'stripe_checkout_button_text', __( 'Next', 'easy-digital-downloads' ) ), 'image' => edd_get_option( 'stripe_checkout_image' ), 'zipcode' => edd_get_option( 'stripe_checkout_zip_code', false ) ? 'true' : 'false', 'billing_address' => edd_get_option( 'stripe_checkout_billing', false ) ? 'true' : 'false', 'remember_me' => edd_get_option( 'stripe_checkout_remember', false ) ? 'true' : 'false', 'no_key_error' => __( 'Stripe publishable key missing. Please enter your publishable key in Settings.', 'easy-digital-downloads' ), 'checkout_required_fields_error' => __( 'Please fill out all required fields to continue your purchase.', 'easy-digital-downloads' ), 'checkout_agree_to_terms' => __( 'Please agree to the terms to complete your purchase.', 'easy-digital-downloads' ), 'checkout_agree_to_privacy' => __( 'Please agree to the privacy policy to complete your purchase.', 'easy-digital-downloads' ), 'generic_error' => __( 'Unable to complete your request. Please try again.', 'easy-digital-downloads' ), 'prepaid' => edd_get_option( 'stripe_allow_prepaid', false ) ? 'true' : 'false', 'successPageUri' => edd_get_success_page_uri(), 'failurePageUri' => edd_get_failed_transaction_uri(), 'debuggingEnabled' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'true' : 'false', 'formLoadingText' => __( 'Please wait...', 'easy-digital-downloads' ), 'cartHasSubscription' => function_exists( 'edd_recurring' ) && edd_recurring()->cart_contains_recurring() ? 'true' : 'false', ); $stripe_vars = apply_filters( 'edd_stripe_js_vars', $stripe_localized_vars ); wp_localize_script( 'edd-stripe-js', 'edd_stripe_vars', $stripe_vars ); } } add_action( 'wp_enqueue_scripts', 'edd_stripe_js', 100 ); /** * Conditionally load the Stripe CSS * * @param bool $force_load_scripts If we should forece loading the scripts outside of checkout. */ function edd_stripe_css( $force_load_scripts = false ) { if ( false === edds_is_gateway_active() ) { return; } if ( edd_is_checkout() || $force_load_scripts ) { $deps = array( 'edd-styles' ); if ( ! wp_script_is( 'edd-styles', 'enqueued' ) ) { $deps = array(); } // We're going to assume Payment Elements needs to load... $style_src = EDDSTRIPE_PLUGIN_URL . 'assets/css/build/paymentelements.min.css'; // But if the user has Card Elements, we need to load that instead. $elements_mode = edds_get_elements_mode(); if ( 'card-elements' === $elements_mode ) { $style_src = EDDSTRIPE_PLUGIN_URL . 'assets/css/build/cardelements.min.css'; } wp_register_style( 'edd-stripe', $style_src, $deps, EDD_STRIPE_VERSION . '-' . $elements_mode ); wp_enqueue_style( 'edd-stripe' ); } } add_action( 'wp_enqueue_scripts', 'edd_stripe_css', 100 ); /** * Loads the javascript for the Stripe Connect functionality in the settings page. * * @param string $hook The current admin page. */ function edd_stripe_connect_admin_script( $hook ) { if ( 'download_page_edd-settings' !== $hook ) { return; } edd_stripe_connect_admin_style(); wp_enqueue_script( 'edd-stripe-admin-scripts', EDDSTRIPE_PLUGIN_URL . 'assets/js/build/admin.min.js', array( 'jquery' ), EDD_STRIPE_VERSION ); $test_key = edd_get_option( 'test_publishable_key' ); $live_key = edd_get_option( 'live_publishable_key' ); wp_localize_script( 'edd-stripe-admin-scripts', 'edd_stripe_admin', array( 'stripe_enabled' => array_key_exists( 'stripe', edd_get_enabled_payment_gateways() ), 'test_mode' => (int) edd_is_test_mode(), 'test_key_exists' => ! empty( $test_key ) ? 'true' : 'false', 'live_key_exists' => ! empty( $live_key ) ? 'true' : 'false', 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), ) ); } add_action( 'admin_enqueue_scripts', 'edd_stripe_connect_admin_script' ); /** * Enqueues the Stripe admin style. * * @since 2.9.3 * * @return void */ function edd_stripe_connect_admin_style() { wp_enqueue_style( 'edd-stripe-admin-styles', EDDSTRIPE_PLUGIN_URL . 'assets/css/build/admin.min.css', array(), EDD_STRIPE_VERSION ); }