/** * Outputs javascript for the Stripe Checkout modal * * @since 2.0 * @return void */ function edd_stripe_purchase_link_output($download_id, $args) { if (!isset($args['stripe-checkout'])) { return; } edd_stripe_js(true); if (edd_is_test_mode()) { $publishable_key = trim(edd_get_option('test_publishable_key')); } else { $publishable_key = trim(edd_get_option('live_publishable_key')); } $download = get_post($download_id); $email = ''; if (is_user_logged_in()) { global $current_user; get_currentuserinfo(); $email = $current_user->user_email; } ?> <script src="https://checkout.stripe.com/checkout.js"></script> <script> jQuery(document).ready(function($) { var edd_global_vars; var edd_scripts; var form = $('#edd_purchase_<?php echo $download_id; ?> '); var handler = StripeCheckout.configure({ key: '<?php echo $publishable_key; ?> ', //image: '/square-image.png', token: function(token) { // insert the token into the form so it gets submitted to the server form.append("<input type='hidden' name='edd_stripe_token' value='" + token.id + "' />"); form.append("<input type='hidden' name='edd_email' value='" + token.email + "' />"); // submit form.get(0).submit(); } }); form.submit(function(e) { if( form.find( '.edd_price_options' ).length ) { var price_id; var prices = []; <?php foreach (edd_get_variable_prices($download_id) as $price_id => $price) { ?> prices[<?php echo $price_id; ?> ] = <?php echo $price['amount'] * 100; ?> ; <?php } ?> price_id = $('.edd_price_options input:checked').val(); amount = prices[ price_id ]; } else { amount = <?php echo edd_get_download_price($download_id) * 100; ?> } // Open Checkout with further options handler.open({ name: '<?php echo get_bloginfo("name"); ?> ', description: '<?php echo $download->post_title; ?> ', amount: amount, zipCode: true, email: '<?php echo $email; ?> ', currency: '<?php echo edd_get_currency(); ?> ' }); e.preventDefault(); }); }); </script> <?php }
/** * Outputs the HTML for the credit card fields */ public function html_cc_form() { if (!wp_script_is('stripe-js')) { edd_stripe_js(true); } get_template_part('html_includes/shop/input-creditcard'); }