catch stripe webhook, send confirmation

This commit is contained in:
Kyle Drake 2014-04-27 18:49:47 -07:00
parent d994536017
commit a631504232
2 changed files with 30 additions and 2 deletions

21
app.rb
View file

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