feat(event): 10th Birthday Bash

with @CuriousMagpie and @phillipthelen
This commit is contained in:
SabreCat
2023-01-20 16:14:33 -06:00
parent a8cb303f46
commit e5bbde7e97
64 changed files with 2185 additions and 235 deletions

View File

@@ -8,7 +8,8 @@ import {
} from '../errors';
import { model as IapPurchaseReceipt } from '../../models/iapPurchaseReceipt';
import { model as User } from '../../models/user';
import { getGemsBlock, validateGiftMessage } from './gems';
import { validateGiftMessage } from './gems';
import { buySkuItem } from './skuItem';
const api = {};
@@ -21,7 +22,7 @@ api.constants = {
RESPONSE_STILL_VALID: 'SUBSCRIPTION_STILL_VALID',
};
api.verifyGemPurchase = async function verifyGemPurchase (options) {
api.verifyPurchase = async function verifyPurchase (options) {
const {
gift, user, receipt, signature, headers,
} = options;
@@ -61,39 +62,11 @@ api.verifyGemPurchase = async function verifyGemPurchase (options) {
userId: user._id,
});
let gemsBlockKey;
switch (receiptObj.productId) { // eslint-disable-line default-case
case 'com.habitrpg.android.habitica.iap.4gems':
gemsBlockKey = '4gems';
break;
case 'com.habitrpg.android.habitica.iap.20gems':
case 'com.habitrpg.android.habitica.iap.21gems':
gemsBlockKey = '21gems';
break;
case 'com.habitrpg.android.habitica.iap.42gems':
gemsBlockKey = '42gems';
break;
case 'com.habitrpg.android.habitica.iap.84gems':
gemsBlockKey = '84gems';
break;
}
if (!gemsBlockKey) throw new NotAuthorized(this.constants.RESPONSE_INVALID_ITEM);
const gemsBlock = getGemsBlock(gemsBlockKey);
if (gift) {
gift.type = 'gems';
if (!gift.gems) gift.gems = {};
gift.gems.amount = shared.content.gems[gemsBlock.key].gems;
}
await payments.buyGems({
await buySkuItem({ // eslint-disable-line no-await-in-loop
user,
gift,
paymentMethod: this.constants.PAYMENT_METHOD_GOOGLE,
gemsBlock,
paymentMethod: api.constants.PAYMENT_METHOD_GOOGLE,
sku: googleRes.productId,
headers,
});