mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
feat(event): 10th Birthday Bash
with @CuriousMagpie and @phillipthelen
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user