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

mr-grayda's avatar

Help understanding front-end Cashier stuff

I'm wanting to implement a subscription service into a webapp I'm building. I've had a look at Cashier and set up a Stripe account, but the documentation for Cashier is a bit sparse when it comes to the front-end stuff.

For example the Cashier docs show some HTML / CSS for adding a Stripe form (which is for changing an existing payment method), but some other videos (e.g. from Scotch.io) show building a form in Laravel by hand (e.g. by adding a <form> tag and fields for credit card number, expiration etc. into the user registration form). Laracasts shows copying and pasting some HTML / Javascript, but I can't find the page referred to because the video was from 6 years ago and the Stripe site has changed.

So my questions is:

What is the correct way to collect payment info from a user? Do I build the form myself? Does Stripe offer a snippet to use?

0 likes
1 reply
mr-grayda's avatar

Righto, so I got it mostly figured out. Here's a few notes that may help others. These notes might not be 100% correct, but they've what I've got noted for the time being:

  1. Securely catching the user's payment details is done through Stripe Elements, which is a Javascript library used to inject HTML into your page. A how-to can be found here in Stripe's documentation. In other words, you build most of the form (e.g. what subscription the user wants, any other details you want to catch) and Stripe just handles the credit card elements on the form.

  2. The Javascript you add also includes an event listener. It stops the form from submitting, makes a request to Stripe to store a payment_method, then returns that back to the Javascript. When the details from Stripe are received, a hidden element is appended to your form containing that info, then the form is submitted like normal. That payment_method can then be used to start a subscription.

  3. Even though Stripe has subscriptions and you can add different plans, Stripe Elements doesn't offer a drop-down box to select a plan. instead, you handle that front end stuff, then when the form is submitted, use the selected plan to start a subscription. For example in my app I have 3 radio buttons that I created. The user picks a plan, enters their card details and then submits the form. My app looks up a config file and finds the plan name (e.g. "Bronze"), and Stripe's plan ID (e.g. plan_StgYxG7xrUh2yD) and then creates a new subscription using the plan ID.

  4. As far as I can tell, you can't have a sign up sheet that both creates a user and starts a subscription. To start a subscription, the javascript needs to request a payment_method from Stripe. And you can only do that if you have a user created. After much hair tearing, I split my sign up form into two parts. First part just registers you like normal, then it redirects you to a subscription page where the user can decide on a plan and start a subscription

  5. Cashier is a bit confusing at first, because you don't know how much stuff you need to handle. At first I thought it was like laravel/ui where it generates everything, blades, controllers and everything so you can just tweak as necessary, then I thought Stripe would just have a checkout page (like PayPal subscription does) but as I learned more, I realized that it was just basically a Stripe SDK wrapper and that I needed to handle SOME, but not ALL things. For example, Stripe handles retrying failed payments, but unconfirmed payments are handled via a (hidden?) Laravel route. You also need to stop and start subscriptions. It's not like PayPal where you go to PayPal's website and say "I want to cancel". Therefore it's a bit daunting because you need to make sure your code is thoroughly tested, otherwise you'll have a lot of pissed off customers on your hands.

Please or to participate in this conversation.