From 748f56ee4780e7d5cc6934a4661acdf4c578eb51 Mon Sep 17 00:00:00 2001 From: Rish Date: Fri, 8 May 2020 23:00:32 +0530 Subject: [PATCH] Added update plan setup for paid members refs https://github.com/TryGhost/members.js/issues/20 - Adds update plan action for paid members to allow switching plans --- ghost/portal/src/components/ParentContainer.js | 5 +++++ ghost/portal/src/components/pages/AccountPlanPage.js | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ghost/portal/src/components/ParentContainer.js b/ghost/portal/src/components/ParentContainer.js index 3bf2a7ceec..a535d9bced 100644 --- a/ghost/portal/src/components/ParentContainer.js +++ b/ghost/portal/src/components/ParentContainer.js @@ -171,6 +171,11 @@ export default class ParentContainer extends React.Component { await this.GhostApi.member.checkoutPlan({ plan }); + } else if (action === 'updatePlan') { + const {plan, subscriptionId} = data; + await this.GhostApi.member.updateSubscription({ + plan, subscriptionId + }); } else if (action === 'editBilling') { await this.GhostApi.member.editBilling(); } diff --git a/ghost/portal/src/components/pages/AccountPlanPage.js b/ghost/portal/src/components/pages/AccountPlanPage.js index b0e63d56b2..faf52d9299 100644 --- a/ghost/portal/src/components/pages/AccountPlanPage.js +++ b/ghost/portal/src/components/pages/AccountPlanPage.js @@ -34,9 +34,15 @@ export default class AccountPlanPage extends React.Component { onPlanCheckout(e) { e.preventDefault(); - const {onAction} = this.context; + const {onAction, member} = this.context; const plan = this.state.plan; - onAction('checkoutPlan', {plan}); + if (member.paid) { + const {subscriptions} = member; + const subscriptionId = subscriptions[0].id; + onAction('updatePlan', {plan, subscriptionId}); + } else { + onAction('checkoutPlan', {plan}); + } } onPlanSelect(e, name) {