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

Nite's avatar
Level 1

Cashier - Get Stripe PaymentMethod object from id

I'm trying to update the payment method of a subscription. I collect the card information using Stripe's js (using a provided setup intent). Then I send the payment method id, retrieved by Stripe's js, to the server to actually update the User default payment method.

Now, the problem is I want to prevent the User to insert duplicated cards, and the only way to prevent that would be to retrieve all the user current payment methods ($user->paymentMethods();), and check if any of those has the same fingerprint of the one I'm adding as default. To get the fingerprint of the new payment method I'd need to get the Stripe PaymentMethod object for that id. The Cashier method to do that would be findPaymentMethod(id).

The problem is that the payment id received by the server is not yet added to the User payments methods, so $user->findPaymentMethod($request->payment_method); fails because that payment method does not belong to $user.

The only solution I can think of would be to first add the new payment method, then check for duplicates and remove them ?

0 likes
0 replies

Please or to participate in this conversation.