paymentMethods() retrieve always array with empty object.
public function userAllPaymentMethods(Request $request)
{
$user = User::find(5);
$paymentMethod = $user->paymentMethods();
return response($paymentMethod);
}
Result : https://www.screencast.com/t/aqenaud77A
Also using Stripe PaymentMethod lib it's works.
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);
}
Result :
https://www.screencast.com/t/X14ane7WyqS
GitHub : here
$paymentMethods = $user->paymentMethods()->map(function($paymentMethod){
return $paymentMethod->asStripePaymentMethod();
});
Here's a solution:
$paymentMethods = [];
foreach ($user->paymentMethods() as $paymentMethod) {
$paymentMethods[] = $paymentMethod->asStripePaymentMethod();
}
Just loop through the payment methods and using $paymentMethod->asStripePaymentMethod() will get the payment methods for the user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With