Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tiered Unit Pricing Labels #790

Merged
merged 4 commits into from
Feb 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor on subscription calculation
  • Loading branch information
douglaslise committed Feb 22, 2023
commit 6e8fab7a31e94825fd2a4ed470cd332bf524e895
30 changes: 13 additions & 17 deletions lib/recurly/pricing/subscription/calculations.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,25 @@ export default class Calculations {
// exclude usage addons
if (addon.add_on_type !== 'fixed') return;

const selectedQuantity = find(this.items.addons, { code: addon.code })?.quantity;
const selectedQuantity = find(this.items.addons, { code: addon.code })?.quantity || 0;

let unitPrice; // Price per unit, displayed on the label
let totalPrice; // Total price for the addon

let price;
if (isTieredAddOn(addon)) {
price = getTieredPricingUnitAmount(addon, selectedQuantity, this.price.currency.code);
const currencyCode = this.pricing.currencyCode;
totalPrice = getTieredPricingTotal(addon, selectedQuantity, currencyCode);
unitPrice = getTieredPricingUnitAmount(addon, selectedQuantity, currencyCode);
} else {
price = addon.price[this.items.currency].unit_amount;
unitPrice = addon.price[this.items.currency].unit_amount;
totalPrice = unitPrice * selectedQuantity;
}
this.price.base.addons[addon.code] = price;

this.price.addons[addon.code] = price; // DEPRECATED
this.price.base.addons[addon.code] = unitPrice;
this.price.addons[addon.code] = totalPrice; // DEPRECATED

if (selectedQuantity) {
if (isTieredAddOn(addon)) {
const currencyCode = this.pricing.currencyCode;
price = getTieredPricingTotal(addon, selectedQuantity, currencyCode);
} else {
price = price * selectedQuantity;
}

if (!this.isTrial()) this.price.now.addons += price;
this.price.next.addons += price;
}
if (!this.isTrial()) this.price.now.addons += totalPrice;
this.price.next.addons += totalPrice;
});
}

Expand Down