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

Unlock this course with a free trial

Join today to access over 22,700 courses taught by industry experts.

Creating a customer in Stripe

Creating a customer in Stripe

- [Instructor] So now we actually have to go create our customer in Stripe and then subscribe them to a plan. So, this is going to start out by creating a customer in Stripe. And the way we'll do that is we'll say current_user.stripe_customer and this will be a method that we create on the user model in order to find or create our Stripe customer. So if you're a new customer, then you will not have a Stripe customer record, so we'll create one for you. And if you're an existing customer resubscribing, then we'll just look you up instead of creating duplicate accounts in Stripe, which they allow, but it's better to organize things so you don't have duplicates there. So we'll open up our user model. And we'll create a method in here called stripe_customer. This method, we want to do a find or create on Stripe's API for their customer object. Now if you remember, our database table for users right here has a Stripe ID column which represents a customer ID in Stripe. So this is super…

Contents