diff --git a/app/settings.rb b/app/settings.rb index c10096ff..83178d5c 100644 --- a/app/settings.rb +++ b/app/settings.rb @@ -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' diff --git a/app/webhooks.rb b/app/webhooks.rb index 1bd1250a..27892dab 100644 --- a/app/webhooks.rb +++ b/app/webhooks.rb @@ -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 diff --git a/views/settings/account/email.erb b/views/settings/account/email.erb index dbf2a186..f5b7359b 100644 --- a/views/settings/account/email.erb +++ b/views/settings/account/email.erb @@ -25,6 +25,18 @@ >
+ <% if current_site.owner.stripe_paying_supporter? %> ++ Receive Invoice Receipts: + + + checked + <% end %> + > +
+ <% end %> +Receive Comment Emails: @@ -48,4 +60,4 @@