[英]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.