From the course: Adding Stripe Payments to Your Ruby on Rails Application

Subscribing the customer in Stripe

- [Teacher] Now once we have the customers verified, we can start to create the subscriptions. So you'll want to create a new subscription object, and this going to be simple. We're going to take the customer subscriptions and create a new one. So this is simple, we will pass in a source, which will be params[:stripeToken], and that will be the credit card number that came from the JavaScript, and we'll have the plan, which comes from the form as params[:plan]. And this is as simple as that is. And then we need to save a reference to this on the current user. So we can assign attributes for the Stripe subscription ID column, we will just pass in the ID of the subscription object, and then we can call current_user.save. The reason we're not using an update here will become more apparent in a little bit when we make some future changes, but for now, we'll just write them like this so it will be easier to update in the future. And then, assuming that this went correctly, we can say flash.notice = "Thanks for subscribing!" and redirect to the root path so they can use the product. So all of this should work, and if we go test this out, and we submit the payment, this should subscribe the user to the monthly plan. This will take a little bit because it will go through Stripe, connect them to a plan, it says "Thanks for subscribing!" We should refresh our customer dashboard and click on that customer, and they now have a credit card on file as well as a payment, and they are actively subscribed to our monthly subscription. So all of our checkout stuff has worked perfectly, and we now have our very first customer subscribed in Stripe.

Contents