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:
Blake Erickson 2024-04-29 15:50:05 -06:00 committed by GitHub
parent 45754baa00
commit 6f54494a3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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