0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Refactored some private methods for stripe

no-issue

This is to expose a clearer contract with the outside world
This commit is contained in:
Fabien O'Carroll 2019-10-08 13:31:59 +07:00
parent e6c8f77d4e
commit d11a0db726
2 changed files with 9 additions and 5 deletions

View file

@ -202,7 +202,7 @@ module.exports = function MembersApi({
const customer = await stripe.getCustomer(event.data.object.customer);
const member = await users.get({email: customer.email}) || await users.create({email: customer.email});
await stripe.addCustomerToMember(member, customer);
await stripe.handleCheckoutSessionCompletedWebhook(member, customer);
const emailType = 'signup';
await sendEmailWithMagicLink(customer.email, emailType, {forceEmailType: true});

View file

@ -81,7 +81,7 @@ module.exports = class StripePaymentProcessor {
let customer;
if (member) {
try {
customer = await this._customerForMember(member);
customer = await this._customerForMemberCheckoutSession(member);
} catch (err) {
debug(`Ignoring Error getting customer for checkout ${err.message}`);
customer = null;
@ -176,7 +176,11 @@ module.exports = class StripePaymentProcessor {
});
}
async addCustomerToMember(member, customer) {
async handleCheckoutSessionCompletedWebhook(member, customer) {
await this._addCustomerToMember(member, customer);
}
async _addCustomerToMember(member, customer) {
const metadata = await this.storage.get(member);
// Do not add the customer if they are already linked
if (metadata.some(data => data.customer_id === customer.id)) {
@ -188,7 +192,7 @@ module.exports = class StripePaymentProcessor {
}));
}
async _customerForMember(member) {
async _customerForMemberCheckoutSession(member) {
const metadata = await this.storage.get(member);
for (const data in metadata) {
@ -207,7 +211,7 @@ module.exports = class StripePaymentProcessor {
email: member.email
});
await this.addCustomerToMember(member, customer);
await this._addCustomerToMember(member, customer);
return customer;
}