diff --git a/app.rb b/app.rb index 94e67062..72dd448a 100644 --- a/app.rb +++ b/app.rb @@ -271,68 +271,74 @@ post '/plan/create' do DB.transaction do customer = Stripe::Customer.create( card: params[:stripe_token], - description: current_site.username, + description: "#{parent_site.username} - #{parent_site.id}", email: current_site.email, plan: params[:selected_plan] ) - current_site.update stripe_customer_id: customer.id, plan_ended: false + parent_site.update stripe_customer_id: customer.id, plan_ended: false plan_name = customer.subscriptions.first['plan']['name'] - EmailWorker.perform_async({ - from: 'web@neocities.org', - reply_to: 'contact@neocities.org', - to: current_site.email, - subject: "[Neocities] You've become a supporter!", - body: Tilt.new('./views/templates/email_subscription.erb', pretty: true).render(self, plan_name: plan_name) - }) + if current_site.email || parent_site.email + EmailWorker.perform_async({ + from: 'web@neocities.org', + reply_to: 'contact@neocities.org', + to: current_site.email || parent_site.email, + subject: "[Neocities] You've become a supporter!", + body: Tilt.new('./views/templates/email_subscription.erb', pretty: true).render(self, plan_name: plan_name) + }) + end end redirect '/plan' end def get_plan_name(customer_id) - subscriptions = Stripe::Customer.retrieve(current_site.stripe_customer_id).subscriptions.all + subscriptions = Stripe::Customer.retrieve(parent_site.stripe_customer_id).subscriptions.all @plan_name = subscriptions.first.plan.name end +def require_active_subscription + redirect '/plan' unless parent_site.supporter? && !parent_site.plan_ended +end + get '/plan/manage' do require_login - redirect '/plan' unless current_site.supporter? && !current_site.plan_ended + require_active_subscription @title = 'Manage Plan' - @plan_name = get_plan_name current_site.stripe_customer_id + @plan_name = get_plan_name parent_site.stripe_customer_id erb :'plan/manage' end get '/plan/end' do require_login - redirect '/plan' unless current_site.supporter? && !current_site.plan_ended + require_active_subscription @title = 'End Plan' - @plan_name = get_plan_name current_site.stripe_customer_id + @plan_name = get_plan_name parent_site.stripe_customer_id erb :'plan/end' end post '/plan/end' do require_login - redirect '/plan' unless current_site.supporter? && !current_site.plan_ended + require_active_subscription recaptcha_is_valid = ENV['RACK_ENV'] == 'test' || recaptcha_valid? if !recaptcha_is_valid @error = 'Recaptcha was filled out incorrectly, please try re-entering.' - @plan_name = get_plan_name current_site.stripe_customer_id + @plan_name = get_plan_name parent_site.stripe_customer_id halt erb :'plan/end' end - customer = Stripe::Customer.retrieve current_site.stripe_customer_id + customer = Stripe::Customer.retrieve parent_site.stripe_customer_id subscriptions = customer.subscriptions.all DB.transaction do subscriptions.each do |subscription| customer.subscriptions.retrieve(subscription.id).delete end - current_site.update plan_ended: true + parent_site.update plan_ended: true end redirect '/plan' @@ -1454,6 +1460,7 @@ def current_site end def parent_site + return nil if current_site.nil? current_site.parent? ? current_site : current_site.parent end diff --git a/views/plan/end.erb b/views/plan/end.erb index 34b19db5..8db2f976 100644 --- a/views/plan/end.erb +++ b/views/plan/end.erb @@ -12,7 +12,7 @@

Ending the Supporter Plan

- You currently have the <%= current_site.plan_name %> (<%= current_site.maximum_space.to_space_pretty %>) - <%= @plan_name %>. + You currently have the <%= parent_site.plan_name %> (<%= parent_site.maximum_space.to_space_pretty %>) - <%= @plan_name %>.

If you need to end the plan, you can do that here. We'll be sorry to see you go. If there's a reason you're ending that we can help with, please contact us and we'll see if we can help you with your issue. Regardless, we'll let you keep your site and the extra space. We hope you'll decide to become a supporter again in the future! diff --git a/views/plan/index.erb b/views/plan/index.erb index 8667ef03..4608f14a 100644 --- a/views/plan/index.erb +++ b/views/plan/index.erb @@ -17,9 +17,9 @@

- <% if current_site && current_site.supporter? && !current_site.plan_ended %> + <% if parent_site && parent_site.supporter? && !parent_site.plan_ended %>

- You currently have the <%= current_site.plan_name %> (<%= current_site.maximum_space.to_space_pretty %>). + You currently have the <%= parent_site.plan_name %> (<%= parent_site.maximum_space.to_space_pretty %>).

Your support means a lot to us. On behalf of Penelope the cat and everyone at Neocities, thank you. If there's anything we can do to make your experience even better, please don't hesitate to contact us. @@ -27,8 +27,8 @@ Manage plan <% else %> - <% if current_site %> -

You currently have the Free Plan (<%= current_site.maximum_space.to_space_pretty %>). Need more space? Become a Neocities Supporter!

+ <% if parent_site %> +

You currently have the Free Plan (<%= parent_site.maximum_space.to_space_pretty %>). Need more space? Become a Neocities Supporter!

Why upgrade?

<% else %> diff --git a/views/plan/manage.erb b/views/plan/manage.erb index 9cf57cf8..a2fecc3c 100644 --- a/views/plan/manage.erb +++ b/views/plan/manage.erb @@ -12,7 +12,7 @@

Change your Supporter Plan

- You currently have the <%= current_site.plan_name %> (<%= current_site.maximum_space.to_space_pretty %>) - <%= @plan_name %>. + You currently have the <%= parent_site.plan_name %> (<%= parent_site.maximum_space.to_space_pretty %>) - <%= @plan_name %>.

End plan