Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PomoPunk's avatar

Trying to retrieve Stripe payment methods; returns null object.

public function getPaymentMethods(Request $request)
    {
        $user = $request->user();
        $paymentMethods = $user->PaymentMethods();

        info($user->PaymentMethods());

        return response()->json($paymentMethods);
    }

The above presents in the logs:

[2020-01-23 21:07:26] local.INFO: [{}] 

However, if given:

public function getPaymentMethods(Request $request)
    {
        $user = $request->user();
        $paymentMethods = $user->paymentMethods();

        info($user->hasPaymentMethod());

        return response()->json($paymentMethods);
    }

Logs present:

[2020-01-23 21:09:18] local.INFO: 1

So "$user->hasPaymentMethod()" returns true, but trying to call those payment methods with "user->paymentmethods()" returns null. We do have a stripe_id for a payment method associated with the user stored locally. Am I missing something?

0 likes
2 replies
PomoPunk's avatar

We've been heavily relying on the Laravel Cashier documentation: https://laravel.com/docs/6.x/billing

Referring to the section under "Retrieving Payment Methods," this is the method as it appears in vendor/laravel/cashier/src/Billable.php

public function paymentMethods($parameters = [])
    {
        $this->assertCustomerExists();

        $parameters = array_merge(['limit' => 24], $parameters);

        // "type" is temporarily required by Stripe...
        $paymentMethods = StripePaymentMethod::all(
            ['customer' => $this->stripe_id, 'type' => 'card'] + $parameters,
            $this->stripeOptions()
        );

        return collect($paymentMethods->data)->map(function ($paymentMethod) {
            return new PaymentMethod($this, $paymentMethod);
        });
    }

Please or to participate in this conversation.