Skip to content

Commit

Permalink
add customer.created event to webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
yshmarov committed Mar 13, 2021
1 parent 6fc9c4e commit bcae4ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/controllers/webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def create

# Handle the event
case event.type
when 'customer.create'
customer = event.data.object
@user = User.find_by(email: customer.email)
@user.update(stripe_customer_id: customer.id)
when 'checkout.session.completed'
session = event.data.object
@user = User.find_by(stripe_customer_id: session.customer)
Expand Down
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def to_s

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

end

0 comments on commit bcae4ea

Please sign in to comment.