rm subscription event

This commit is contained in:
Rimian Perkins 2020-01-14 20:58:34 +11:00
parent 071e1d6cb5
commit 190ca28089
1 changed files with 24 additions and 0 deletions

View File

@ -2,6 +2,7 @@
module DiscourseSubscriptions
class HooksController < ::ApplicationController
include DiscourseSubscriptions::Group
skip_before_action :verify_authenticity_token, only: [:create]
def create
@ -20,6 +21,29 @@ module DiscourseSubscriptions
return
end
# Handle the event
case event[:type]
when 'customer.subscription.deleted'
customer = Customer.find_by(
customer_id: event[:customer],
product_id: event[:plan][:product]
)
if customer
customer.delete
user = ::User.find(customer.user_id)
group = plan_group(event[:plan])
group.remove(user) if group
end
else
# Unexpected event type
status 400
return
end
head 200
end
end