diff --git a/website/server/libs/payments/subscriptions.js b/website/server/libs/payments/subscriptions.js index 80401f21de..2052dc4c9a 100644 --- a/website/server/libs/payments/subscriptions.js +++ b/website/server/libs/payments/subscriptions.js @@ -11,7 +11,6 @@ import { // eslint-disable-line import/no-cycle model as Group, basicFields as basicGroupFields, } from '../../models/group'; -import { model as User } from '../../models/user'; // eslint-disable-line import/no-cycle import { NotAuthorized, NotFound, @@ -80,22 +79,6 @@ async function createSubscription (data) { let emailType = 'subscription-begins'; let recipientIsSubscribed = recipient.isSubscribed(); - if (data.user && !data.gift && !data.groupId) { - const unlockedUser = await User.findOneAndUpdate( - { - _id: data.user._id, - $or: [ - { _subSignature: 'NOT_RUNNING' }, - { _subSignature: { $exists: false } }, - ], - }, - { $set: { _subSignature: 'SUB_IN_PROGRESS' } }, - ); - if (!unlockedUser) { - throw new NotFound('User not found or subscription already processing.'); - } - } - // If we are buying a group subscription if (data.groupId) { const groupFields = basicGroupFields.concat(' purchased'); @@ -299,6 +282,10 @@ async function createSubscription (data) { } } + if (group) await group.save(); + if (data.user && data.user.isModified()) await data.user.save(); + if (data.gift) await data.gift.member.save(); + slack.sendSubscriptionNotification({ buyer: { id: data.user._id, @@ -315,24 +302,6 @@ async function createSubscription (data) { groupId, autoRenews, }); - - if (group) { - await group.save(); - } - if (data.user) { - if (data.user.isModified()) { - await data.user.save(); - } - if (!data.gift && !data.groupId) { - await User.findOneAndUpdate( - { _id: data.user._id }, - { $set: { _subSignature: 'NOT_RUNNING' } }, - ); - } - } - if (data.gift) { - await data.gift.member.save(); - } } // Cancels a subscription or group plan, setting termination to happen later