mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added support for canceling subscriptions (#13039)
refs https://github.com/TryGhost/Team/issues/775 As we currently do not delete canceled subscriptions and they are exposed via the API, this functionality has been added to the editSubscription controller method under the PUT HTTP method. The cancelSubscription method in @tryghost/members-api was updated to handle deleting by member id
This commit is contained in:
parent
526993965a
commit
8ea577b58b
3 changed files with 26 additions and 13 deletions
|
@ -229,7 +229,8 @@ module.exports = {
|
||||||
'subscription_id'
|
'subscription_id'
|
||||||
],
|
],
|
||||||
data: [
|
data: [
|
||||||
'cancel_at_period_end'
|
'cancel_at_period_end',
|
||||||
|
'status'
|
||||||
],
|
],
|
||||||
validation: {
|
validation: {
|
||||||
options: {
|
options: {
|
||||||
|
@ -243,6 +244,9 @@ module.exports = {
|
||||||
data: {
|
data: {
|
||||||
cancel_at_period_end: {
|
cancel_at_period_end: {
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
values: ['canceled']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -250,13 +254,22 @@ module.exports = {
|
||||||
method: 'edit'
|
method: 'edit'
|
||||||
},
|
},
|
||||||
async query(frame) {
|
async query(frame) {
|
||||||
await membersService.api.members.updateSubscription({
|
if (frame.data.status === 'canceled') {
|
||||||
id: frame.options.id,
|
await membersService.api.members.cancelSubscription({
|
||||||
subscription: {
|
id: frame.options.id,
|
||||||
subscription_id: frame.options.subscription_id,
|
subscription: {
|
||||||
cancel_at_period_end: frame.data.cancel_at_period_end
|
subscription_id: frame.options.subscription_id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
await membersService.api.members.updateSubscription({
|
||||||
|
id: frame.options.id,
|
||||||
|
subscription: {
|
||||||
|
subscription_id: frame.options.subscription_id,
|
||||||
|
cancel_at_period_end: frame.data.cancel_at_period_end
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
let model = await membersService.api.members.get({id: frame.options.id}, {
|
let model = await membersService.api.members.get({id: frame.options.id}, {
|
||||||
withRelated: ['labels', 'products', 'stripeSubscriptions', 'stripeSubscriptions.customer', 'stripeSubscriptions.stripePrice', 'stripeSubscriptions.stripePrice.stripeProduct']
|
withRelated: ['labels', 'products', 'stripeSubscriptions', 'stripeSubscriptions.customer', 'stripeSubscriptions.stripePrice', 'stripeSubscriptions.stripePrice.stripeProduct']
|
||||||
});
|
});
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
"@tryghost/limit-service": "0.6.1",
|
"@tryghost/limit-service": "0.6.1",
|
||||||
"@tryghost/logging": "0.1.0",
|
"@tryghost/logging": "0.1.0",
|
||||||
"@tryghost/magic-link": "1.0.3",
|
"@tryghost/magic-link": "1.0.3",
|
||||||
"@tryghost/members-api": "1.13.1",
|
"@tryghost/members-api": "1.14.0",
|
||||||
"@tryghost/members-csv": "1.0.1",
|
"@tryghost/members-csv": "1.0.1",
|
||||||
"@tryghost/members-ssr": "1.0.3",
|
"@tryghost/members-ssr": "1.0.3",
|
||||||
"@tryghost/mw-session-from-token": "0.1.21",
|
"@tryghost/mw-session-from-token": "0.1.21",
|
||||||
|
|
|
@ -880,10 +880,10 @@
|
||||||
jsonwebtoken "^8.5.1"
|
jsonwebtoken "^8.5.1"
|
||||||
lodash "^4.17.15"
|
lodash "^4.17.15"
|
||||||
|
|
||||||
"@tryghost/members-api@1.13.1":
|
"@tryghost/members-api@1.14.0":
|
||||||
version "1.13.1"
|
version "1.14.0"
|
||||||
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-1.13.1.tgz#534478c89bcfa8bc75c7f8726651164ba9d7ea4b"
|
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-1.14.0.tgz#83fa4d3a10194f8980bc3d187d97bf13bf37d94f"
|
||||||
integrity sha512-qUjfMXotdRAiHPorx0omt3wUIv/cUl21z1Wy0SMJimBLRpaencruU7mBuicwA53P4uoV6vzbQFgy8Ce9hLm6Ig==
|
integrity sha512-10tQMkkdXkVECKN7ruoCKUn9Z+DhjKXNiamDs66ltSAuLgumwci8OX3gcSN5JB9v8mdCA54N8KtcZqmLkg+QYA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@tryghost/errors" "^0.2.9"
|
"@tryghost/errors" "^0.2.9"
|
||||||
"@tryghost/magic-link" "^1.0.3"
|
"@tryghost/magic-link" "^1.0.3"
|
||||||
|
|
Loading…
Add table
Reference in a new issue