urlencode( $api->client_id ), 'currency' => urlencode( strtoupper( edd_get_currency() ) ), 'intent' => 'capture', 'disable-funding' => 'card,credit,bancontact,blik,eps,giropay,ideal,mercadopago,mybank,p24,sepa,sofort,venmo' ) ); wp_register_script( 'sandhills-paypal-js-sdk', esc_url_raw( add_query_arg( array_filter( $sdk_query_args ), 'https://www.paypal.com/sdk/js' ) ) ); wp_register_script( 'edd-paypal', EDD_PLUGIN_URL . 'assets/js/paypal-checkout.js', array( 'sandhills-paypal-js-sdk', 'jquery', 'edd-ajax' ), EDD_VERSION, true ); if ( edd_is_checkout() || $force_load ) { maybe_enqueue_polyfills(); wp_enqueue_script( 'sandhills-paypal-js-sdk' ); wp_enqueue_script( 'edd-paypal' ); $paypal_script_vars = array( /** * Filters the order approval handler. * * @since 2.11 */ 'approvalAction' => apply_filters( 'edd_paypal_on_approve_action', 'edd_capture_paypal_order' ), 'defaultError' => edd_build_errors_html( array( 'paypal-error' => esc_html__( 'An unexpected error occurred. Please try again.', 'easy-digital-downloads' ) ) ), 'intent' => ! empty( $sdk_query_args['intent'] ) ? $sdk_query_args['intent'] : 'capture', 'style' => get_button_styles(), ); wp_localize_script( 'edd-paypal', 'eddPayPalVars', $paypal_script_vars ); } } add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_js', 100 ); /** * Removes the "?ver=" query arg from the PayPal JS SDK URL, because PayPal will throw an error * if it's included. * * @param string $url * * @since 2.11 * @return string */ function remove_ver_query_arg( $url ) { $sdk_url = 'https://www.paypal.com/sdk/js'; if ( false !== strpos( $url, $sdk_url ) ) { $new_url = preg_split( "/(&ver|\?ver)/", $url ); return $new_url[0]; } return $url; } add_filter( 'script_loader_src', __NAMESPACE__ . '\remove_ver_query_arg', 100 ); /** * Adds data attributes to the PayPal JS SDK