【发布时间】:2018-03-03 10:26:15
【问题描述】:
我正在尝试使用 Stripe 在一个小网站上处理一些付款。
在本地,一切正常:我的所有测试都很好。
问题出在实时网站中:我可以获得一个令牌(来自 javascript),但 php 端的 \Stripe\Charge::create 有问题,我不知道为什么。
这里有一些信息:
# Making Stripe works
require_once(dirname(__FILE__).'/stripe/init.php');
# Set API Key (Both Live and Test keys don't work)
\Stripe\Stripe::setApiKey("sk_test_****");
# Trying to charge
# $token is defined from the $_POST and works great ($amount and $metas are fine too)
try {
$charge = \Stripe\Charge::create(
array(
'amount' => $amount,
'currency' => 'eur',
'source' => $token,
'metadata' => $metas
)
);
// Blabla
} catch(\Stripe\Error\Card $e) {
// Catching card error
} catch (\Stripe\Error\RateLimit $e) {
// Catching RateLimit API error
} catch (\Stripe\Error\InvalidRequest $e) {
// Catching invalid request (missing param or else)
} catch (\Stripe\Error\Authentication $e) {
// Catching fail authentification from API KEY for example
} catch (\Stripe\Error\ApiConnection $e) {
// Catching fail APIConnection
// The error seems related to this because the catch is done here !
} catch (\Stripe\Error\Base $e) {
// Catching base error
} catch (Exception $e) {
// Catching other errors
}
在本地它工作得很好,但在实时服务器上它在\Stripe\Error\ApiConnection 上捕获一个错误(一段时间后),没有真实信息。
#$e contains :
"httpStatus":null,
"httpBody":null,
"jsonBody":null,
"httpHeaders":null,
"requestId":null,
"stripeCode":null
这不是一个好兆头。
除了 gettin' token 部分(效果很好)之外,我的 Stripe 仪表板日志中没有关于此 Charge Trial 的任何内容。看起来 Stripe 从未收到过请求。
我尝试从我的服务器 ping api.stripe.com,效果很好。
本地和实时站点上的代码是相同的,条带键可以很好地复制/粘贴(它适用于本地,所以...)。
我的 Stripe 帐户已经过验证,所以我可以使用 Live Keys(但 Live Keys 和 Test Keys 都不能像我说的那样工作)。
API 是最新的。
我不知道还能去哪里搜索:我联系了 Stripe 的支持人员,但仍在等待答复。
感谢您的关注...
【问题讨论】:
-
在每个 catch 语句中输入
print_r( $e );,然后尝试处理付款。您将看到相关错误(如果有)。 -
如果它有时有效(如您的文本所示),您可能会遇到速率限制异常,或者与您的托管环境相关的某种出站 https 连接失败。只是摇摆不定。
-
@RahulDev print_r 发生在我提到的 catch \Stripe\Error\ApiConnection 中,但只包含
null值...... @YvesLeBorg 它只适用于本地(它总是适用于本地) 但从未在实时网站中...关于 https 连接失败,我应该检查什么?谢谢大家 -
@Vae 您的主机可能正在阻止端口或目标 IP 地址。如果您在 AWS 或其他有能力的云提供商上,您可能会因为没有为您的虚拟服务启用适当的策略而阻止这些。另外...
after a while似乎暗示了 DNS 解析错误(和回退,通常通常需要 5 秒)。验证目标主机名是否可在您的托管服务器中解析。 -
(当然,通过 php 的 curl_getinfo() 给了我一个充满空值的数组......)
标签: php stripe-payments