简体   繁体   English

条带结帐后页面不重定向

[英]Page not redirecting after stripe checkout

I'm trying to add a stripe checkout button to my Leadpages landing page and after somebody completes a successful payment they're supposed to be redirected...but that redirect is not happening and I have no idea why. 我正在尝试向Leadpages登录页面添加条带结帐按钮,在某人完成付款后,他们应该被重定向...但是重定向没有发生,我不明白为什么。

Here's my page: http://snapstories.leadpages.co/test/ ... it's using test keys right now so you can test the checkout with Stripe's demo Visa number: 4242424242424242 and any expiry / security code...you'll see that you don't get redirected anywhere. 这是我的页面: http ://snapstories.leadpages.co/test/ ...它现在正在使用测试键,因此您可以使用Stripe的演示版Visa号码4242424242424242和任何到期/安全代码来测试结账...你会看到你没有被重定向到任何地方。

The demo-stripe.php script is supposed to send a 'success' response to my front-end code which triggers the redirect but that 'success' response is not being sent. demo-stripe.php脚本应该向我的前端代码发送“成功”响应,该响应会触发重定向,但不会发送“成功”响应。

Here's the demo-stripe.php code: 这是demo-stripe.php代码:

    <?php
require_once('./stripe/init.php');

$stripe = array(
  "secret_key"      => "sk_test_******",
  "publishable_key" => "pk_test_******"
);

\Stripe\Stripe::setApiKey($stripe['secret_key']);
// Get the credit card details submitted by the form
$token  = $_GET['stripeToken'];
$email  = $_GET['stripeEmail'];
$callback = $_GET['callback'];

try {
    $customer = \Stripe\Customer::create(array(
      "source" => $token,
   "email" => $email
      ));
    $charge = \Stripe\Charge::create(array(
  'customer' => $customer->id,
     'amount'   => 100,
      'currency' => 'usd'
    ));


    header('Content-type: application/json');
    $response_array['status'] = 'success';
    echo $callback.'('.json_encode($response_array).')';
    return 1;

} 

catch ( \Stripe\Error\Card $e) {
    // Since it's a decline, \Stripe\Error\Card will be caught
}
?>

Here's the front-end code: 这是前端代码:

<script src="https://checkout.stripe.com/checkout.js"></script>

<script>
var handler = StripeCheckout.configure({
  key: 'pk_test_*****',
  image: 'imagefile.png',
  locale: 'auto',
  token: function(token) {
    $.ajax({
      type: "POST",
      dataType: 'jsonp',
      url: "https://snapstories.co/demo-stripe.php",
      data: { stripeToken: token.id, stripeEmail: token.email},
      success: function(data) {
          window.location.href = "http//www.google.com";
    },

   });
  }
});

document.getElementsByClassName('w-f73e4cf1-859d-e3e4-97af-8efccae7644a')[0].addEventListener('click', function(e) {
  // Open Checkout with further options:
  handler.open({
    name: 'Testing',
    description: 'testing',
    amount: 100
  });
  e.preventDefault();
});


// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
  handler.close();
});
</script>

I'm guessing your front-end code doesn't get to the success function. 我猜你的前端代码没有达到成功功能。

Web console returns: Web控制台返回:

ReferenceError: $ is not defined

It looks like you're using the jQuery command $.ajax() , but I can't see where you've loaded the jQuery library. 看起来你正在使用jQuery命令$.ajax() ,但是我看不到你在哪里加载了jQuery库。 Try and load it above the script that uses it and see what happens 尝试将其加载到使用它的脚本上方,看看会发生什么

Be sure to double check the Stripe Checkout requirements. 请务必仔细检查Stripe Checkout要求。 It seems, based on the link you posted, that you're using the HTTP protocol. 根据您发布的链接,您似乎正在使用HTTP协议。 Stripe Checkout requires you use the HTTPS protocol. Stripe Checkout要求您使用HTTPS协议。 That means if you're not using an ssl certificate on your page using Checkout, your page isn't going to return a token nor will it execute any further. 这意味着如果您没有使用Checkout在您的页面上使用ssl证书 ,那么您的页面将不会返回令牌,也不会再执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM