mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
4ead495b45
no-issue This also mean sthe subscription will be cancelled
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
module.exports = function ({
|
|
stripe,
|
|
createMember,
|
|
getMember,
|
|
listMembers,
|
|
deleteMember
|
|
}) {
|
|
async function get(data, options) {
|
|
const member = await getMember(data, options);
|
|
if (!member) {
|
|
return member;
|
|
}
|
|
if (!stripe) {
|
|
return Object.assign(member, {
|
|
plans: []
|
|
});
|
|
}
|
|
try {
|
|
const subscription = await stripe.getSubscription(member);
|
|
if (subscription.status !== 'active') {
|
|
return Object.assign(member, {
|
|
plans: []
|
|
});
|
|
}
|
|
|
|
return Object.assign(member, {
|
|
plans: [subscription.plan]
|
|
});
|
|
} catch (err) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function destroy(data, options) {
|
|
const member = await getMember(data, options);
|
|
if (!member) {
|
|
return;
|
|
}
|
|
if (stripe) {
|
|
await stripe.removeCustomer(member);
|
|
}
|
|
return deleteMember(data, options);
|
|
}
|
|
|
|
return {
|
|
create: createMember,
|
|
list: listMembers,
|
|
get,
|
|
destroy
|
|
};
|
|
};
|