Added default description to prices

refs https://github.com/TryGhost/Team/issues/641

When default prices are created via the setup wizard, this adds a default description for Monthly and Yearly prices that mimics the values set for them currently in Portal.
This commit is contained in:
Rishabh 2021-05-09 17:36:45 +05:30
parent d00d1c2052
commit 575f85a8ca

View File

@ -143,15 +143,25 @@ export default class GhLaunchWizardSetPricingComponent extends Component {
this.args.nextStep();
}
calculateDiscount(monthly, yearly) {
if (isNaN(monthly) || isNaN(yearly)) {
return 0;
}
return monthly ? 100 - Math.floor((yearly / 12 * 100) / monthly) : 0;
}
getProduct() {
if (this.product) {
const stripePrices = this.product.stripePrices || [];
if (stripePrices.length === 0 && this.stripeMonthlyAmount && this.stripeYearlyAmount) {
const yearlyDiscount = this.calculateDiscount(this.stripeMonthlyAmount, this.stripeYearlyAmount);
stripePrices.push(
{
nickname: 'Monthly',
amount: this.stripeMonthlyAmount * 100,
active: 1,
description: 'Full Access',
currency: this.currency,
interval: 'month',
type: 'recurring'
@ -161,6 +171,7 @@ export default class GhLaunchWizardSetPricingComponent extends Component {
amount: this.stripeYearlyAmount * 100,
active: 1,
currency: this.currency,
description: yearlyDiscount > 0 ? `${yearlyDiscount}% discount` : 'Full Access',
interval: 'month',
type: 'recurring'
}