Add more catches for stripe events

This commit is contained in:
Kyle Drake 2015-03-13 11:27:39 -05:00
parent 4e0ff8a7ca
commit d085a99ddc
3 changed files with 49 additions and 0 deletions

View file

@ -11,5 +11,33 @@ post '/stripe_webhook' do
body: "#{username}\n#{email}\n#{Site[username: username].uri}"
})
end
if event['type'] == 'charge.failed'
site_id = event['data']['object']['description'].split(' - ').last
site = Site[site_id]
EmailWorker.perform_async({
from: 'web@neocities.org',
to: site.email,
subject: "[Neocities] There was an issue charging your card",
body: Tilt.new('./views/templates/email/charge_failure.erb', pretty: true).render(self)
})
end
if event['type'] == 'customer.subscription.deleted'
site_id = event['data']['object']['description'].split(' - ').last
site = Site[site_id]
site.stripe_subscription_id = nil
site.plan_type = nil
site.save_changes validate: false
EmailWorker.perform_async({
from: 'web@neocities.org',
to: site.email,
subject: "[Neocities] Supporter plan has ended",
body: Tilt.new('./views/templates/email/supporter_ended.erb', pretty: true).render(self)
})
end
'ok'
end

View file

@ -0,0 +1,10 @@
Hello,
We're writing to let you know that Neocities has had an issue charging your card. We will try again automatically in a few days, but we just wanted to give you a heads up in case something is wrong with your card.
We will retry over the next few weeks. If we can't make a successful charge, your account will be downgraded from supporter to the free plan.
If you need to change the card on file, you can do so on the settings page. If you run into any issues, please contact us at https://neocities.org/contact.
Regards,
- The Neocities Team

View file

@ -0,0 +1,11 @@
Hi there,
We're just emailing to let you know that your supporter plan has ended.
If you feel this is in error, please re-register for a supporter account on Neocities, or contact us at https://neocities.org/contact and we'll take a look.
We're sorry to see you go, but we understand. Thanks for helping us out (it means a lot), and our best wishes to you!
Regards,
- The Neocities Team