Skip to content

Commit

Permalink
Merge pull request #888 from recurly/pricing-zero-qty-subs
Browse files Browse the repository at this point in the history
Allows subscription quantities of zero on Pricing instances
  • Loading branch information
abachman authored Jul 16, 2024
2 parents 8dce434 + d2be988 commit e8dd7e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/recurly/pricing/subscription/calculations.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ export default class Calculations {
const plan = this.items.plan;
if (!plan) return { amount: 0, setup_fee: 0 };
let price = plan.price[this.items.currency];
price.amount = price.unit_amount * (plan.quantity || 1);
let quantity = parseInt(plan.quantity, 10);
if (isNaN(quantity)) quantity = 1;
price.amount = price.unit_amount * quantity;
return price;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/recurly/pricing/subscription/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ export default class SubscriptionPricing extends Pricing {

// options.quantity, plan.quantity, 1
if (plan && plan.quantity) quantity = plan.quantity;
if (options.quantity) quantity = parseInt(options.quantity, 10);
if (!quantity || quantity < 1) quantity = 1;

if ('quantity' in options) quantity = parseInt(options.quantity, 10);
if (isNaN(quantity) || quantity < 0) quantity = 1;

return { currentPlan: plan, quantity, planCode, options, done };
}
Expand Down

0 comments on commit e8dd7e5

Please sign in to comment.