Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#40 - ignore non zero included price quantities #41

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

phillipn
Copy link
Contributor

@phillipn phillipn commented Aug 21, 2023

Would love to add a spec, but it is not possible to test this class in this repo alone. I decided to run some local tests in the CF repo to make sure this change did as it is supposed to.

[6][12:29:12](deve)> Workspace.find(3).team.current_billing_subscription.included_prices.first.update(quantity: 0)
=> true

[7][12:29:14](deve)> Billing::Usage::ProductCatalog.new(Workspace.find(3)).current_products
=> [#<Billing::Product:0x000000012cacdd70 @attributes={:id=>"free", :_=>nil}>]

[8][12:29:18](deve)> Workspace.find(3).team.current_billing_subscription.included_prices.first.update(quantity: nil)
=> true

[9][12:29:19](deve)> Billing::Usage::ProductCatalog.new(Workspace.find(3)).current_products
=> [#<Billing::Product:0x000000012cacdd70 @attributes={:id=>"free", :_=>nil}>]

[10][12:30:22](deve)> Workspace.find(3).team.current_billing_subscription.included_prices.first.update(quantity: 1)
=> true

[11][12:30:23](deve)> Billing::Usage::ProductCatalog.new(Workspace.find(3)).current_products
=> [#<Billing::Product:0x000000012cac4950 @attributes={:id=>"2ccx", :name=>"2CCX", :prices=>{"2ccx"=>{"amount"=>nil, "currency"=>nil, "duration"=>nil, "interval"=>nil, "trial_days"=>nil, "vip_program"=>true}}, :limits=>{"workspaces"=>{"have"=>{"count"=>10, "enforcement"=>"hard"}}}, :features=>{"classic_upgrade"=>true}}>]

closes #40

@phillipn phillipn requested a review from jagthedrummer August 21, 2023 17:15
@phillipn phillipn self-assigned this Aug 21, 2023
.billing_subscriptions
.active
.flat_map(&:included_prices)
.select{ |included_price| included_price.quantity && included_price.quantity > 0 }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have added a scope, but I am worried about repos like CF that have already cloned the starter repo. I.e. if I were to deploy a new scope, and upgrade CF, everything would break because we override the IncludedPrice model, and there would be no scope definition in there.

@@ -8,7 +8,7 @@ def self.all_products
end

def current_products
products = parent.team.billing_subscriptions.active.map(&:included_prices).flatten.map(&:price).map(&:product)
products = non_zero_included_prices.map(&:price).compact.map(&:product).compact
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these compacts to prevent breakages in the event of a dev or someone removing a product or price from the products.yml

.billing_subscriptions
.active
.flat_map(&:included_prices)
.select { |included_price| included_price.quantity && included_price.quantity > 0 }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have added a scope, but I am worried about repos like CF that have already cloned the starter repo. I.e. if I were to deploy a new scope, and upgrade CF, everything would break because we override the IncludedPrice model, and there would be no scope definition in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Billing::Usage::ProductCatalog - Account For Quantity of IncludedPrice
1 participant