Advertisement
Edomaia

Untitled

Jan 26th, 2021
225
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. case event.type
  2.     when 'checkout.session.completed'
  3.       session = event.data.object
  4.       @user = User.find_by(stripe_customer_id: session.customer)
  5.       @subscription = Subscription.new(user_id: @user.id)
  6.       @subscription.stripe_id = session.subscription
  7.       subscription_status = Stripe::Subscription.retrieve(session.subscription).status
  8.       @subscription.membership_id = session.metadata.membership_id
  9.       @subscription.update(subscription_status: subscription_status)
  10.       flash.notice = "Congratulations #{@user.first_name}!You are now subscribed to the #{session.metadata.membership_title}."
Advertisement
RAW Paste Data Copied
Advertisement