Merge branch 'develop' into TheHollidayInn-tasks-api-up-checkoff-todo

This commit is contained in:
Blade Barringer
2015-06-19 23:00:18 -05:00
350 changed files with 11713 additions and 10453 deletions
+1
View File
@@ -40,6 +40,7 @@ var populateQuery = function(type, q, additionalFields){
q.populate('members', partyFields + (additionalFields ? (' ' + additionalFields) : ''));
else
q.populate(guildPopulate);
q.populate('leader', nameFields);
q.populate('invites', nameFields);
q.populate({
path: 'challenges',
+43 -35
View File
@@ -6,7 +6,7 @@ var nconf = require('nconf');
var inAppPurchase = require('in-app-purchase');
inAppPurchase.config({
// this is the path to the directory containing iap-sanbox/iap-live files
googlePublicKeyPath: nconf.get("IAP_GOOGLE_KEYDIR")
googlePublicKeyPath: nconf.get("IAP_GOOGLE_KEYDIR")
});
// Validation ERROR Codes
@@ -24,15 +24,11 @@ exports.androidVerify = function(req, res, next) {
ok: false,
data: 'IAP Error'
};
console.error('IAP Setup ERROR');
console.error(error);
res.json(resObj);
return;
return res.json(resObj);
}
/*
google receipt must be provided as an object
{
@@ -44,7 +40,7 @@ exports.androidVerify = function(req, res, next) {
data: iapBody.transaction.receipt,
signature: iapBody.transaction.signature
};
// iap is ready
iap.validate(iap.GOOGLE, testObj, function (err, googleRes) {
if (err) {
@@ -56,9 +52,7 @@ exports.androidVerify = function(req, res, next) {
}
};
res.json(resObj);
console.error(err);
return;
return res.json(resObj);
}
if (iap.isValidated(googleRes)) {
@@ -69,16 +63,13 @@ exports.androidVerify = function(req, res, next) {
payments.buyGems({user:user, paymentMethod:'IAP GooglePlay'});
// yay good!
res.json(resObj);
return res.json(resObj);
}
});
});
};
exports.iosVerify = function(req, res, next) {
console.info(req.body);
var iapBody = req.body;
var user = res.locals.user;
@@ -89,15 +80,11 @@ exports.iosVerify = function(req, res, next) {
data: 'IAP Error'
};
console.error('IAP Setup ERROR');
console.error(error);
return res.json(resObj);
res.json(resObj);
return;
}
// iap is ready
//iap is ready
iap.validate(iap.APPLE, iapBody.transaction.receipt, function (err, appleRes) {
if (err) {
var resObj = {
@@ -108,22 +95,43 @@ exports.iosVerify = function(req, res, next) {
}
};
res.json(resObj);
console.error(err);
return;
return res.json(resObj);
}
if (iap.isValidated(appleRes)) {
var purchaseDataList = iap.getPurchaseData(appleRes);
if (purchaseDataList.length > 0) {
if (purchaseDataList[0].productId === "com.habitrpg.ios.Habitica.20gems") {
//Correct receipt
payments.buyGems({user:user, paymentMethod:'IAP AppleStore'});
var resObj = {
ok: true,
data: appleRes
};
// yay good!
return res.json(resObj);
}
}
//wrong receipt content
var resObj = {
ok: true,
data: appleRes
ok: false,
data: {
code: INVALID_PAYLOAD,
message: "Incorrect receipt content"
}
};
payments.buyGems({user:user, paymentMethod:'IAP AppleStore'});
// yay good!
res.json(resObj);
return res.json(resObj);
}
//invalid receipt
var resObj = {
ok: false,
data: {
code: INVALID_PAYLOAD,
message: "Invalid receipt"
}
};
return res.json(resObj);
});
});
};
};