From f3fab88f0bc0ea6ee29e9c4911547702a819ae37 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Sun, 19 Mar 2017 20:08:14 +0100 Subject: [PATCH] add console.log statements for debugging --- website/server/libs/stripePayments.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/website/server/libs/stripePayments.js b/website/server/libs/stripePayments.js index 64555318fe..476c2d6e7f 100644 --- a/website/server/libs/stripePayments.js +++ b/website/server/libs/stripePayments.js @@ -287,9 +287,11 @@ api.handleWebhooks = async function handleWebhooks (options, stripeInc) { if (stripeInc) stripeApi = stripeInc; const eventJSON = JSON.parse(requestBody); + console.log(eventJSON); // Verify the event by fetching it from Stripe const event = await stripeApi.events.retrieve(eventJSON.id); + console.log(event); switch (event.type) { case 'customer.subscription.deleted': { @@ -305,6 +307,7 @@ api.handleWebhooks = async function handleWebhooks (options, stripeInc) { let groupId; if (isGroupSub) { + console.log('is group sub'); let groupFields = basicGroupFields.concat(' purchased'); let group = await Group.findOne({ 'purchased.plan.customerId': customerId, @@ -316,6 +319,7 @@ api.handleWebhooks = async function handleWebhooks (options, stripeInc) { user = await User.findById(group.leader).exec(); } else { + console.log('is not group sub'); user = await User.findOne({ 'purchased.plan.customerId': customerId, paymentMethod: this.constants.PAYMENT_METHOD, @@ -324,13 +328,21 @@ api.handleWebhooks = async function handleWebhooks (options, stripeInc) { if (!user) throw new NotFound(i18n.t('groupNotFound')); + console.log('groupId', groupId); + console.log('userId', user._id); + await stripeApi.customers.del(customerId); + console.log('deleted stripe customer'); + await payments.cancelSubscription({ user, groupId, paymentMethod: this.constants.PAYMENT_METHOD, }); + + console.log('cancelled subscription'); + break; } default: {