Join Chris Oliver for an in-depth discussion in this video Subscribing the customer in Stripe, part of Adding Stripe Payments to Your Ruby on Rails Application.
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.
- Adding users and products to the application
- Creating a checkout form
- Creating and sending card tokens
- Subscribing the customer
- Charging the customer
- Allowing users to update payment info, cancel, and resubscribe
- Adding receipts with webhooks