2017-03-08 18 views
0

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

这里是我的网页: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> 
+2

请将代码放入文章中,而不是图片。 – imtheman

+0

更新,没有更多的图像。 – jam

回答

0

我猜你的前端代码不会得到成功功能。

Web控制台的回报:

ReferenceError: $ is not defined 

它看起来像你使用jQuery命令$.ajax(),但我不能看到你已经加载了jQuery库。尝试并加载它,使用它上面的脚本,并看看会发生什么

+0

工作谢谢! – jam

0

请务必仔细检查条纹结帐要求。看来,根据您发布的链接,您使用的HTTP协议上。条纹Checkout要求您使用HTTPS 协议。如果你不使用Google Checkout使用页面上的SSL证书,你的页面不会返回一个标记也不会再执行任何手段。