mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 05:42:32 +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);
|
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} */
|
/** @type {number|null} */
|
||||||
#monthlyPrice;
|
#monthlyPrice;
|
||||||
get monthlyPrice() {
|
get monthlyPrice() {
|
||||||
@ -134,7 +149,7 @@ module.exports = class Tier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updatePricing({currency, monthlyPrice, yearlyPrice}) {
|
updatePricing({currency, monthlyPrice, yearlyPrice}) {
|
||||||
if (this.#type !== 'paid') {
|
if (this.#type !== 'paid' && (currency || monthlyPrice || yearlyPrice)) {
|
||||||
throw new ValidationError({
|
throw new ValidationError({
|
||||||
message: 'Cannot set pricing for free tiers'
|
message: 'Cannot set pricing for free tiers'
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user