PHP - 条纹 Client/Customer 创建无效

PHP - Stripe Client/Customer Creation not working

我正在尝试创建一个新的 Stripe 客户端,然后它将用于创建一个新的客户。 但是当我尝试创建客户端时出现错误 (但没有错误消息).

$email = "test@gmail.com"; // Only for testing: is drawn from my database above

// STRIPE STUFF //
require_once('./vendor/autoload.php');

echo "OK";

// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/account/apikeys
$stripe = new \Stripe\StripeClient('sk_test_***');

echo "OK";

// Create the Customer
$customer = $stripe->customers->create([
    'email' => $email
]);
$customerResponse = json_decode($response->withJson(['customer' => $customer]), TRUE);

$stripeCustomerId = $customerResponse["id"];

输出了第一个“OK”,但没有输出第二个“OK”,之后没有执行进一步的代码。所以这一定是因为我如何创建 Stripe 客户端,但不幸的是我在 Stack Overflow 或 Stripe 文档中找不到任何对我有帮助的东西。

StripeClient class 是几个月前由 Stripe 添加的。它在 stripe-php 的 7.33.0 版本中发布,如文档 here 所示。这意味着如果您使用的是旧版本的库,class 将不存在。

根据您分享的代码以及它在第一次回显后如何崩溃,这可能是问题所在。您没有足够新的库版本,并且您的代码无法安全地处理错误并崩溃。如果您查看系统上的 PHP 错误日志,很可能会显示一条错误消息,指出 StripeClient class 不存在。

尽管最好升级到最新版本,但您至少需要升级到 7.33.0 版本。如果您使用的是 7.x 之前的版本,请确保查看版本 7.x 中的重大更改:https://github.com/stripe/stripe-php/wiki/Migration-guide-for-v7