I'm trying to implement the checkout fuctionality (+ stripe with WooCommerce Stripe Payment Gateway plugin) in a modal window, and I'm using the ajax for this. Here is my backend code to get/refresh the checkout:
add_action('wp_ajax_refresh_checkout', 'getCheckoutPageContentCallBack');
add_action('wp_ajax_nopriv_refresh_checkout', 'getCheckoutPageContentCallBack');
function getCheckoutPageContentCallBack() {
define('WOOCOMMERCE_CHECKOUT', true);
echo do_shortcode('[woocommerce_checkout]');
if (class_exists('WooCommerce')) {
$wcurl = WooCommerce::plugin_url();
$credit_card_form_script = file_get_contents($wcurl . '/assets/js/frontend/credit-card-form.min.js');
if ($credit_card_form_script) {
echo "<script>";
echo $credit_card_form_script;
echo "</script>";
}
$checkout_script = file_get_contents($wcurl . '/assets/js/frontend/checkout.min.js');
if ($checkout_script) {
echo "<script>";
echo $checkout_script;
echo "</script>";
}
}
wp_die();
}
I included all the scripts that checkout page has, but still getting the error:
Please enter your card details to make a payment. Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.
jQuery is included and there are no js errors on the page. The original checkout page works just fine. I thought the problem was that I removed the payment part from the original part by this code:
remove_action('woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20);
add_action('woocommerce_checkout_order_payment', 'woocommerce_checkout_payment', 20);
But commenting these lines gave me nothing. I edited the page, so this is not even a shop page right now (just a page with a loop).
I noticed that when making payments via the checkout page, the first request goes to the https://api.stripe.com/v1/tokens with card credentials, the next one goes to /checkout/?wc-ajax=checkout
with stripe_token
and so When I try to checkout from my modal, there is no request to the Stripe API, just to the checkout. Maybe there is some script I need to include every time I refresh the checkout? I can't find any info about it.