fix(subscriptions): avoid parallelSave from recursive fn call
This commit is contained in:
@@ -18,6 +18,7 @@ import { // eslint-disable-line import/no-cycle
|
||||
} from '../../models/group';
|
||||
import { model as Coupon } from '../../models/coupon';
|
||||
import { getGemsBlock } from './gems'; // eslint-disable-line import/no-cycle
|
||||
import promoSubscription from './promoSubscription'; // eslint-disable-line import/no-cycle
|
||||
|
||||
// TODO better handling of errors
|
||||
|
||||
@@ -185,6 +186,8 @@ api.checkout = async function checkout (options = {}) {
|
||||
gift.member = await User.findById(gift.uuid).exec();
|
||||
data.gift = gift;
|
||||
data.paymentMethod = this.constants.PAYMENT_METHOD_GIFT;
|
||||
|
||||
promoSubscription(data);
|
||||
}
|
||||
|
||||
await payments[method](data);
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from '../errors';
|
||||
import { model as IapPurchaseReceipt } from '../../models/iapPurchaseReceipt';
|
||||
import { model as User } from '../../models/user';
|
||||
import promoSubscription from './promoSubscription'; // eslint-disable-line import/no-cycle
|
||||
|
||||
const api = {};
|
||||
|
||||
@@ -236,6 +237,8 @@ api.noRenewSubscribe = async function noRenewSubscribe (options) {
|
||||
gift.subscription = sub;
|
||||
data.gift = gift;
|
||||
data.paymentMethod = this.constants.PAYMENT_METHOD_GIFT;
|
||||
|
||||
promoSubscription(data);
|
||||
}
|
||||
|
||||
await payments.createSubscription(data);
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import { model as IapPurchaseReceipt } from '../../models/iapPurchaseReceipt';
|
||||
import { model as User } from '../../models/user';
|
||||
import { getGemsBlock } from './gems';
|
||||
import promoSubscription from './promoSubscription'; // eslint-disable-line import/no-cycle
|
||||
|
||||
const api = {};
|
||||
|
||||
@@ -218,6 +219,8 @@ api.noRenewSubscribe = async function noRenewSubscribe (options) {
|
||||
gift.subscription = sub;
|
||||
data.gift = gift;
|
||||
data.paymentMethod = this.constants.PAYMENT_METHOD_GIFT;
|
||||
|
||||
promoSubscription(data);
|
||||
}
|
||||
|
||||
await payments.createSubscription(data);
|
||||
|
||||
@@ -11,6 +11,7 @@ import payments from './payments'; // eslint-disable-line import/no-cycle
|
||||
import { getGemsBlock } from './gems'; // eslint-disable-line import/no-cycle
|
||||
import { model as Coupon } from '../../models/coupon';
|
||||
import { model as User } from '../../models/user'; // eslint-disable-line import/no-cycle
|
||||
import promoSubscription from './promoSubscription'; // eslint-disable-line import/no-cycle
|
||||
import { // eslint-disable-line import/no-cycle
|
||||
model as Group,
|
||||
basicFields as basicGroupFields,
|
||||
@@ -162,6 +163,8 @@ api.checkoutSuccess = async function checkoutSuccess (options = {}) {
|
||||
|
||||
data.paymentMethod = 'PayPal (Gift)';
|
||||
data.gift = gift;
|
||||
|
||||
promoSubscription(data);
|
||||
} else {
|
||||
data.gemsBlock = getGemsBlock(gemsBlockKey);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { getCurrentEvent } from '../worldState'; // eslint-disable-line import/no-cycle
|
||||
import createSubscription from './payments'; // eslint-disable-line import/no-cycle
|
||||
|
||||
const currentEvent = getCurrentEvent();
|
||||
|
||||
export default async function promoSubscription (data) {
|
||||
if (currentEvent && currentEvent.promo && currentEvent.promo === 'g1g1') {
|
||||
const promoData = {
|
||||
user: data.user,
|
||||
gift: {
|
||||
member: data.user,
|
||||
subscription: {
|
||||
key: data.gift.subscription.key,
|
||||
},
|
||||
},
|
||||
paymentMethod: data.paymentMethod,
|
||||
promo: 'Winter',
|
||||
promoUsername: data.gift.member.auth.local.username,
|
||||
};
|
||||
await createSubscription(promoData);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
import payments from '../payments'; // eslint-disable-line import/no-cycle
|
||||
import { getGemsBlock } from '../gems'; // eslint-disable-line import/no-cycle
|
||||
import stripeConstants from './constants';
|
||||
import promoSubscription from '../promoSubscription'; // eslint-disable-line import/no-cycle
|
||||
|
||||
function getGiftAmount (gift) {
|
||||
if (gift.type === 'subscription') {
|
||||
@@ -98,6 +99,8 @@ async function applyGemPayment (user, response, gemsBlock, gift) {
|
||||
if (gift) {
|
||||
if (gift.type === 'subscription') method = 'createSubscription';
|
||||
data.paymentMethod = 'Gift';
|
||||
|
||||
promoSubscription(data);
|
||||
}
|
||||
|
||||
await payments[method](data);
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
import shared from '../../../common';
|
||||
import { sendNotification as sendPushNotification } from '../pushNotifications'; // eslint-disable-line import/no-cycle
|
||||
import calculateSubscriptionTerminationDate from './calculateSubscriptionTerminationDate';
|
||||
import { getCurrentEvent } from '../worldState'; // eslint-disable-line import/no-cycle
|
||||
|
||||
// @TODO: Abstract to shared/constant
|
||||
const JOINED_GROUP_PLAN = 'joined group plan';
|
||||
@@ -244,23 +243,6 @@ async function createSubscription (data) {
|
||||
|
||||
// Only send push notifications if sending to a user other than yourself
|
||||
if (data.gift.member._id !== data.user._id) {
|
||||
const currentEvent = getCurrentEvent();
|
||||
if (currentEvent && currentEvent.promo && currentEvent.promo === 'g1g1') {
|
||||
const promoData = {
|
||||
user: data.user,
|
||||
gift: {
|
||||
member: data.user,
|
||||
subscription: {
|
||||
key: data.gift.subscription.key,
|
||||
},
|
||||
},
|
||||
paymentMethod: data.paymentMethod,
|
||||
promo: 'Winter',
|
||||
promoUsername: data.gift.member.auth.local.username,
|
||||
};
|
||||
await this.createSubscription(promoData);
|
||||
}
|
||||
|
||||
if (data.gift.member.preferences.pushNotifications.giftedSubscription !== false) {
|
||||
sendPushNotification(data.gift.member,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user