mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-04 01:29:21 +00:00
apiv2 swagger fixes to paypal, and send admin emails
This commit is contained in:
parent
6d8e4ed8a2
commit
5e321b0205
2 changed files with 19 additions and 20 deletions
|
|
@ -285,28 +285,24 @@ api.buyGems = function(req, res) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
api.buyGemsPaypalIPN = function(req, res) {
|
api.buyGemsPaypalIPN = function(req, res, next) {
|
||||||
res.send(200);
|
res.send(200);
|
||||||
ipn.verify(req.body, function callback(err, msg) {
|
ipn.verify(req.body, function callback(err, msg) {
|
||||||
if (err) {
|
if (err) return next('PayPal Error: ' + msg);
|
||||||
console.error(msg);
|
|
||||||
res.send(500, msg);
|
|
||||||
} else {
|
|
||||||
if (req.body.payment_status == 'Completed') {
|
if (req.body.payment_status == 'Completed') {
|
||||||
//Payment has been confirmed as completed
|
//Payment has been confirmed as completed
|
||||||
var parts = url.parse(req.body.custom, true);
|
var parts = url.parse(req.body.custom, true);
|
||||||
var uid = parts.query.uid; //, apiToken = query.apiToken;
|
var uid = parts.query.uid; //, apiToken = query.apiToken;
|
||||||
if (!uid) throw new Error("uuid or apiToken not found when completing paypal transaction");
|
if (!uid) return next("uuid or apiToken not found when completing paypal transaction");
|
||||||
User.findById(uid, function(err, user) {
|
User.findById(uid, function(err, user) {
|
||||||
if (err) throw err;
|
if (_.isEmpty(user)) err = "user not found with uuid " + uuid + " when completing paypal transaction";
|
||||||
if (_.isEmpty(user)) throw "user not found with uuid " + uuid + " when completing paypal transaction"
|
if (err) return nex(err);
|
||||||
user.balance += 5;
|
user.balance += 5;
|
||||||
user.purchased.ads = true;
|
user.purchased.ads = true;
|
||||||
user.save();
|
user.save();
|
||||||
console.log('PayPal transaction completed and user updated');
|
console.log('PayPal transaction completed and user updated');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,10 @@ module.exports = (swagger, v2) ->
|
||||||
action:user.buyGems
|
action:user.buyGems
|
||||||
|
|
||||||
"/user/buy-gems/paypal-ipn":
|
"/user/buy-gems/paypal-ipn":
|
||||||
spec: method: 'POST', description: "Don't use this route"
|
spec:
|
||||||
|
method: 'POST'
|
||||||
|
description: "Don't use this route"
|
||||||
|
middleware: []
|
||||||
action: user.buyGemsPaypalIPN
|
action: user.buyGemsPaypalIPN
|
||||||
|
|
||||||
"/user/batch-update":
|
"/user/batch-update":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue