mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-02-19 18:04:45 +00:00
deletes the customer on subscription cancel
This commit is contained in:
parent
190ca28089
commit
dca6c7ddc9
@ -21,7 +21,6 @@ module DiscourseSubscriptions
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Handle the event
|
|
||||||
case event[:type]
|
case event[:type]
|
||||||
when 'customer.subscription.deleted'
|
when 'customer.subscription.deleted'
|
||||||
|
|
||||||
@ -32,16 +31,13 @@ module DiscourseSubscriptions
|
|||||||
|
|
||||||
if customer
|
if customer
|
||||||
customer.delete
|
customer.delete
|
||||||
|
#
|
||||||
user = ::User.find(customer.user_id)
|
# binding.pry
|
||||||
group = plan_group(event[:plan])
|
#
|
||||||
group.remove(user) if group
|
# user = ::User.find(customer.user_id)
|
||||||
|
# group = plan_group(event[:plan])
|
||||||
|
# group.remove(user) if group
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
|
||||||
# Unexpected event type
|
|
||||||
status 400
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
head 200
|
head 200
|
||||||
|
@ -10,15 +10,44 @@ module DiscourseSubscriptions
|
|||||||
|
|
||||||
it "contructs a webhook event" do
|
it "contructs a webhook event" do
|
||||||
payload = 'we-want-a-shrubbery'
|
payload = 'we-want-a-shrubbery'
|
||||||
headers = { 'HTTP_STRIPE_SIGNATURE' => 'stripe-webhook-signature' }
|
headers = { HTTP_STRIPE_SIGNATURE: 'stripe-webhook-signature' }
|
||||||
|
|
||||||
::Stripe::Webhook
|
::Stripe::Webhook
|
||||||
.expects(:construct_event)
|
.expects(:construct_event)
|
||||||
.with('we-want-a-shrubbery', 'stripe-webhook-signature', 'zascharoo')
|
.with('we-want-a-shrubbery', 'stripe-webhook-signature', 'zascharoo')
|
||||||
|
.returns(type: 'something')
|
||||||
|
|
||||||
post "/s/hooks.json", params: payload, headers: headers
|
post "/s/hooks.json", params: payload, headers: headers
|
||||||
|
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "cancels a subscription" do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
group = Fabricate(:group, name: 'subscribers-group')
|
||||||
|
|
||||||
|
customer = Fabricate(
|
||||||
|
:customer,
|
||||||
|
customer_id: 'c_575768',
|
||||||
|
product_id: 'p_8654',
|
||||||
|
user_id: user.id
|
||||||
|
)
|
||||||
|
|
||||||
|
event = {
|
||||||
|
type: 'customer.subscription.deleted',
|
||||||
|
customer: customer.customer_id,
|
||||||
|
plan: { product: customer.product_id, metadata: { group_name: group.name } }
|
||||||
|
}
|
||||||
|
|
||||||
|
::Stripe::Webhook
|
||||||
|
.expects(:construct_event)
|
||||||
|
.returns(event)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
post "/s/hooks.json"
|
||||||
|
}.to change { DiscourseSubscriptions::Customer.count }.by(-1)
|
||||||
|
|
||||||
|
expect(response.status).to eq 200
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user