Added ability to link member to existing stripe customer (#120)

refs https://github.com/TryGhost/Ghost/pull/11539

- Method needed to allow linking existing Stripe customers and subscriptions with members
This commit is contained in:
Naz Gargol 2020-01-28 19:00:28 +07:00 committed by GitHub
parent cf0d52c2da
commit 96aea55270
2 changed files with 22 additions and 1 deletions

View File

@ -121,6 +121,20 @@ module.exports = class StripePaymentProcessor {
};
}
async linkStripeCustomer(id, member) {
const customer = await retrieve(this._stripe, 'customers', id);
await this._updateCustomer(member, customer);
if (customer.subscriptions && customer.subscriptions.data) {
for (const subscription of customer.subscriptions.data) {
await this._updateSubscription(subscription);
}
}
return customer;
}
async cancelAllSubscriptions(member) {
const subscriptions = await this.getSubscriptions(member);

View File

@ -87,6 +87,12 @@ module.exports = function ({
}
}
async function linkStripeCustomer(id, member) {
if (stripe) {
await stripe.linkStripeCustomer(id, member);
}
}
async function get(data, options) {
debug(`get id:${data.id} email:${data.email}`);
const member = await getMember(data, options);
@ -160,6 +166,7 @@ module.exports = function ({
getStripeSubscriptions,
setComplimentarySubscription,
cancelComplimentarySubscription,
destroyStripeSubscriptions
destroyStripeSubscriptions,
linkStripeCustomer
};
};