update the logic to get the number of credits for a monthly plan
This commit is contained in:
@@ -4,8 +4,6 @@ module Enterprise::Billing::Concerns::PlanProvisioningHelper
|
||||
private
|
||||
|
||||
def provision_new_plan(new_pricing_plan_id)
|
||||
sync_plan_credits(new_pricing_plan_id)
|
||||
|
||||
plan_definition = Enterprise::Billing::V2::PlanCatalog.definition_for(new_pricing_plan_id)
|
||||
return unless plan_definition
|
||||
|
||||
@@ -13,14 +11,6 @@ module Enterprise::Billing::Concerns::PlanProvisioningHelper
|
||||
enable_plan_specific_features(plan_name) if plan_name.present?
|
||||
end
|
||||
|
||||
def sync_plan_credits(pricing_plan_id)
|
||||
plan_credits = Enterprise::Billing::V2::PlanCatalog.monthly_credits_for(pricing_plan_id)
|
||||
|
||||
Enterprise::Billing::V2::CreditManagementService
|
||||
.new(account: account)
|
||||
.sync_monthly_response_credits(plan_credits.to_i)
|
||||
end
|
||||
|
||||
def extract_plan_name(plan_definition)
|
||||
plan_definition[:display_name].split.find { |word| %w[Startup Startups Business Enterprise].include?(word) }
|
||||
end
|
||||
|
||||
@@ -105,7 +105,16 @@ class Enterprise::Billing::HandleStripeEventService
|
||||
return credits.to_i if credits.present? && credits.to_i.positive?
|
||||
end
|
||||
|
||||
0
|
||||
amount = extract_attribute(grant, :amount)
|
||||
return 0 if amount.blank?
|
||||
|
||||
custom_pricing_unit = extract_attribute(amount, :custom_pricing_unit)
|
||||
return 0 if custom_pricing_unit.blank?
|
||||
|
||||
value = extract_attribute(custom_pricing_unit, :value)
|
||||
return 0 if value.blank?
|
||||
|
||||
value.to_i
|
||||
end
|
||||
|
||||
def extract_attribute(object, attribute)
|
||||
|
||||
@@ -53,11 +53,6 @@ module Enterprise::Billing::V2::PlanCatalog
|
||||
nil
|
||||
end
|
||||
|
||||
def monthly_credits_for(plan_id)
|
||||
definition = definition_for(plan_id)
|
||||
definition ? definition[:monthly_credits] : nil
|
||||
end
|
||||
|
||||
def plan_id_for(definition)
|
||||
InstallationConfig.find_by(name: definition[:config_key])&.value
|
||||
end
|
||||
|
||||
@@ -63,7 +63,9 @@ class Enterprise::Billing::V2::SubscriptionProvisioningService < Enterprise::Bil
|
||||
update_custom_attributes(attributes)
|
||||
|
||||
# Sync credits for Hacker plan (0 credits)
|
||||
sync_plan_credits(pricing_plan_id)
|
||||
Enterprise::Billing::V2::CreditManagementService
|
||||
.new(account: account)
|
||||
.sync_monthly_response_credits(0)
|
||||
|
||||
# Disable all premium features and save
|
||||
disable_all_premium_features
|
||||
|
||||
Reference in New Issue
Block a user