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

Add Support for Tiered Pricing Plans #629

Open
wants to merge 14 commits into
base: original
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix Django Compatability Issues
  • Loading branch information
jksimoniii committed Feb 1, 2019
commit 0a75829f3bea57611141a80dbd1a3ff5397e2091
14 changes: 8 additions & 6 deletions pinax/stripe/actions/plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def sync_plan(plan, event=None):

if plan["tiers"]:
obj.tiers.all().delete() # delete all tiers, since they don't have ids in Stripe
obj.tiers.set([models.Tier(
plan=obj,
amount=utils.convert_amount_for_db(tier["amount"], plan["currency"]),
flat_amount=utils.convert_amount_for_db(tier["flat_amount"], plan["currency"]),
up_to=tier["up_to"]
) for tier in plan["tiers"]], bulk=False)
for tier in plan["tiers"]:
tier_obj = models.Tier.objects.create(
plan=obj,
amount=utils.convert_amount_for_db(tier["amount"], plan["currency"]),
flat_amount=utils.convert_amount_for_db(tier["flat_amount"], plan["currency"]),
up_to=tier["up_to"]
)
obj.tiers.add(tier_obj)
2 changes: 1 addition & 1 deletion pinax/stripe/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def calculate_final_cost(self, plan, quantity, mode):
all_tiers = self.all_tiers(plan)

if mode == self.TIERS_MODE_VOLUME:
applicable_tiers = filter(lambda t: quantity <= t.up_to, all_tiers)
applicable_tiers = list(filter(lambda t: not t.up_to or quantity <= t.up_to, all_tiers))
tier = applicable_tiers[0] if applicable_tiers else all_tiers[-1]
cost = tier.calculate_cost(quantity)
elif mode == self.TIERS_MODE_GRADUATED:
Expand Down