2016-04-13 6 views
2

私はカード支払いのためにストライプチャージカードAPIを使用しています。トークンが正常に作成され、この情報もストライプサーバーに送られます。しかし、料金支払いのために行くと、致命的なエラーが発生します。ストライプチャージカードはphp rest 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 
} 

それは致命的なエラーを与えます。

Fatal error: Uncaught exception 'Stripe\Error\ApiConnection' with message 'Could not connect to Stripe (https://api.stripe.com/v1/charges). Please check your internet connection and try again. If this problem persists, you should check Stripe's service status at https://twitter.com/stripestatus , or let us know at [email protected] (Network error [errno 28]: Connection timed out after 30055 milliseconds)' in /opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/HttpClient/CurlClient.php:216 Stack trace: #0 /opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/HttpClient/CurlClient.php(178): Stripe\HttpClient\CurlClient->handleCurlError(' https://api.str ...', 28, 'Connection time...') #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', Array, Ar in /opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/HttpClient/CurlClient.php on line 216

私は、その理由を知らない。

+0

httpsを使用していますか? – Kisaragi

+0

いいえ私はhttpsを使用していません –

+0

これはテスト環境でない場合は、SSL証明書を使用する必要があります。 – Kisaragi

答えて

3

メッセージにネットワークエラー[errno 28]が表示されます。これはcurl errorで、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に許可します。