- [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 customersubscriptions 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 camefrom 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 referenceto this on the current user.So we can assign attributes forthe 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 herewill become more apparent in a little bitwhen we make some future changes,but for now, we'll just write them like thisso it will be easier to update in the future.And then, assuming that this went correctly, we can sayflash.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 gotest 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 gothrough Stripe, connect them to a plan,it says "Thanks for subscribing!"We should refresh our customer dashboard and clickon that customer, and they now have a credit cardon file as well as a payment, and they are activelysubscribed to our monthly subscription.

So all of our checkout stuff has worked perfectly, andwe now have our very first customer subscribed in Stripe.

Resume Transcript Auto-Scroll

Author

Released

12/16/2016

Add Stripe to your Ruby on Rails application to collect payments from your users. Stripe allows developers to add Payment Card Industry-compliant ecommerce functionality without having to implement complicated security. The result is an efficient and secure app experience, with fully encrypted token-based transactions that allow you to charge for content on a monthly or annual basis. In this course, Chris Oliver teaches you how to build a Rails app with paid content, securely collect credit card numbers, charge your users for a subscription to your site, and give them access to the paid content, all with Stripe.js and the Stripe Ruby gem. You'll also learn how to allow customers to unsubscribe and resubscribe from the app, and create PDF receipts for charges.