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

hellomars's avatar

[Stripe] How do I check if a creditcard is attached?

Hi spark (or cashier) developers,

I am playing around with a Spark setup and Stripe and most of the stuff is working quite well. I can add an credit card as well as start subscriptions. However, I also want users to be able to pay single payments. If a credit card has been entered, the $user->charge(100); command works perfect. However, in my single payment view I would like to know if a user has any active credit cards so that I can display a message if they are not available. Is there a way of checking this?

Thanks in advance for your reply

0 likes
4 replies
Cronix's avatar

Haven't tried doing this, but when something gets successfully charged, it puts their stripe_id in the subscription table for the user. I don't think there is any guarantee that they have a "valid" card though until you actually try to charge something.

hellomars's avatar

Hi Cronix, you are right, a strip_id is indeed added to the subscription table. Out of curiosity, I deleted the creditcard on the stripe dashboard for a particular user. The stripe_id was still there (which makes sense, the consumer is still available) but the credit card fields were not empty on the Spark side. Not a very realistic scenario, but I also couldn't remove my credit card info on the Spark side.

Cronix's avatar

But the credit card info stored in spark is trivial, like the last 4 digits of the card number, what kind of card it is, and country. It isn't storing the specific card details. I'm not sure what you're meaning by "credit card info on the spark side"

hellomars's avatar

Hi Cronix, indeed the last four digits are stored but will it also be active? I guess I could always an exception and show this to the user.

Please or to participate in this conversation.