- 收银版:^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/