gpt4 book ai didi

php - Laravel Cashier paymentMethods() 总是返回空对象结果

转载 作者:行者123 更新时间:2023-12-05 08:25:59 25 4
gpt4 key购买 nike

  • 收银版:^10.5
  • Laravel 版本:^6.0
  • PHP 版本:7.3.5
  • 数据库驱动程序和版本:

描述:

paymentMethods() 始终检索具有空对象的数组。

public function userAllPaymentMethods(Request $request)
{
$user = User::find(5);
$paymentMethod = $user->paymentMethods();
return response($paymentMethod);
}

结果: https://www.screencast.com/t/aqenaud77A

也可以使用 Stripe PaymentMethod 库。

public function userAllPaymentMethods(Request $request)
{
$user = User::find(5);
\Stripe\Stripe::setApiKey('{{KEY}}');
$paymentMethod = \Stripe\PaymentMethod::all([
'customer' => $user->stripe_id,
'type' => 'card',
]);

return response($paymentMethod);
}

结果:
https://www.screencast.com/t/X14ane7WyqS

GitHub : here

最佳答案

$paymentMethods = $user->paymentMethods()->map(function($paymentMethod){
return $paymentMethod->asStripePaymentMethod();
});

关于php - Laravel Cashier paymentMethods() 总是返回空对象结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58898278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com