mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
fix supporter plan management
This commit is contained in:
parent
f44ce014d3
commit
52fde7a0d5
4 changed files with 31 additions and 24 deletions
43
app.rb
43
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
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<div class="content single-Col misc-page">
|
||||
<h3>Ending the Supporter Plan</h3>
|
||||
<p>
|
||||
You currently have the <strong><%= current_site.plan_name %> (<%= current_site.maximum_space.to_space_pretty %>)</strong> - <%= @plan_name %>.
|
||||
You currently have the <strong><%= parent_site.plan_name %> (<%= parent_site.maximum_space.to_space_pretty %>)</strong> - <%= @plan_name %>.
|
||||
</p>
|
||||
<p>
|
||||
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 <a href="/contact">contact us</a> 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!
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
<div class="content single-Col misc-page">
|
||||
<h3></h3>
|
||||
|
||||
<% if current_site && current_site.supporter? && !current_site.plan_ended %>
|
||||
<% if parent_site && parent_site.supporter? && !parent_site.plan_ended %>
|
||||
<p>
|
||||
You currently have the <strong><%= current_site.plan_name %> (<%= current_site.maximum_space.to_space_pretty %>)</strong>.
|
||||
You currently have the <strong><%= parent_site.plan_name %> (<%= parent_site.maximum_space.to_space_pretty %>)</strong>.
|
||||
</p>
|
||||
<p>
|
||||
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 <a href="/contact">contact us</a>.
|
||||
|
@ -27,8 +27,8 @@
|
|||
|
||||
<a href="/plan/manage">Manage plan</a>
|
||||
<% else %>
|
||||
<% if current_site %>
|
||||
<p>You currently have the <strong>Free Plan (<%= current_site.maximum_space.to_space_pretty %>)</strong>. Need more space? Become a <strong>Neocities Supporter!</strong></p>
|
||||
<% if parent_site %>
|
||||
<p>You currently have the <strong>Free Plan (<%= parent_site.maximum_space.to_space_pretty %>)</strong>. Need more space? Become a <strong>Neocities Supporter!</strong></p>
|
||||
|
||||
<h3>Why upgrade?</h3>
|
||||
<% else %>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<div class="content single-Col misc-page">
|
||||
<h3>Change your Supporter Plan</h3>
|
||||
<p>
|
||||
You currently have the <strong><%= current_site.plan_name %> (<%= current_site.maximum_space.to_space_pretty %>)</strong> - <%= @plan_name %>.
|
||||
You currently have the <strong><%= parent_site.plan_name %> (<%= parent_site.maximum_space.to_space_pretty %>)</strong> - <%= @plan_name %>.
|
||||
</p>
|
||||
|
||||
<a href="/plan/end">End plan</a>
|
||||
|
|
Loading…
Add table
Reference in a new issue