add console.log statements for debugging

This commit is contained in:
Matteo Pagliazzi 2017-03-19 20:08:14 +01:00
parent 207e3476e6
commit f3fab88f0b

View file

@ -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: {