【问题标题】:Page not redirecting after stripe checkout条带结帐后页面未重定向
【发布时间】:2017-07-29 18:07:35
【问题描述】:

我正在尝试向我的 Leadpages 登录页面添加条带结帐按钮,并且在有人成功完成付款后,他们应该被重定向...但是该重定向没有发生,我不知道为什么。

这是我的页面:http://snapstories.leadpages.co/test/...它现在正在使用测试密钥,因此您可以使用 Stripe 的演示签证号码: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>

【问题讨论】:

  • 请将代码作为文本而不是图像放入您的帖子中。
  • 已更新,没有更多图片了。
  • 嗨@jam,我只是想用leadpages和stripe进行类似的配置(进行结帐并将重定向url设置到我的主要方面)我找不到来自stripe/的任何文档围绕这个的潜在客户。你能指出我正确的方向吗?
  • 我在 Stripe 上找到的页面似乎已经不存在了(我敢肯定你已经遇到过这个)...想知道配置是否不再有效? stripe.com/works-with/leadpages

标签: javascript php redirect stripe-payments checkout


【解决方案1】:

请务必仔细检查 Stripe Checkout 要求。根据您发布的链接,您似乎正在使用 HTTP 协议。 Stripe Checkout 要求您使用 HTTPS 协议。这意味着如果您没有在使用 Checkout 的页面上使用 ssl 证书,您的页面将不会返回令牌,也不会进一步执行。

【讨论】:

    【解决方案2】:

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

    Web 控制台返回:

    ReferenceError: $ is not defined
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      • 1970-01-01
      相关资源
      最近更新 更多