Skip to content

Commit

Permalink
Merge pull request #288 from recurly/fix-addon-attachment
Browse files Browse the repository at this point in the history
Fixes bug with pricing attachment of addons
  • Loading branch information
SteveDugas authored Aug 2, 2016
2 parents e665f46 + 6ca9c51 commit 51e10b0
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/recurly/pricing/attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,25 @@ export default class Attachment {
const updateCurrency = updating('currency');
const updateCoupon = elems.coupon && (updating('coupon') || updating('plan'));
const updateGiftcard = elems.gift_card && updating('gift_card');
const updatePlan = updating('plan');
const updateTax = updating('vat_number') || updating('tax_code');

let pricing = this.pricing;

if (updatePlan) {
pricing = pricing.plan(dom.value(elems.plan), { quantity: dom.value(elems.plan_quantity) });
}
let pricing = this.pricing.plan(dom.value(elems.plan), { quantity: dom.value(elems.plan_quantity) });

if (updateCurrency) {
pricing = pricing.currency(dom.value(elems.currency));
}

if (updateAddon) {
elems.addon.forEach(elem => {
const plan = this.items.plan;
const code = dom.data(elem, 'recurlyAddon');
const quantity = dom.value(elem);

if (plan.addons && find(plan.addons, { code })) {
pricing = pricing.addon(addonCode, { quantity });
}
pricing = pricing.then(() => {
elems.addon.forEach(elem => {
const plan = this.pricing.items.plan;
const code = dom.data(elem, 'recurlyAddon');
const quantity = dom.value(elem);

if (plan.addons && find(plan.addons, { code })) {
pricing = pricing.addon(code, { quantity });
}
});
});
}

Expand Down

0 comments on commit 51e10b0

Please sign in to comment.