Skip to content

Commit

Permalink
Merge pull request #302 from recurly/fix-attachment-taxation
Browse files Browse the repository at this point in the history
Fixes issue with address attachment
  • Loading branch information
jayseeg authored Oct 18, 2016
2 parents b1d5b14 + eae1ced commit 59f73ad
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/recurly/pricing/attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class Attachment {
const elems = this.elements;
const target = event.target || event.srcElement;
const targetName = dom.data(target, 'recurly');
const updating = name => event === INIT_RUN || targetName === name;
const updating = name => name in elems && event === INIT_RUN || targetName === name;
const updateAddon = elems.addon && updating('addon');
const updateAddress = updating('country') || updating('postal_code');
const updateCurrency = updating('currency');
Expand Down
24 changes: 22 additions & 2 deletions test/pricing/attachment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,31 @@ describe('Recurly.Pricing.attach', function () {
it('sets the shipping address', function (done) {
assert(typeof this.pricing.items.shipping_address === 'undefined');
this.pricing.on('set.shipping_address', () => {
assert(this.pricing.items.shipping_address.country === 'US');
assert(this.pricing.items.shipping_address.postal_code === '94129');
assert.equal(this.pricing.items.shipping_address.country, 'US');
assert.equal(this.pricing.items.shipping_address.postal_code, '94129');
done();
});
});

describe('when shipping address is blank and billing address is present', function () {
this.ctx.fixtureOpts = {
plan: 'basic',
country: 'US',
postal_code: '94129',
'shipping_address.country': '',
'shipping_address.postal_code': ''
};

it('does not set the shipping address', function (done) {
assert(typeof this.pricing.items.shipping_address === 'undefined');
this.pricing.on('set.address', () => {
assert.equal(this.pricing.items.address.country, 'US');
assert.equal(this.pricing.items.address.postal_code, '94129');
assert.equal(this.pricing.items.shipping_address, undefined);
done();
});
});
})
});

describe('when pre-populated with a valid giftcard redemption code', function () {
Expand Down
4 changes: 2 additions & 2 deletions test/support/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ const pricing = opts => `
<input type="text" data-recurly="tax_code" value="${fetch(opts, 'tax_code', '')}">
<input type="text" data-recurly="vat_number" value="${fetch(opts, 'vat_number', '')}">
<input type="text" data-recurly="shipping_address.country" value="${fetch(opts, 'shipping_address.country', '')}">
<input type="text" data-recurly="shipping_address.postal_code" value="${fetch(opts, 'shipping_address.postal_code', '')}">
${opts['shipping_address.country'] ? `<input type="text" data-recurly="shipping_address.country" value="${fetch(opts, 'shipping_address.country', '')}">` : '' }
${opts['shipping_address.postal_code'] ? `<input type="text" data-recurly="shipping_address.postal_code" value="${fetch(opts, 'shipping_address.postal_code', '')}">` : '' }
<span data-recurly="total_now"></span>
<span data-recurly="subtotal_now"></span>
Expand Down

0 comments on commit 59f73ad

Please sign in to comment.