使用php rest api条纹收费卡出现致命错误

时间:2016-04-13 14:44:35

标签: php api rest amazon-web-services stripe-payments

我使用条形充值卡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 \ Error \ ApiConnection',消息'无法连接到条带   (https://api.stripe.com/v1/charges)。请检查您的互联网   连接,然后再试一次。如果此问题仍然存在,您应该检查   条纹在https://twitter.com/stripestatus的服务状态,或者让我们   知道在support@stripe.com。 (网络错误[错误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):   条纹\ 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',Array,Ar in   /opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/HttpClient/CurlClient.php   在第216行

我不知道背后的原因。

1 个答案:

答案 0 :(得分:3)

该消息显示网络错误[错误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。