Skip to content

Commit

Permalink
assign stripe_customer_id to newly registered users
Browse files Browse the repository at this point in the history
  • Loading branch information
yshmarov committed Mar 12, 2021
1 parent 93b6bcd commit 7dcba4d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable

def to_s
email
end

after_create do
customer = Stripe::Customer.create(email: self.email)
update(stripe_customer_id: customer.id)
end

end
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<%= link_to current_user.email, edit_user_registration_path %>
<%= link_to "Log out", destroy_user_session_path, method: :delete %>
<br>
Stripe customer id:
<%= current_user.stripe_customer_id %>
<br>
Plan:
<%= current_user.plan %>
<br>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20210312160417_add_stripe_customer_id_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddStripeCustomerIdToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :stripe_customer_id, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7dcba4d

Please sign in to comment.