feat: Enable features on successful subscription (#6953)
* feat: Enable features on successful subscription * fix: Add specs * disable features for default plan * Remove mark as cloud customers --------- Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -27,6 +27,7 @@ class Enterprise::Billing::HandleStripeEventService
|
||||
subscribed_quantity: subscription['quantity']
|
||||
}
|
||||
)
|
||||
change_plan_features
|
||||
end
|
||||
|
||||
def process_subscription_deleted
|
||||
@@ -36,10 +37,23 @@ class Enterprise::Billing::HandleStripeEventService
|
||||
Enterprise::Billing::CreateStripeCustomerService.new(account: account).perform
|
||||
end
|
||||
|
||||
def change_plan_features
|
||||
if default_plan?
|
||||
account.disable_features(*features_to_update)
|
||||
else
|
||||
account.enable_features(*features_to_update)
|
||||
end
|
||||
account.save!
|
||||
end
|
||||
|
||||
def ensure_event_context(event)
|
||||
@event = event
|
||||
end
|
||||
|
||||
def features_to_update
|
||||
%w[help_center campaigns team_management channel_twitter channel_facebook channel_email]
|
||||
end
|
||||
|
||||
def subscription
|
||||
@subscription ||= @event.data.object
|
||||
end
|
||||
@@ -52,4 +66,10 @@ class Enterprise::Billing::HandleStripeEventService
|
||||
installation_config = InstallationConfig.find_by(name: 'CHATWOOT_CLOUD_PLANS')
|
||||
installation_config.value.find { |config| config['product_id'].include?(plan_id) }
|
||||
end
|
||||
|
||||
def default_plan?
|
||||
installation_config = InstallationConfig.find_by(name: 'CHATWOOT_CLOUD_PLANS')
|
||||
default_plan = installation_config.value.first
|
||||
@account.custom_attributes['plan_name'] == default_plan['name']
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user