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,27 +285,23 @@ api.buyGems = function(req, res) {
|
|||
});
|
||||
};
|
||||
|
||||
api.buyGemsPaypalIPN = function(req, res) {
|
||||
api.buyGemsPaypalIPN = function(req, res, next) {
|
||||
res.send(200);
|
||||
ipn.verify(req.body, function callback(err, msg) {
|
||||
if (err) {
|
||||
console.error(msg);
|
||||
res.send(500, msg);
|
||||
} else {
|
||||
if (req.body.payment_status == 'Completed') {
|
||||
//Payment has been confirmed as completed
|
||||
var parts = url.parse(req.body.custom, true);
|
||||
var uid = parts.query.uid; //, apiToken = query.apiToken;
|
||||
if (!uid) throw new Error("uuid or apiToken not found when completing paypal transaction");
|
||||
User.findById(uid, function(err, user) {
|
||||
if (err) throw err;
|
||||
if (_.isEmpty(user)) throw "user not found with uuid " + uuid + " when completing paypal transaction"
|
||||
user.balance += 5;
|
||||
user.purchased.ads = true;
|
||||
user.save();
|
||||
console.log('PayPal transaction completed and user updated');
|
||||
});
|
||||
}
|
||||
if (err) return next('PayPal Error: ' + msg);
|
||||
if (req.body.payment_status == 'Completed') {
|
||||
//Payment has been confirmed as completed
|
||||
var parts = url.parse(req.body.custom, true);
|
||||
var uid = parts.query.uid; //, apiToken = query.apiToken;
|
||||
if (!uid) return next("uuid or apiToken not found when completing paypal transaction");
|
||||
User.findById(uid, function(err, user) {
|
||||
if (_.isEmpty(user)) err = "user not found with uuid " + uuid + " when completing paypal transaction";
|
||||
if (err) return nex(err);
|
||||
user.balance += 5;
|
||||
user.purchased.ads = true;
|
||||
user.save();
|
||||
console.log('PayPal transaction completed and user updated');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -305,7 +305,10 @@ module.exports = (swagger, v2) ->
|
|||
action:user.buyGems
|
||||
|
||||
"/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
|
||||
|
||||
"/user/batch-update":
|
||||
|
|
|
|||
Loading…
Reference in a new issue