我試圖向我的首頁登錄頁面添加一個條紋結帳按鈕,並且在有人完成了成功的付款後,他們應該被重定向...但是,重定向沒有發生,我有不知道爲什麼。頁面在條紋結賬後不重定向
這裏是我的網頁:http://snapstories.leadpages.co/test/ ...它使用測試鍵現在這樣你就可以測試與條紋的演示簽證號碼結帳:4242424242424242和任何到期/安全代碼......你會發現你沒有得到重定向到任何地方。
的演示stripe.php腳本應該發到我的前端代碼中的「成功」響應觸發重定向,但沒有被髮送的「成功」的迴應。
這裏的演示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>
請將代碼放入文章中,而不是圖片。 – imtheman
更新,沒有更多的圖像。 – jam