Skip to content

Commit

Permalink
Merge pull request #475 from recurly/fix-tax-min
Browse files Browse the repository at this point in the history
Fixes issue where tax exemption results in negative taxes
  • Loading branch information
bhelx authored Aug 30, 2018
2 parents b2ca580 + 5665b67 commit ec5ba94
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/util/tax-ceil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
* Ceilings the second decimal of a number without risk of
* floating point math errors
*
* - returns zero if the result is negative
*
* @param {Number} number
* @return {Number}
*/

export default function taxCeil (number) {
number = Math.max(number, 0);
return +(Math.ceil(number + 'e+2') + 'e-2');
}
39 changes: 32 additions & 7 deletions test/pricing/checkout/checkout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ describe('CheckoutPricing', function () {
});
});

beforeEach(function (done) {
subscriptionPricingFactory('tax_exempt', this.recurly, sub => {
this.subscriptionPricingExampleTaxExempt = sub;
done();
});
})

/**
* Subscriptions
*/
Expand Down Expand Up @@ -1413,13 +1420,6 @@ describe('CheckoutPricing', function () {
});

describe('given some tax exempt adjustments and subscriptions', () => {
beforeEach(function (done) {
subscriptionPricingFactory('tax_exempt', this.recurly, sub => {
this.subscriptionPricingExampleTaxExempt = sub;
done();
});
});

beforeEach(function () {
return this.pricing
.subscription(this.subscriptionPricingExampleTaxExempt) // $2 setup fee
Expand Down Expand Up @@ -1504,6 +1504,31 @@ describe('CheckoutPricing', function () {
});
});

describe('given tax exempt items and a discount', () => {
beforeEach(function () {
// Reset to eliminate the pre-defined adjustments
this.pricing = this.recurly.Pricing.Checkout();
return this.pricing
.address({ country: 'US', postalCode: '94110' })
.subscription(this.subscriptionPricingExampleTaxExempt)
.adjustment({ amount: 10, taxExempt: true })
.adjustment({ amount: 27.25, taxExempt: true })
.coupon('coop-fixed-all-5')
.reprice();
});

it('does not discount negatively', function (done) {
this.pricing
.reprice()
.then(price => {
assert.equal(price.now.taxes, 0);
assert.equal(price.now.discount, 5);
done();
})
.done();
});
});

describe('given VAT numbers on address and tax info', () => {
it('takes the VAT number from the tax info', function (done) {
sinon.spy(this.recurly, 'tax');
Expand Down
21 changes: 21 additions & 0 deletions test/server/fixtures/coupons/coop-fixed-all-5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"code": "coop-fixed-all-5",
"name": "Test coupon: $5 off all charges",
"discount": {
"type": "dollars",
"amount":
{
"USD": 5.0
}
},
"single_use": false,
"applies_for_months": null,
"duration": "forever",
"temporal_unit": null,
"temporal_amount": null,
"plans": [],
"applies_to_non_plan_charges": true,
"applies_to_plans": true,
"applies_to_all_plans": true,
"redemption_resource": "account"
}

0 comments on commit ec5ba94

Please sign in to comment.