2014-12-05 152 views
2

我以Stripe Payment開始,需要將用戶連接到我的Stripe應用程序。我按照Stripe的guildance用PHP代碼來獲取accesss_token:PHP - Stripe Connect返回null

// See full code example here: https://gist.github.com/3507366 

if (isset($_GET['code'])) { // Redirect w/ code 
    $code = $_GET['code']; 

    $token_request_body = array(
    'grant_type' => 'authorization_code', 
    'client_id' => 'ca_*************************', 
    'code' => $code, 
    'client_secret' => 'sk_test_************************' 
); 

    $req = curl_init(TOKEN_URI); 
    curl_setopt($req, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($req, CURLOPT_POST, true); 
    curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body)); 

    // TODO: Additional error handling 
    $respCode = curl_getinfo($req, CURLINFO_HTTP_CODE); 
    $resp = json_decode(curl_exec($req), true); 
    curl_close($req); 

    echo $resp['access_token']; 
} else if (isset($_GET['error'])) { // Error 
    echo $_GET['error_description']; 
} else { // Show OAuth link 
    $authorize_request_body = array(
    'response_type' => 'code', 
    'scope' => 'read_write', 
    'client_id' => 'ca_************************' 
); 

    $url = AUTHORIZE_URI . '?' . http_build_query($authorize_request_body); 
    echo "<a href='$url'>Connect with Stripe</a>"; 
} 

但是,從條紋的響應總是空。有沒有人曾經遇到過類似的問題。這次任何幫助對我來說都非常有價值。

非常感謝。

回答

2

經過一段時間的調試後,我發現問題出在我的PHP服務器的cURL庫上。看起來cURL不適用於HTTPS。並在此基礎上螺紋:PHP cURL Not Working with HTTPS 我找到解決辦法,使其繞過驗證功能:

... 
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body)); 
curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false); // Bypass the verification 
$resp = json_decode(curl_exec($req), true); // Now has response well. 
... 

P/S:這不是一個很好的解決方案,更好地做更多的研究(here

我希望這可以幫助像我這樣的初學者:)