From a63150423276c093a46fa8206abecf1eb960e8e1 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Sun, 27 Apr 2014 18:49:47 -0700 Subject: [PATCH] catch stripe webhook, send confirmation --- app.rb | 21 +++++++++++++++++++-- views/templates/email_subscription.erb | 11 +++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 views/templates/email_subscription.erb diff --git a/app.rb b/app.rb index 1eaa211d..d2e2ac5f 100644 --- a/app.rb +++ b/app.rb @@ -708,8 +708,25 @@ post '/contact' do end post '/stripe_webhook' do - event_json = JSON.parse(request.body.read) - puts event_json.inspect + event = JSON.parse request.body.read + if event['type'] == 'customer.created' + username = event['data']['object']['description'] + email = event['data']['object']['email'] + plan_name = event['data']['object']['subscriptions']['object']['data'].first['plan']['name'] + + site = Site[username: username] + halt 200, 'ok' if site.nil? + + EmailWorker.perform_async({ + from: 'web@neocities.org', + reply_to: site.email, + to: 'contact@neocities.org', + subject: "[NeoCities] You've become a supporter!", + body: Tilt.new('./views/templates/email_subscription.erb', pretty: true).render(self) + }) + end + + 'ok' end post '/api/upload' do diff --git a/views/templates/email_subscription.erb b/views/templates/email_subscription.erb new file mode 100644 index 00000000..ea327ff2 --- /dev/null +++ b/views/templates/email_subscription.erb @@ -0,0 +1,11 @@ +Hi there! + +We just wanted to email you to confirm your supporter upgrade! You are on the <%= plan_name %> support tier. You now have <%= Site::SUPPORTER_MAXIMUM_IN_MEGABYTES %> MB of space (and we're likely to upgrade this even more soon). We're looking forward to seeing the awesome things you will do with it. + +Thank you very, very much for supporting Neocities. It means a lot to us. It also helps us keep the free tier for others, so your support helps everyone. We'll try our hardest to keep improving the site and stick to our core values (NO MARKETING OR ADVERTISING, EVER). + +If you have any questions or comments, or just want to say hi, feel free to contact us at https://neocities.org/contact. You can also reach us on Twitter at @neocitiesweb. + +From Penelope (the Neocities' cat), the Neocities Team, and on behalf of all our sites, our very best wishes for you (and your awesome web site). + +- The Neocities Team \ No newline at end of file