我正在尝试实现Stripe连接,我得到了代码,直到从Stripe获得以下响应
{
"token_type": "bearer",
"stripe_publishable_key": PUBLISHABLE_KEY,
"scope": "read_write",
"livemode": false,
"stripe_user_id": USER_ID,
"refresh_token": REFRESH_TOKEN,
"access_token": ACCESS_TOKEN
}
这就是我的代码看起来的样子,它给了我上面的回应。
define('TOKEN_URI', 'https://connect.stripe.com/oauth/token');
define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize');
define('CLIENT_SECRET', 'xxx');
define('CLIENT_ID', 'yyy');
$token_request_body = array(
'grant_type' => 'authorization_code',
'client_id' => CLIENT_ID,
'code' => $code,
'client_secret' => CLIENT_SECRET
);
$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);
我假设因为我没有要求用户提供信用卡号码,所以金额将从与他/她的条带帐户链接的用户银行帐户中扣除。所以我然后尝试向用户收费
\Stripe\Stripe::setApiKey(CLIENT_SECRET);
\Stripe\Charge::create(array(
'amount' => 1000*100,
'currency' => 'gbp',
'source' => $resp['access_token'],
'destination' => $resp['stripe_user_id']
));
这给了我一个错误
No such token: sk_test_HSBM8.....
如果有人能告诉我我做错了,我会非常感激,因为这是我第一次使用Stripe Connect