【问题标题】:Stripe charge card get fatal error with php rest apiStripe 收费卡使用 php rest api 出现致命错误
【发布时间】:2016-08-04 18:14:00
【问题描述】:

我正在使用条带收费卡 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”与消息“无法连接到 Stripe” (https://api.stripe.com/v1/charges)。请检查您的互联网 连接并重试。如果此问题仍然存在,您应该检查 Stripe 的服务状态在https://twitter.com/stripestatus,或者让我们 通过 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...', 数组,数组,假)#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 行

我不知道背后的原因。

【问题讨论】:

  • 你在使用 https 吗?
  • 不,我没有使用 https
  • 如果这不是测试环境,您必须使用 ssl 证书。
  • 目前处于测试环境中
  • @SatanandTiwari - 我相信您使用的是 HTTPS,因为错误表明 API 端点是 api.stripe.com/v1/charges

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-06-18
    • 2019-04-13
    • 2015-05-27
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    • 2015-01-18
    • 1970-01-01
    相关资源
    最近更新 更多