mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Groups can prevent members from getting gems (#8870)
* add possibility for group to block members from getting gems * fixes * fix tests * adds some tests * unit tests * finish unit tests * remove old code
This commit is contained in:
committed by
Sabe Jones
parent
fe9521a63f
commit
78ba596504
@@ -76,6 +76,11 @@ api.checkout = async function checkout (options, stripeInc) {
|
||||
|
||||
if (!token) throw new BadRequest('Missing req.body.id');
|
||||
|
||||
if (gift) {
|
||||
const member = await User.findById(gift.uuid).exec();
|
||||
gift.member = member;
|
||||
}
|
||||
|
||||
if (sub) {
|
||||
if (sub.discount) {
|
||||
if (!coupon) throw new BadRequest(shared.i18n.t('couponCodeRequired'));
|
||||
@@ -114,6 +119,12 @@ api.checkout = async function checkout (options, stripeInc) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!gift || gift.type === 'gems') {
|
||||
const receiver = gift ? gift.member : user;
|
||||
const receiverCanGetGems = await receiver.canGetGems();
|
||||
if (!receiverCanGetGems) throw new NotAuthorized(shared.i18n.t('groupPolicyCannotGetGems', receiver.preferences.language));
|
||||
}
|
||||
|
||||
response = await stripeApi.charges.create({
|
||||
amount,
|
||||
currency: 'usd',
|
||||
@@ -141,8 +152,6 @@ api.checkout = async function checkout (options, stripeInc) {
|
||||
};
|
||||
|
||||
if (gift) {
|
||||
let member = await User.findById(gift.uuid).exec();
|
||||
gift.member = member;
|
||||
if (gift.type === 'subscription') method = 'createSubscription';
|
||||
data.paymentMethod = 'Gift';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user