From 5640137bd331529843a3d08ae4f7adab519cf465 Mon Sep 17 00:00:00 2001 From: Rish Date: Tue, 26 May 2020 20:36:10 +0530 Subject: [PATCH] Renamed update plan action to update subscription no issue - Renames update plan action to update subscription as it can be also used to cancel current subscription - Pass cancelAtPeriodEnd option to update subscription API call --- ghost/portal/src/components/ParentContainer.js | 8 ++++---- ghost/portal/src/components/pages/AccountPlanPage.js | 2 +- ghost/portal/src/utils/api.js | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ghost/portal/src/components/ParentContainer.js b/ghost/portal/src/components/ParentContainer.js index 4e0c986ee7..92ab3a4b3c 100644 --- a/ghost/portal/src/components/ParentContainer.js +++ b/ghost/portal/src/components/ParentContainer.js @@ -171,14 +171,14 @@ export default class ParentContainer extends React.Component { await this.GhostApi.member.checkoutPlan({ plan }); - } else if (action === 'updatePlan') { - const {plan, subscriptionId} = data; + } else if (action === 'updateSubscription') { + const {plan, subscriptionId, cancelAtPeriodEnd} = data; await this.GhostApi.member.updateSubscription({ - planName: plan, subscriptionId + planName: plan, subscriptionId, cancelAtPeriodEnd }); const member = await this.GhostApi.member.sessionData(); this.setState({ - action: 'updatePlan:success', + action: 'updateSubscription:success', page: 'accountHome', member: member }); diff --git a/ghost/portal/src/components/pages/AccountPlanPage.js b/ghost/portal/src/components/pages/AccountPlanPage.js index 7edf7e9369..0d884c38de 100644 --- a/ghost/portal/src/components/pages/AccountPlanPage.js +++ b/ghost/portal/src/components/pages/AccountPlanPage.js @@ -41,7 +41,7 @@ export default class AccountPlanPage extends React.Component { if (member.paid) { const {subscriptions} = member; const subscriptionId = subscriptions[0].id; - onAction('updatePlan', {plan, subscriptionId}); + onAction('updateSubscription', {plan, subscriptionId}); } else { onAction('checkoutPlan', {plan}); } diff --git a/ghost/portal/src/utils/api.js b/ghost/portal/src/utils/api.js index 7462e05c88..df4bb99960 100644 --- a/ghost/portal/src/utils/api.js +++ b/ghost/portal/src/utils/api.js @@ -197,7 +197,7 @@ function setupGhostApi() { throw err; }); }, - async updateSubscription({subscriptionId, planName}) { + async updateSubscription({subscriptionId, planName, cancelAtPeriodEnd}) { const identity = await api.member.identity(); const url = endpointFor({type: 'members', resource: 'subscriptions'}) + subscriptionId + '/'; return makeRequest({ @@ -207,6 +207,7 @@ function setupGhostApi() { 'Content-Type': 'application/json' }, body: JSON.stringify({ + cancel_at_period_end: cancelAtPeriodEnd, identity: identity, planName })