Skip to content

Commit

Permalink
Allows subscription quantities of zero on Pricing instances
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissrogers committed Jul 16, 2024
1 parent dbe1dbc commit 6eaaffd
Show file tree
Hide file tree
Showing 2 changed files with 7 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 = plan.quantity;
if (typeof quantity !== 'number') quantity = 1;
price.amount = price.unit_amount * quantity;
return price;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/recurly/pricing/subscription/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,10 @@ 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 (typeof Number(options.quantity) === 'number') quantity = parseInt(options.quantity, 10);
if (typeof quantity !== 'number' || quantity < 0) quantity = 1;

console.log('resolvePlanOptions', { options, quantity })

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

0 comments on commit 6eaaffd

Please sign in to comment.