Chore: Remove dead code related to billing (#935)
- remove subscription model - remove billing-related code
This commit is contained in:
@@ -46,13 +46,11 @@ class Account < ApplicationRecord
|
||||
has_many :canned_responses, dependent: :destroy
|
||||
has_many :webhooks, dependent: :destroy
|
||||
has_many :labels, dependent: :destroy
|
||||
has_one :subscription, dependent: :destroy
|
||||
has_many :notification_settings, dependent: :destroy
|
||||
has_flags ACCOUNT_SETTINGS_FLAGS.merge(column: 'settings_flags').merge(DEFAULT_QUERY_SETTING)
|
||||
|
||||
enum locale: LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_1_code], key] }.to_h
|
||||
|
||||
after_create :create_subscription
|
||||
after_create :notify_creation
|
||||
after_destroy :notify_deletion
|
||||
|
||||
@@ -74,22 +72,6 @@ class Account < ApplicationRecord
|
||||
.map { |_| _.tag.name }
|
||||
end
|
||||
|
||||
def subscription_data
|
||||
agents_count = users.count
|
||||
per_agent_price = Plan.paid_plan.price
|
||||
{
|
||||
state: subscription.state,
|
||||
expiry: subscription.expiry.to_i,
|
||||
agents_count: agents_count,
|
||||
per_agent_cost: per_agent_price,
|
||||
total_cost: (per_agent_price * agents_count),
|
||||
iframe_url: Subscription::ChargebeeService.hosted_page_url(self),
|
||||
trial_expired: subscription.trial_expired?,
|
||||
account_suspended: subscription.suspended?,
|
||||
payment_source_added: subscription.payment_source_added
|
||||
}
|
||||
end
|
||||
|
||||
def webhook_data
|
||||
{
|
||||
id: id,
|
||||
@@ -99,11 +81,6 @@ class Account < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def create_subscription
|
||||
subscription = build_subscription
|
||||
subscription.save
|
||||
end
|
||||
|
||||
def notify_creation
|
||||
Rails.configuration.dispatcher.dispatch(ACCOUNT_CREATED, Time.zone.now, account: self)
|
||||
end
|
||||
|
||||
@@ -2,16 +2,15 @@
|
||||
#
|
||||
# Table name: channel_web_widgets
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# agent_away_message :string
|
||||
# website_token :string
|
||||
# website_url :string
|
||||
# welcome_tagline :string
|
||||
# welcome_title :string
|
||||
# widget_color :string default("#1f93ff")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :integer
|
||||
# id :integer not null, primary key
|
||||
# website_token :string
|
||||
# website_url :string
|
||||
# welcome_tagline :string
|
||||
# welcome_title :string
|
||||
# widget_color :string default("#1f93ff")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :integer
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: subscriptions
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# billing_plan :string default("trial")
|
||||
# expiry :datetime
|
||||
# payment_source_added :boolean default(FALSE)
|
||||
# pricing_version :string
|
||||
# state :integer default("trial")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :integer
|
||||
# stripe_customer_id :string
|
||||
#
|
||||
|
||||
class Subscription < ApplicationRecord
|
||||
include Events::Types
|
||||
|
||||
belongs_to :account
|
||||
before_create :set_default_billing_params
|
||||
after_create :notify_creation
|
||||
|
||||
enum state: [:trial, :active, :cancelled]
|
||||
|
||||
def payment_source_added!
|
||||
self.payment_source_added = true
|
||||
save
|
||||
end
|
||||
|
||||
def trial_expired?
|
||||
(trial? && expiry < Date.current) ||
|
||||
(cancelled? && !payment_source_added)
|
||||
end
|
||||
|
||||
def suspended?
|
||||
cancelled? && payment_source_added
|
||||
end
|
||||
|
||||
def summary
|
||||
{
|
||||
state: state,
|
||||
expiry: expiry.to_i
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_default_billing_params
|
||||
self.expiry = Time.now + Plan.default_trial_period
|
||||
self.pricing_version = Plan.default_pricing_version
|
||||
end
|
||||
|
||||
def notify_creation
|
||||
Rails.configuration.dispatcher.dispatch(SUBSCRIPTION_CREATED, Time.zone.now, subscription: self)
|
||||
end
|
||||
end
|
||||
@@ -118,7 +118,6 @@ class User < ApplicationRecord
|
||||
|
||||
def serializable_hash(options = nil)
|
||||
serialized_user = super(options).merge(confirmed: confirmed?)
|
||||
serialized_user.merge(subscription: account.try(:subscription).try(:summary)) if ENV['BILLING_ENABLED']
|
||||
serialized_user
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user