Skip to content

Commit

Permalink
Ensures addons are not included in subscriptions with qty=0
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissrogers committed Aug 26, 2024
1 parent 2a26029 commit fe66efb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/recurly/pricing/subscription/calculations.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ export default class Calculations {
let unitPrice; // Price per unit, displayed on the label
let totalPrice; // Total price for the addon

if (isTieredAddOn(addon)) {
if (this.planQuantity < 1) {
unitPrice = 0;
totalPrice = 0;
} else if (isTieredAddOn(addon)) {
const currencyCode = this.pricing.currencyCode;
totalPrice = getTieredPricingTotal(addon, selectedQuantity, currencyCode);
unitPrice = getTieredPricingUnitAmount(addon, selectedQuantity, currencyCode);
Expand Down
18 changes: 18 additions & 0 deletions test/unit/pricing/subscription/subscription.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,24 @@ describe('Recurly.Pricing.Subscription', function () {
});
});
});

describe('when the plan quantity is zero', () => {
it('calculates to zero', function (done) {
this.pricing
.plan('basic', { quantity: 0 })
.addon('snarf', { quantity: 2 })
.done(price => {
assert.equal(this.pricing.items.addons.length, 1);
assert.equal(this.pricing.items.addons[0].code, 'snarf');
assert.equal(this.pricing.items.addons[0].quantity, 2);
assert.equal(price.now.addons, '0.00');
assert.equal(price.next.addons, '0.00');
assert.equal(price.now.total, '0.00');
assert.equal(price.next.total, '0.00');
done();
});
});
});
});

describe('with usage addons', () => {
Expand Down

0 comments on commit fe66efb

Please sign in to comment.