【发布时间】: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