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

rabol's avatar
Level 14

Cashier addPaymentMethod does not update card_brand

Hi

I have been struggling with making the latest version of Cashier work.

My flow is like this: User select a 'plan' Check if the user is a stripe user - check if strip_id is filled on the user, if not create a stripe customer

check to see if the user have payment methods - auth()->user()->hasPaymentMethod()

if the user does not have a payment method, then show a form and capture the 'payment method' The payment method is saved like this: auth()->user()->addPaymentMethod($paymentMethod)

then I redirect the user to the plans page as now we should have a valid payment method - It even shows up in the Stripe Dashboard

but... auth()->user()->hasPaymentMethod() return 'false'

 public function hasPaymentMethod()
    {
        return (bool) $this->card_brand;
    }

the card_brand is never filled when calling the addPaymentMethod. card_brand is only filled in fillPaymentMethodDetails(), and the fillPaymentMethodDetails() method is only called when one update the default payment method

So my question is: What do I need to do to make the hasPaymentMethod() working ?

0 likes
7 replies
Nakov's avatar

@rabol I just tried, and got the same result as you did.. Then I set a default payment method for my account using this:

$user->updateDefaultPaymentMethod($user->paymentMethods()->first()->id);

Now when I try:

$user->hasPaymentMethod();

it does returns true.

1 like
rabol's avatar
Level 14

yes, I know that I can 'trick' the system, but I think that the user should be in control of which payment method is the default and not the first.

If the user 'delete' his default card in Strip, but still have 2-3-4 other payment methods, then I should get theses and allow the user to select which to use and if there is more than one, then hasPaymentMethod() should not return false

from the Documentation:

"To determine if a Billable model has a payment method attached to their account, use the hasPaymentMethod method:"

Nakov's avatar

@rabol but it is not tricking the system, I gave you just an example. I would list all the payment methods and allow the user to select the preferred one and use that one as a Default. But in order for hasPaymentMethod to work, you will have to select a default one. Laravel won't do that for you, because then it is really tricking the user. You charge him/her from a card that is not his/her preferred one.

I hope you get my point of view.

You can list all payment methods for the user using $user->paymentMethods(). I have that in my repo that I've created for your other post.

rabol's avatar
Level 14

I'm sorry, but I do not see the example, you simply

$user->updateDefaultPaymentMethod($user->paymentMethods()->first()->id);

which is a 'trick'

My point is that haPaymentMethod() should return true if the user have any payment methods, and then i should use defaultPaymentMethod() to get the default payment, and if there is no default payment method, let the user select one of the payment methods on his profile

Nakov's avatar

@rabol I am sorry, I am just showing you what I see and how I manage to make it work. Checked the Billable trait and in order for the card_brand to have any value, the user has to have a default payment method, otherwise it just returns false. That's it.

Trying to help here, but obviously you don't like my answers.

No this is not a trick:

$user->updateDefaultPaymentMethod($user->paymentMethods()->first()->id);

it is an example on how a user default payment method can be set..

Will this be more of a helpful example:

$user->updateDefaultPaymentMethod("pm_asdsadsa");   

Then I will be asked what is the string in there..

Or I remember, you want someone to do the complete job for you.. But we are programmers that's our job, to find a way out, using documentation, trying out and debug..

I am out of here :) Sorry once again if I offended you somehow, not my intention in any shape or form.

rabol's avatar
Level 14

It's about liking your answer, the point is that I was trying to figure out the behaviour of a method.

The method name is hasPaymentMehod, and the doc say that it can be used to check if a billable model have a payment method.

Even after adding a payment method, using addPaymentMethod() the hasPaymentMethod() returns false.

I have reported it at github and it will be fixed

A workaround could be like this:

in the model where you use the Billable trait:

        use Billable {
            hasPaymentMethod as traithasPaymentMethod;
        }

    public function hasPaymentMethod()
    {
        return (bool) $this->paymentMethods()->count();
    }

Please or to participate in this conversation.