0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-01 02:41:39 -05:00

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
This commit is contained in:
Rish 2020-05-26 20:36:10 +05:30
parent 838c440a5a
commit 5640137bd3
3 changed files with 7 additions and 6 deletions
ghost/portal/src

View file

@ -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
});

View file

@ -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});
}

View file

@ -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
})