diff --git a/ghost/admin/app/components/gh-launch-wizard/connect-stripe.hbs b/ghost/admin/app/components/gh-launch-wizard/connect-stripe.hbs
index 739ef0847b..5b190bb53f 100644
--- a/ghost/admin/app/components/gh-launch-wizard/connect-stripe.hbs
+++ b/ghost/admin/app/components/gh-launch-wizard/connect-stripe.hbs
@@ -102,7 +102,11 @@
@class="w-70 ml4 right gh-btn gh-btn-black gh-btn-large gh-btn-icon-right"
data-test-button="wizard-next"
>
- {{if this.settings.stripeConnectAccountId "Continue" "Save and continue"}}{{svg-jar "arrow-right-tail"}}
+ {{#if this.saveAndContinueTask.isRunning}}
+ Saving...
+ {{else}}
+ {{if this.settings.stripeConnectAccountId "Continue" "Save and continue"}}{{svg-jar "arrow-right-tail"}}
+ {{/if}}
diff --git a/ghost/admin/app/components/gh-launch-wizard/connect-stripe.js b/ghost/admin/app/components/gh-launch-wizard/connect-stripe.js
index 6d394ebe83..0151786024 100644
--- a/ghost/admin/app/components/gh-launch-wizard/connect-stripe.js
+++ b/ghost/admin/app/components/gh-launch-wizard/connect-stripe.js
@@ -10,6 +10,7 @@ export default class GhLaunchWizardConnectStripeComponent extends Component {
@service config;
@service ghostPaths;
@service settings;
+ @service store;
@tracked hasActiveStripeSubscriptions = false;
@tracked showDisconnectStripeConnectModal = false;
@@ -59,6 +60,34 @@ export default class GhLaunchWizardConnectStripeComponent extends Component {
this.stripeConnectError = null;
}
+ calculateDiscount(monthly, yearly) {
+ if (isNaN(monthly) || isNaN(yearly)) {
+ return 0;
+ }
+
+ return monthly ? 100 - Math.floor((yearly / 12 * 100) / monthly) : 0;
+ }
+
+ getActivePrice(prices, interval, amount, currency) {
+ return prices.find((price) => {
+ return (
+ price.active && price.amount === amount && price.type === 'recurring' &&
+ price.interval === interval && price.currency.toLowerCase() === currency.toLowerCase()
+ );
+ });
+ }
+
+ updatePortalPlans(monthlyPriceId, yearlyPriceId) {
+ let portalPlans = ['free'];
+ if (monthlyPriceId) {
+ portalPlans.push(monthlyPriceId);
+ }
+ if (yearlyPriceId) {
+ portalPlans.push(yearlyPriceId);
+ }
+ this.settings.set('portalPlans', portalPlans);
+ }
+
@task({drop: true})
*openDisconnectStripeConnectModalTask() {
this.hasActiveStripeSubscriptions = false;
@@ -114,6 +143,43 @@ export default class GhLaunchWizardConnectStripeComponent extends Component {
try {
yield this.settings.save();
+
+ const products = yield this.store.query('product', {include: 'stripe_prices'});
+ this.product = products.firstObject;
+ if (this.product) {
+ const stripePrices = this.product.stripePrices || [];
+ const yearlyDiscount = this.calculateDiscount(5, 50);
+ stripePrices.push(
+ {
+ nickname: 'Monthly',
+ amount: 500,
+ active: 1,
+ description: 'Full access',
+ currency: 'usd',
+ interval: 'month',
+ type: 'recurring'
+ },
+ {
+ nickname: 'Yearly',
+ amount: 5000,
+ active: 1,
+ currency: 'usd',
+ description: yearlyDiscount > 0 ? `${yearlyDiscount}% discount` : 'Full access',
+ interval: 'year',
+ type: 'recurring'
+ }
+ );
+ this.product.set('stripePrices', stripePrices);
+ yield timeout(1000);
+ const updatedProduct = yield this.product.save();
+ const monthlyPrice = this.getActivePrice(updatedProduct.stripePrices, 'month', 500, 'usd');
+ const yearlyPrice = this.getActivePrice(updatedProduct.stripePrices, 'year', 5000, 'usd');
+ this.updatePortalPlans(monthlyPrice.id, yearlyPrice.id);
+ this.settings.set('membersMonthlyPriceId', monthlyPrice.id);
+ this.settings.set('membersYearlyPriceId', yearlyPrice.id);
+ yield this.settings.save();
+ }
+
this.pauseAndContinueTask.perform();
return true;
} catch (error) {