簡體   English   中英

條帶結帳后頁面不重定向

[英]Page not redirecting after stripe checkout

我正在嘗試向Leadpages登錄頁面添加條帶結帳按鈕,在某人完成付款后,他們應該被重定向...但是重定向沒有發生,我不明白為什么。

這是我的頁面: http ://snapstories.leadpages.co/test/ ...它現在正在使用測試鍵,因此您可以使用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庫。 嘗試將其加載到使用它的腳本上方,看看會發生什么

請務必仔細檢查Stripe Checkout要求。 根據您發布的鏈接,您似乎正在使用HTTP協議。 Stripe Checkout要求您使用HTTPS協議。 這意味着如果您沒有使用Checkout在您的頁面上使用ssl證書 ,那么您的頁面將不會返回令牌,也不會再執行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM