mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 13:22:39 +03:00
Improved price data access and setting for Tier
refs https://github.com/TryGhost/Team/issues/2078 We want to be able to easily get the price for a Tier based on the cadence for use when creating Stripe Prices. We also want to be able to set the pricing data to `null` for free Tiers, rather than erroring.
This commit is contained in:
parent
68f1df545c
commit
253c30c37a
@ -115,6 +115,21 @@ module.exports = class Tier {
|
||||
this.#currency = validateCurrency(value, this.#type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {'month'|'year'} cadence
|
||||
*/
|
||||
getPrice(cadence) {
|
||||
if (cadence === 'month') {
|
||||
return this.monthlyPrice;
|
||||
}
|
||||
if (cadence === 'year') {
|
||||
return this.yearlyPrice;
|
||||
}
|
||||
throw new ValidationError({
|
||||
message: 'Invalid cadence'
|
||||
});
|
||||
}
|
||||
|
||||
/** @type {number|null} */
|
||||
#monthlyPrice;
|
||||
get monthlyPrice() {
|
||||
@ -134,7 +149,7 @@ module.exports = class Tier {
|
||||
}
|
||||
|
||||
updatePricing({currency, monthlyPrice, yearlyPrice}) {
|
||||
if (this.#type !== 'paid') {
|
||||
if (this.#type !== 'paid' && (currency || monthlyPrice || yearlyPrice)) {
|
||||
throw new ValidationError({
|
||||
message: 'Cannot set pricing for free tiers'
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user