mirror of
https://github.com/neocities/neocities.git
synced 2025-07-23 02:56:05 +02:00
track subscription ids
This commit is contained in:
parent
5235286d8a
commit
609cee1c17
6 changed files with 147 additions and 86 deletions
51
app.rb
51
app.rb
|
@ -271,30 +271,43 @@ post '/plan/update' 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 || parent_site.email),
|
||||
plan: params[:plan_type]
|
||||
)
|
||||
if parent_site.stripe_subscription_id
|
||||
customer = Stripe::Customer.retrieve parent_site.stripe_customer_id
|
||||
subscription = customer.subscriptions.retrieve parent_site.stripe_subscription_id
|
||||
subscription.plan = params[:plan_type]
|
||||
subscription.save
|
||||
|
||||
parent_site.update(
|
||||
stripe_customer_id: customer.id,
|
||||
plan_ended: false,
|
||||
plan_type: params[:plan_type]
|
||||
)
|
||||
parent_site.update(
|
||||
plan_ended: false,
|
||||
plan_type: params[:plan_type]
|
||||
)
|
||||
else
|
||||
customer = Stripe::Customer.create(
|
||||
card: params[:stripe_token],
|
||||
description: "#{parent_site.username} - #{parent_site.id}",
|
||||
email: (current_site.email || parent_site.email),
|
||||
plan: params[:plan_type]
|
||||
)
|
||||
|
||||
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: Site::PLAN_FEATURES[params[:plan_type].to_sym][:name])
|
||||
})
|
||||
parent_site.update(
|
||||
stripe_customer_id: customer.id,
|
||||
stripe_subscription_id: customer.subscriptions.first.id,
|
||||
plan_ended: false,
|
||||
plan_type: params[:plan_type]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
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: Site::PLAN_FEATURES[params[:plan_type].to_sym][:name])
|
||||
})
|
||||
end
|
||||
|
||||
redirect '/plan/thanks'
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue