0
Fork 0
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:
Fabien O'Carroll 2019-09-25 10:23:25 +07:00
parent 69abbc6fa2
commit a92d5f064b

View file

@ -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);
}