Laravel 使用 Stripe\Customer 作为控制器中的 StripeCustomer 抛出错误

Laravel use Stripe\Customer as StripeCustomer in Controller throws Error

我在尝试在控制器中使用 StripeCustomer 时遇到问题。我需要从 Stripe 检索客户。所以我在我的控制器上:使用 Stripe\Customer 作为 StripeCustomer;我在 cashier's Billable.php 中看到这种用法。但是我尝试在我得到的控制器中使用它

Could not determine which URL to request: Stripe\Customer instance has invalid ID:

知道如何在控制器中使用 Stripe\Customer 吗?有命名空间的范围吗?提前致谢。

看起来代码找到得很好,所以您的 use 语句可能没有任何问题。

错误消息表明您正在尝试操作或使用未初始化的 Stripe\Customer 对象。

您的代码应该有点像这样(取自 Stripes 文档)

\Stripe\Stripe::setApiKey("sk_test_KZ3pTiXRPJ1gpqLlKlEGA3bY");
$customer = StripeCustomer::retrieve("cus_8gZXNXuq2kIsQv");
// work with $customer here... (assumes your use statement from the question)