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

mruiz's avatar
Level 1

Cashier: newSubscription doesn't create Stripe user

It's not clear from the documentation but, from what I've gleaned anecdotally from others' comments and examples, the newSubscription function is supposed to: a. take the token as created in createToken() b. create customer in Stripe c. associate a new subscription with that new customer d. update Laravel databases accordingly

Is this correct? In my testing, I always get the same message: "message": "No such customer: tok_********************", "exception": "Stripe\Error\InvalidRequest",

because Cashier has not in fact created a Stripe user using my token.

Apologies if I'm missing something obvious. Are we supposed to use the Stripe PHP to create Customer and THEN use Cashier to associate a subscription to that customer?

0 likes
6 replies
shez1983's avatar

code? but you are correct, users fill in form, request gets sent to stripe using js, they send back the token which you use.

mruiz's avatar
Level 1

Right, I get the token correctly, and then I do:

$user->newSubscription('main', 'my_plan_name')->create($request);

with that token, but no Stripe Customer has been created, so it always fails: there's no Stripe Customer to associate the subscription with. That's why I'm assuming there must be another step, either with Cashier, or via the Stripe PHP, that creates the Stripe Customer?

shez1983's avatar

this should be:

$user->newSubscription('main', 'my_plan_name')->create($request->token);

mruiz's avatar
Level 1

Sorry, I should have explained, $request in my code above represents the Stripe token, I don't need to specify $request->token

I guess I'm not really asking for coding help, my question is more conceptual: is the newSubscription function actually supposed to create a Stripe Customer?

The documentation suggests that as long as I have a User record in my database with the stripe_id (tok_****) defined for it, the newSubscription function will somehow both create the Stripe user with that token associated, and then add a Subscription for that User, both in Stripe and in the database. That doesn't happen for me: calling newSubscription doesn't create a Stripe Customer, so the subscription part always fails.

shez1983's avatar

i think when the JS code sends users details to stripe THAT creates a new token. this code just creates a new subscription for that user.

You can always dig down and see exactly what newSubscription() does.

mruiz's avatar
mruiz
OP
Best Answer
Level 1

Turns out that the term "stripe_id" in the documentation, Laravel means the Stripe Customer ID (cus_1234), although I don't see that that's explicitly defined anywhere. So I was mistakenly saving the Stripe token as stripe_id (tok_1234), and then trying to add the subscription to the user later, which doesn't work. Maybe this is intuitive to people who've used Laravel extensively.

Please or to participate in this conversation.