From d085a99ddc07228a592e0ff6623153753ab761fb Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Fri, 13 Mar 2015 11:27:39 -0500 Subject: [PATCH] Add more catches for stripe events --- app/stripe_webhook.rb | 28 +++++++++++++++++++++++ views/templates/email/charge_failure.erb | 10 ++++++++ views/templates/email/supporter_ended.erb | 11 +++++++++ 3 files changed, 49 insertions(+) create mode 100644 views/templates/email/charge_failure.erb create mode 100644 views/templates/email/supporter_ended.erb diff --git a/app/stripe_webhook.rb b/app/stripe_webhook.rb index 00b04839..4b335a1e 100644 --- a/app/stripe_webhook.rb +++ b/app/stripe_webhook.rb @@ -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 diff --git a/views/templates/email/charge_failure.erb b/views/templates/email/charge_failure.erb new file mode 100644 index 00000000..26145982 --- /dev/null +++ b/views/templates/email/charge_failure.erb @@ -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 diff --git a/views/templates/email/supporter_ended.erb b/views/templates/email/supporter_ended.erb new file mode 100644 index 00000000..cab30368 --- /dev/null +++ b/views/templates/email/supporter_ended.erb @@ -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