mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
code for legacy supporters
This commit is contained in:
parent
9d6e2566dd
commit
78b11c75dd
3 changed files with 48 additions and 92 deletions
97
app.rb
97
app.rb
|
@ -268,7 +268,16 @@ def generate_question
|
|||
end
|
||||
|
||||
get '/plan/?' do
|
||||
@title = 'Supporter'
|
||||
@title = 'Support Us'
|
||||
|
||||
if parent_site && parent_site.unconverted_legacy_supporter?
|
||||
customer = Stripe::Customer.retrieve(parent_site.stripe_customer_id)
|
||||
subscription = customer.subscriptions.first
|
||||
parent_site.stripe_subscription_id = subscription.id
|
||||
parent_site.plan_type = subscription.plan.id
|
||||
parent_site.save_changes
|
||||
end
|
||||
|
||||
erb :'plan/index'
|
||||
end
|
||||
|
||||
|
@ -321,92 +330,6 @@ get '/plan/thanks' do
|
|||
erb :'plan/thanks'
|
||||
end
|
||||
|
||||
=begin
|
||||
get '/plan/?' do
|
||||
@title = 'Supporter'
|
||||
erb :'plan/index'
|
||||
end
|
||||
|
||||
post '/plan/create' do
|
||||
require_login
|
||||
|
||||
DB.transaction do
|
||||
customer = Stripe::Customer.create(
|
||||
card: params[:stripe_token],
|
||||
description: "#{parent_site.username} - #{parent_site.id}",
|
||||
email: current_site.email,
|
||||
plan: params[:selected_plan]
|
||||
)
|
||||
|
||||
parent_site.update stripe_customer_id: customer.id, plan_ended: false
|
||||
|
||||
plan_name = customer.subscriptions.first['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(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
|
||||
require_active_subscription
|
||||
@title = 'Manage Plan'
|
||||
@plan_name = get_plan_name parent_site.stripe_customer_id
|
||||
erb :'plan/manage'
|
||||
end
|
||||
|
||||
get '/plan/end' do
|
||||
require_login
|
||||
require_active_subscription
|
||||
@title = 'End Plan'
|
||||
@plan_name = get_plan_name parent_site.stripe_customer_id
|
||||
erb :'plan/end'
|
||||
end
|
||||
|
||||
post '/plan/end' do
|
||||
require_login
|
||||
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 parent_site.stripe_customer_id
|
||||
halt erb :'plan/end'
|
||||
end
|
||||
|
||||
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
|
||||
parent_site.update plan_ended: true
|
||||
end
|
||||
|
||||
redirect '/plan'
|
||||
end
|
||||
=end
|
||||
|
||||
get '/site/:username/tip' do |username|
|
||||
@site = Site[username: username]
|
||||
@title = "Tip #{@site.title}"
|
||||
|
|
|
@ -115,6 +115,15 @@ class Site < Sequel::Model
|
|||
unlimited_site_creation: false
|
||||
)
|
||||
|
||||
LEGACY_SUPPORTER_PRICES = {
|
||||
plan_one: 1,
|
||||
plan_two: 2,
|
||||
plan_three: 3,
|
||||
plan_four: 4,
|
||||
plan_five: 5
|
||||
}
|
||||
|
||||
|
||||
many_to_many :tags
|
||||
|
||||
one_to_many :profile_comments
|
||||
|
@ -879,8 +888,17 @@ class Site < Sequel::Model
|
|||
PLAN_FEATURES[plan_type.to_sym][:name]
|
||||
end
|
||||
|
||||
def unconverted_legacy_supporter?
|
||||
stripe_customer_id && !plan_ended && values[:plan_type].nil? && stripe_subscription_id.nil?
|
||||
end
|
||||
|
||||
def legacy_supporter?
|
||||
!values[:plan_type].match(/plan_/).nil?
|
||||
end
|
||||
|
||||
def plan_type
|
||||
return 'free' if values[:plan_type].nil?
|
||||
return 'supporter' if values[:plan_type].match /^plan_/
|
||||
values[:plan_type]
|
||||
end
|
||||
|
||||
|
|
|
@ -67,9 +67,19 @@
|
|||
<div class="col col-25 supporter">
|
||||
<div class="plan-image" data-original-title="No no, pick me!"></div>
|
||||
<h3>Supporter</h3>
|
||||
<div class="price">$<%= Site::PLAN_FEATURES[:supporter][:price] %></div>
|
||||
<div class="interval">per month, billed annually</div>
|
||||
<%== plan_pricing_button :supporter %>
|
||||
<% if parent_site && parent_site.legacy_supporter? %>
|
||||
<div class="price">$<%= Site::LEGACY_SUPPORTER_PRICES[parent_site[:plan_type].to_sym] %></div>
|
||||
<div class="interval">per month, billed annually</div>
|
||||
<% else %>
|
||||
<div class="price">$<%= Site::PLAN_FEATURES[:supporter][:price] %></div>
|
||||
<div class="interval">per month, billed annually</div>
|
||||
<% end %>
|
||||
|
||||
<% if parent_site && parent_site.legacy_supporter? %>
|
||||
<div class="current-plan">Current Plan</div>
|
||||
<% else %>
|
||||
<%== plan_pricing_button :supporter %>
|
||||
<% end %>
|
||||
<ul>
|
||||
<li><strong><%= Site::PLAN_FEATURES[:supporter][:space].to_space_pretty %></strong> storage</li>
|
||||
<li><strong><%= Site::PLAN_FEATURES[:supporter][:bandwidth].to_space_pretty %></strong> bandwidth</li>
|
||||
|
@ -131,8 +141,13 @@
|
|||
</th>
|
||||
<th class="professional">
|
||||
<h3>Supporter</h3>
|
||||
<p>$<%= Site::PLAN_FEATURES[:supporter][:price] %>/mo</p>
|
||||
<%== plan_pricing_button :supporter %>
|
||||
<% if parent_site && parent_site.legacy_supporter? %>
|
||||
<p>$<%= Site::LEGACY_SUPPORTER_PRICES[parent_site.values[:plan_type].to_sym] %>/mo</p>
|
||||
<div class="current-plan">Current Plan</div>
|
||||
<% else %>
|
||||
<p>$<%= Site::PLAN_FEATURES[:supporter][:price] %>/mo</p>
|
||||
<%== plan_pricing_button :supporter %>
|
||||
<% end %>
|
||||
</th>
|
||||
<th class="professional">
|
||||
<h3>Cat Bus</h3>
|
||||
|
|
Loading…
Add table
Reference in a new issue