FIX: Allow active status for updated webhook (#203)
Likely there was an API change at some point now that we are using the latest version of the stripe API. When the `customer.subscription.updated` webhook is called we should also accept the status of "active".
This commit is contained in:
parent
45754baa00
commit
6f54494a3b
|
@ -64,6 +64,9 @@ module DiscourseSubscriptions
|
|||
)
|
||||
when "customer.subscription.created"
|
||||
when "customer.subscription.updated"
|
||||
status = event[:data][:object][:status]
|
||||
return head 200 if !%w[complete active].include?(status)
|
||||
|
||||
customer =
|
||||
Customer.find_by(
|
||||
customer_id: event[:data][:object][:customer],
|
||||
|
@ -71,7 +74,6 @@ module DiscourseSubscriptions
|
|||
)
|
||||
|
||||
return render_json_error "customer not found" if !customer
|
||||
return head 200 if event[:data][:object][:status] != "complete"
|
||||
|
||||
user = ::User.find_by(id: customer.user_id)
|
||||
return render_json_error "user not found" if !user
|
||||
|
|
|
@ -204,6 +204,14 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
|
||||
it "adds the user to the group when status is active" do
|
||||
event_data[:object][:status] = "active"
|
||||
|
||||
expect { post "/s/hooks.json" }.to change { user.groups.count }.by(1)
|
||||
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue