[英]Stripe charge card get fatal error with php rest api
我正在使用條紋收費卡api進行卡付款。 令牌已成功創建,並且此信息也將轉到條帶服務器。 但是,當進行收費時,會出現致命錯誤。
我正在使用amazone ubuntu實例發布我的網站。
我的PHP代碼是:-
$token=$this->input->post('stripeToken');
var_dump($token);
\Stripe\Stripe::setApiKey("xxx");
// Get the credit card details submitted by the form
//$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = \Stripe\Charge::create(array(
"amount" => 100, // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "Example charge"
));
} catch(\Stripe\Error\Card $e) {
// The card has been declined
}
它會導致致命錯誤。
致命錯誤:消息為“無法連接到Stripe( https://api.stripe.com/v1/charges )”的未捕獲異常'Stripe \\ Error \\ ApiConnection'。 請檢查您的互聯網連接,然后重試。 如果此問題仍然存在,則應通過https://twitter.com/stripestatus檢查Stripe的服務狀態,或通過support@stripe.com告知我們。 (網絡錯誤[errno 28]:30055毫秒后連接超時)在/opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/HttpClient/CurlClient.php:216堆棧跟蹤:#0 / opt / lampp /htdocs/devbeacon/application/libraries/stripe/lib/HttpClient/CurlClient.php(178):Stripe \\ HttpClient \\ CurlClient-> handleCurlError(' https://api.str ...',28,'連接時間。 ..')#1 /opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/ApiRequestor.php(184):Stripe \\ HttpClient \\ CurlClient-> request('post',' https:// api。 str ...',Array,Array,false)#2 /opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/ApiRequestor.php(59):Stripe \\ ApiRequestor-> _ requestRaw('post',' / v1 / charges',數組,/ opt / lampp / htdocs / devbeacon / application / libraries / stripe / lib / HttpClient / CurlClient.php中的Ar
我不知道其背后的原因。
該消息顯示網絡錯誤[errno 28],它是卷曲錯誤 ,定義為CURLE_OPERATION_TIMEDOUT錯誤。 這是一個連接錯誤。
連接錯誤通常是由於安全組設置導致的,並且不允許出站https,在這種情況下,這是API終結點( https://api.stripe.com/v1/charges )。
您可以嘗試curl https://api.stripe.com/v1/charges
並確認可以連接嗎?
您應該獲得以下信息:
{
"error": {
"type": "invalid_request_error",
"message": "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/d
ocs/api#authentication for details, or we can help at https://support.stripe.com/."
}
}
如果您在服務器上的命令行中未收到該響應,則您的代碼也將無法連接。 查看您的傳出安全組設置,並允許出站HTTPS到端點的IP或0.0.0.0/0。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.