Email invoice support

This commit is contained in:
Kyle Drake 2017-10-04 20:27:24 -07:00
parent ea760fc849
commit 68352e3d8f
3 changed files with 37 additions and 1 deletions

View file

@ -265,6 +265,7 @@ post '/settings/change_email_notification' do
owner.send_emails = params[:send_emails]
owner.send_comment_emails = params[:send_comment_emails]
owner.send_follow_emails = params[:send_follow_emails]
owner.email_invoice = params[:email_invoice]
owner.save_changes validate: false
flash[:success] = 'Email notification settings have been updated.'
redirect '/settings#email'

View file

@ -102,6 +102,29 @@ post '/webhooks/stripe' do
})
end
if event['type'] == 'invoice.payment_succeeded'
site = stripe_get_site_from_event event
if site.email_invoice && site.stripe_paying_supporter?
invoice_obj = event['data']['object']
EmailWorker.perform_async({
from: 'web@neocities.org',
to: site.email,
subject: "[Neocities] Invoice",
body: Tilt.new('./views/templates/email/invoice.erb', pretty: true).render(
self,
site: site,
amount: invoice_obj['amount_due'],
period_start: Time.at(invoice_obj['period_start']),
period_end: Time.at(invoice_obj['period_end']),
date: Time.at(invoice_obj['date'])
)
})
end
end
'ok'
end

View file

@ -25,6 +25,18 @@
>
</p>
<% if current_site.owner.stripe_paying_supporter? %>
<p>
Receive Invoice Receipts:
<input name="email_invoice" type="hidden" value="false">
<input name="email_invoice" type="checkbox" value="true"
<% if current_site.owner.email_invoice %>
checked
<% end %>
>
</p>
<% end %>
<p>
Receive Comment Emails:
<input name="send_comment_emails" type="hidden" value="false">