javascript - strip 结帐后页面未重定向

标签 javascript php redirect stripe-payments checkout

我正在尝试向我的 Leadpages 登陆页面添加一个 Stripe 结账按钮,在有人成功付款后,他们应该被重定向......但该重定向没有发生,我不知道为什么。

这是我的页面:http://snapstories.leadpages.co/test/ ...它现在正在使用测试 key ,因此您可以使用 Stripe 的演示 Visa 号码:4242424242424242 和任何到期/安全代码来测试结账...您会发现您不会被重定向到任何地方。

demo-stripe.php 脚本应该向我的前端代码发送“成功”响应,从而触发重定向,但“成功”响应并未发送。

这是 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
}
?>

前端代码如下:

<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>

最佳答案

我猜你的前端代码没有到达成功函数。

Web 控制台返回:

ReferenceError: $ is not defined

看起来您正在使用 jQuery 命令$.ajax(),但我看不到您加载 jQuery 库的位置。尝试将其加载到使用它的脚本上方,看看会发生什么

关于javascript - strip 结帐后页面未重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42683774/

相关文章:

Javascript fadeIn() 过渡

javascript - 选择 Fabric.js Canvas 上的所有文本对象

php - 检查字符串是否在 PHP 中序列化

redirect - nginx HTTPS 重定向

Angular Express 重定向

javascript - 寻找 ReactJS 运行时插件概念

javascript - 访问下一个 sibling

php 获取所有磁盘 linux ubuntu 服务器 12.04

php - AFNetworking 代码块未被执行

redirect - 在 Docker 中运行 sonarqube 不断将我重定向回登录页面