diff --git a/index.js b/index.js index 5e71ade..765da40 100644 --- a/index.js +++ b/index.js @@ -32,13 +32,17 @@ function totalDueNow(orderItem) { return orderItem.total; } else { var quantity = orderItem.quantity || 0, - total = orderItem.priceInCents; + total = orderItem.priceInCents; if (orderItem.variation) { total += orderItem.variation.priceInCents || 0; } if (orderItem.coupon) { + if (orderItem.purchasableType === 'bundle' && quantity > 1) { + total = total * quantity; + quantity = 1; + } total = Math.round(discountable(total, orderItem.coupon.percentOff, orderItem.coupon.amountOffInCents)); } diff --git a/package.json b/package.json index 6da9a64..4c895a1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "couponable", "description": "Helper functions for dealing with coupons.", - "version": "6.0.0", + "version": "6.0.1", "author": "Chris McC", "license": "MIT", "repository": { diff --git a/test.js b/test.js index c5111b8..95e61ec 100644 --- a/test.js +++ b/test.js @@ -30,6 +30,15 @@ describe('totalDueNow', function() { priceInCents: 2 }), 1); }); + + it('handles coupons for bundles correctly', function() { + assert.equal(totalDueNow({ + quantity: 10, + coupon: {amountOffInCents: 5}, + priceInCents: 10, + purchasableType: 'bundle' + }), 95) + }); }); describe('totalRecurring', function() {