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

Ensures addons are not included in subscriptions with quantity = 0 #895

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading