mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-13 10:55:58 +03:00
✨ 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:
parent
cf0d52c2da
commit
96aea55270
@ -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);
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user