Ghost/ghost/admin/app/components/gh-member-settings-form.js
Rishabh Garg 2edb7226e1 Added past_due and unpaid subscriptions for members (#1740)
refs https://github.com/TryGhost/Ghost/issues/12256, https://github.com/TryGhost/Ghost/issues/12255

Currently when listing subscriptions for Members in both the Admin and the Theme, we only show the subscriptions which have a status of trialing or active.

Based on discussion, the `unpaid` and `past_due` states on Stripe also represent owner's intention of considering a subscription as active instead of `cancelled`, so we allow any subscriptions under these 2 states to be also listed for a member and consider them as `paid`. This updates Admin to consider those subscriptions as active as well.

- Subscriptions will go into a past_due state if the payment is missed, this should be considered a grace period where the member still has access.

- After this the subscriptions will either go to the unpaid or the cancelled state - this can be configured on an account by account basis in the Stripe dashboard. `unpaid` is considered as an intention to keep the subscription to allow for re-activation later.
2020-10-27 15:27:31 +05:30

87 lines
2.9 KiB
JavaScript

import Component from '@ember/component';
import moment from 'moment';
import {computed} from '@ember/object';
import {gt} from '@ember/object/computed';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
export default Component.extend({
membersUtils: service(),
feature: service(),
config: service(),
mediaQueries: service(),
ghostPaths: service(),
ajax: service(),
store: service(),
// Allowed actions
setProperty: () => {},
hasMultipleSubscriptions: gt('member.stripe', 1),
canShowStripeInfo: computed('member.isNew', 'membersUtils.isStripeEnabled', function () {
let stripeEnabled = this.membersUtils.isStripeEnabled;
if (this.member.get('isNew') || !stripeEnabled) {
return false;
} else {
return true;
}
}),
subscriptions: computed('member.stripe', function () {
let subscriptions = this.member.get('stripe');
if (subscriptions && subscriptions.length > 0) {
return subscriptions.map((subscription) => {
const statusLabel = subscription.status === 'past_due' ? 'Past due' : subscription.status;
return {
id: subscription.id,
customer: subscription.customer,
name: subscription.name || '',
email: subscription.email || '',
status: subscription.status,
statusLabel: statusLabel,
startDate: subscription.start_date ? moment(subscription.start_date).format('D MMM YYYY') : '-',
plan: subscription.plan,
amount: parseInt(subscription.plan.amount) ? (subscription.plan.amount / 100) : 0,
cancelAtPeriodEnd: subscription.cancel_at_period_end,
validUntil: subscription.current_period_end ? moment(subscription.current_period_end).format('D MMM YYYY') : '-'
};
}).reverse();
}
return null;
}),
actions: {
setProperty(property, value) {
this.setProperty(property, value);
}
},
cancelSubscription: task(function* (subscriptionId) {
let url = this.get('ghostPaths.url').api('members', this.member.get('id'), 'subscriptions', subscriptionId);
let response = yield this.ajax.put(url, {
data: {
cancel_at_period_end: true
}
});
this.store.pushPayload('member', response);
return response;
}).drop(),
continueSubscription: task(function* (subscriptionId) {
let url = this.get('ghostPaths.url').api('members', this.member.get('id'), 'subscriptions', subscriptionId);
let response = yield this.ajax.put(url, {
data: {
cancel_at_period_end: false
}
});
this.store.pushPayload('member', response);
return response;
}).drop()
});