2017-03-08 16 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證書,你的頁面不會返回一個標記也不會再執行任何手段。