mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added method for getting stripe customer for member
no-issue This finds the first active customer that is linked to the member, and created and links a new customer if a viable one does not exist.
This commit is contained in:
parent
69abbc6fa2
commit
a92d5f064b
1 changed files with 19 additions and 0 deletions
|
@ -82,6 +82,25 @@ module.exports = class StripePaymentProcessor {
|
|||
}));
|
||||
}
|
||||
|
||||
async _customerForMember(member) {
|
||||
const metadata = await this.storage.get(member);
|
||||
|
||||
for (const data in metadata) {
|
||||
const customer = await this.getCustomer(data.customer_id);
|
||||
if (!customer.deleted) {
|
||||
return customer;
|
||||
}
|
||||
}
|
||||
|
||||
const customer = await create(this._stripe, 'customers', {
|
||||
email: member.email
|
||||
});
|
||||
|
||||
await this.addCustomerToMember(member, customer);
|
||||
|
||||
return customer;
|
||||
}
|
||||
|
||||
async getCustomer(id) {
|
||||
return retrieve(this._stripe, 'customers', id);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue