rm subscription event
This commit is contained in:
parent
071e1d6cb5
commit
190ca28089
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
module DiscourseSubscriptions
|
module DiscourseSubscriptions
|
||||||
class HooksController < ::ApplicationController
|
class HooksController < ::ApplicationController
|
||||||
|
include DiscourseSubscriptions::Group
|
||||||
skip_before_action :verify_authenticity_token, only: [:create]
|
skip_before_action :verify_authenticity_token, only: [:create]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -20,6 +21,29 @@ module DiscourseSubscriptions
|
||||||
return
|
return
|
||||||
end
|
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
|
head 200
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue