diff --git a/lib/recurly/pricing/checkout/calculations.js b/lib/recurly/pricing/checkout/calculations.js index 3a3494809..61725a955 100644 --- a/lib/recurly/pricing/checkout/calculations.js +++ b/lib/recurly/pricing/checkout/calculations.js @@ -149,9 +149,7 @@ export default class Calculations { this.price.next.discount = discountNext; } - return promise.then(() => { - if (coupon.single_use) this.price.next.discount = 0; - }); + return promise; } /** @@ -329,6 +327,7 @@ export default class Calculations { * * @return {Object} { discountNow, discountNext } */ + discountAmounts () { const coupon = this.items.coupon; let discountNow = 0; @@ -339,13 +338,18 @@ export default class Calculations { } else if (coupon.discount.rate) { const { discountableNow, discountableNext } = this.discountableSubtotals(coupon, { setupFees: false }); discountNow = roundForDiscount(discountableNow * coupon.discount.rate); - discountNext = roundForDiscount(discountableNext * coupon.discount.rate); + // If coupon is single use, we want discountNext to be zero + if (!coupon.single_use) { + discountNext = roundForDiscount(discountableNext * coupon.discount.rate); + } } else if (coupon.discount.amount) { const { discountableNow, discountableNext } = this.discountableSubtotals(coupon); // Falls back to zero if the coupon does not support the checkout currency const discountAmount = coupon.discount.amount[this.items.currency] || 0; discountNow = Math.min(discountableNow, discountAmount); - discountNext = Math.min(discountableNext, discountAmount); + if (!coupon.single_use) { + discountNext = Math.min(discountableNext, discountAmount); + } } } return { discountNow, discountNext }; diff --git a/test/unit/pricing/checkout/checkout.test.js b/test/unit/pricing/checkout/checkout.test.js index ed3f7cf17..e975eac1d 100644 --- a/test/unit/pricing/checkout/checkout.test.js +++ b/test/unit/pricing/checkout/checkout.test.js @@ -1765,6 +1765,19 @@ describe('CheckoutPricing', function () { done(); }); }); + + describe('is single-use and applies to subscriptions and adjustments with taxes', () => { + beforeEach(applyCoupon('coop-single-use')); + + it('discounts only the subscriptions now, and applies no discounts next cycle', function () { + assert.equal(this.price.now.subtotal, 41.99); // 19.99 + 2 (setup fee) + 20 (adj) + 20 (adj) - $20 discount + assert.equal(this.price.now.discount, 20); + assert.equal(this.price.next.subscriptions, 19.99); + assert.equal(this.price.next.discount, 0); + assert.equal(this.price.now.taxes, 3.67); + assert.equal(this.price.next.taxes, 1.75); + }); + }); }); });