mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00:00
paypal: begin adding paypal alternative to credit-card payments
This commit is contained in:
parent
8aefe96910
commit
09cd132420
6 changed files with 37 additions and 7 deletions
|
|
@ -32,12 +32,12 @@
|
|||
"angular-route": "1.2.0-rc.2",
|
||||
"angular-ui-utils": "~0.0.4",
|
||||
"angular-sanitize": "1.2.0-rc.2",
|
||||
"marked": "~0.2.9"
|
||||
"marked": "~0.2.9",
|
||||
"JavaScriptButtons": "git://github.com/paypal/JavaScriptButtons.git#master"
|
||||
},
|
||||
"resolutions": {
|
||||
"jquery": "~2.0.3",
|
||||
"angular": "1.2.0-rc.2",
|
||||
"angular-mocks": "1.2.0-rc.2"
|
||||
"angular": "1.2.0-rc.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"angular-mocks": "1.2.0-rc.2"
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@
|
|||
"passport": "~0.1.17",
|
||||
"validator": "~1.5.1",
|
||||
"nodemailer": "~0.5.2",
|
||||
"grunt-cli": "~0.1.9"
|
||||
"grunt-cli": "~0.1.9",
|
||||
"paypal-ipn": "~1.0.1"
|
||||
},
|
||||
"private": true,
|
||||
"subdomain": "habitrpg",
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// fixme remove this junk, was coffeescript compiled (probably for IE8 compat)
|
||||
var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
var url = require('url');
|
||||
var _ = require('lodash');
|
||||
var nconf = require('nconf');
|
||||
var async = require('async');
|
||||
|
|
@ -591,6 +592,31 @@ api.buyGems = function(req, res) {
|
|||
});
|
||||
};
|
||||
|
||||
api.buyGemsPaypalIPN = function(req, res) {
|
||||
var ipn = require('paypal-ipn');
|
||||
|
||||
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.flags.ads = 'hide';
|
||||
user.save();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------
|
||||
Tags
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ module.exports.locals = function(req, res, next) {
|
|||
res.locals.habitrpg = res.locals.habitrpg || {}
|
||||
_.defaults(res.locals.habitrpg, {
|
||||
NODE_ENV: nconf.get('NODE_ENV'),
|
||||
BASE_URL: nconf.get('BASE_URL'),
|
||||
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
|
||||
STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY'),
|
||||
getBuildUrl: getBuildUrl
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ router.post('/user/revive', auth.auth, cron, user.revive);
|
|||
router.post('/user/batch-update', auth.auth, cron, user.batchUpdate);
|
||||
router.post('/user/reroll', auth.auth, cron, user.reroll);
|
||||
router.post('/user/buy-gems', auth.auth, user.buyGems);
|
||||
router.post('/user/buy-gems/paypal-ipn', user.buyGemsPaypalIPN);
|
||||
router.post('/user/reset', auth.auth, user.reset);
|
||||
router['delete']('/user', auth.auth, user['delete']);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ div(modal='modals.whyAds')
|
|||
.modal-body
|
||||
p.
|
||||
Habit is an open source project, and can use all the help it can get - consider this a donation to the contributors. You also get 20 Gems from the purchase, which you can use to buy special items.
|
||||
p
|
||||
| "Hey, I backed the Kickstarter!" - follow
|
||||
a(target='_blank', href='http://community.habitrpg.com/node/22') these instructions.
|
||||
p.
|
||||
"Hey, I backed the Kickstarter!" - follow <a target='_blank' href='http://community.habitrpg.com/node/22'> these instructions.</a>
|
||||
script(src='/bower_components/JavaScriptButtons/dist/paypal-button.min.js?merchant=tylerrenelle-facilitator@gmail.com', data-button='buynow', data-name='20 Gems, Disable Ads, Donation to the Developers', data-quantity='1', data-amount='.1', data-currency='USD', data-shipping='0', data-tax='0', data-callback='#{env.BASE_URL}/api/v1/user/buy-gems/paypal-ipn', data-env='sandbox', data-custom='?uid={{user._id}}&apiToken={{user.apiToken}}')
|
||||
|
||||
.modal-footer
|
||||
button.btn.btn-default.cancel(ng-click='modals.whyAds = false') Ok
|
||||
Loading…
Reference in a new issue