Merge branch 'paypal' into develop

Conflicts:
	bower.json
This commit is contained in:
Tyler Renelle 2013-10-12 19:23:44 -07:00
commit 4c018d84c1
17 changed files with 86 additions and 54 deletions

View file

@ -32,11 +32,13 @@
"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",
"bootstrap": "v2.3.2"
"bootstrap": "v2.3.2",
"angular": "1.2.0-rc.2"
},
"devDependencies": {
"angular-mocks": "1.2.0-rc.2"

View file

@ -13,4 +13,5 @@
"SMTP_SERVICE":"Gmail",
"STRIPE_API_KEY":"aaaabbbbccccddddeeeeffff00001111",
"STRIPE_PUB_KEY":"22223333444455556666777788889999"
"PAYPAL_MERCHANT":"paypal-merchant@gmail.com"
}

View file

@ -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",

View file

@ -168,4 +168,8 @@ a
word-wrap: break-word
.btn
margin-right: 5px
margin-right: 5px
.buy-gems-list
margin-left: 10px;
padding-left: 10px;

View file

@ -114,7 +114,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
$scope.create = function(group){
if (User.user.balance < 1) {
return $rootScope.modals.moreGems = true;
return $rootScope.modals.buyGems = true;
// $('#more-gems-modal').modal('show');
}

View file

@ -12,7 +12,7 @@ habitrpg.controller("MarketCtrl", ['$rootScope', '$scope', 'User', 'API_URL', '$
storePath = type === 'egg' ? 'items.eggs' : 'items.hatchingPotions'
if(gems < item.value){
return $rootScope.modals.moreGems = true;
return $rootScope.modals.buyGems = true;
}
var message = "Buy this " + (type == 'egg' ? 'egg' : 'hatching potion') + " with " + item.value + " of your " + gems + " Gems?"

View file

@ -42,25 +42,24 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
}
$rootScope.showStripe = function() {
var disableAds = User.user.flags.ads == 'hide' ? '' : 'Disable Ads, ';
StripeCheckout.open({
key: window.env.STRIPE_PUB_KEY,
address: false,
amount: 500,
name: "Checkout",
description: "Buy 20 Gems, " + disableAds + "Support the Developers",
panelLabel: "Checkout",
token: function(data) {
$scope.$apply(function(){
$http.post("/api/v1/user/buy-gems", data)
.success(function() {
window.location.href = "/";
}).error(function(err) {
alert(err);
});
})
}
});
StripeCheckout.open({
key: window.env.STRIPE_PUB_KEY,
address: false,
amount: 500,
name: "Checkout",
description: "Buy 20 Gems, Disable Ads, Support the Developers",
panelLabel: "Checkout",
token: function(data) {
$scope.$apply(function(){
$http.post("/api/v1/user/buy-gems", data)
.success(function() {
window.location.href = "/";
}).error(function(err) {
alert(err);
});
})
}
});
}
}
]);

View file

@ -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

View file

@ -63,6 +63,8 @@ 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'),
PAYPAL_MERCHANT: nconf.get('PAYPAL_MERCHANT'),
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY'),
getBuildUrl: getBuildUrl

View file

@ -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']);

View file

@ -1,5 +1,5 @@
a.pull-right.gem-wallet(popover-trigger='mouseenter', popover-title='Gems', popover="Used for buying special items (reroll, eggs, hatching potions, etc). You'll need to unlock those features before being able to use Gems.", popover-placement='bottom')
span.task-action-btn.tile.flush.bright.add-gems-btn(ng-click='showStripe()')
span.task-action-btn.tile.flush.bright.add-gems-btn(ng-click='modals.buyGems = true')
span.task-action-btn.tile.flush.neutral
.Gems
| {{user.balance * 4 | number:0}} Gems

View file

@ -0,0 +1,21 @@
div(modal='modals.buyGems')
.modal-header
h3 Buy Gems / Donate
.modal-body
include ../gems
p <span class='label label-info'>$5 USD</span> will:
ul.buy-gems-list
li Add 20 gems to your account, which are used to buy special items.
li Disable ads.
li Donate to the developers (as an open source project, we can us all the help we can get).
.row-fluid
.span6.well
h3 Pay with Card
.btn.btn-primary(ng-click='showStripe()') Pay with Card
.span6.well
h3 Pay with PayPal
script(src='/bower_components/JavaScriptButtons/dist/paypal-button.min.js?merchant=#{env.PAYPAL_MERCHANT}', data-button='buynow', data-name='20 Gems, Disable Ads, Donation to the Developers', data-quantity='1', data-amount='5', data-currency='USD', data-shipping='0', data-tax='0', data-callback='#{env.BASE_URL}/api/v1/user/buy-gems/paypal-ipn', data-env="#{env.NODE_ENV == 'production' ? '' : 'sandbox'}", data-custom='?uid={{user._id}}&apiToken={{user.apiToken}}', data-return='#{env.BASE_URL}', data-no_shipping='1')
.modal-footer
button.btn.btn-default.cancel(ng-click='modals.buyGems = false') Cancel

View file

@ -3,8 +3,7 @@ include ./login
include ./reroll
include ./death
include ./new-stuff
include ./why-ads
include ./more-gems
include ./buy-gems
include ./members
include ./settings
include ./pets

View file

@ -1,10 +0,0 @@
div(modal='modals.moreGems', header='Out Of Gems')
.modal-header
h3 Out Of Gems
.modal-body
include ../gems
p.
Oops, out of Gems, which are used to buy special items! Habit is an open source project, and can use all the help
it can get - buy more Gems to receive this pet, and consider it a donation to the contributors.
.modal-footer
button.btn.btn-default.cancel(ng-click='modals.moreGems = false') Cancel

View file

@ -11,7 +11,7 @@ div(modal='modals.reroll')
.modal-footer
span(ng-if='user.balance < 1')
a.btn.btn-success.btn-large(ng-click="showStripe()") Buy More Gems
a.btn.btn-success.btn-large(ng-click="modals.buyGems = true") Buy More Gems
span.gem-cost Not enough Gems
span(ng-if='user.balance >= 1', ng-controller='SettingsCtrl')
a.btn.btn-danger.btn-large(ng-click='reroll()') Re-Roll

View file

@ -1,11 +0,0 @@
div(modal='modals.whyAds')
.modal-header
h3 Why Ads?
.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.
.modal-footer
button.btn.btn-default.cancel(ng-click='modals.whyAds = false') Ok

View file

@ -1,10 +1,7 @@
div(ng-if='authenticated() && user.flags.ads!="hide"')
span.pull-right(ng-if='list.type!="reward"')
a(ng-click='showStripe()', tooltip='Remove Ads')
a(ng-click='modals.buyGems=true', tooltip='Remove Ads')
i.icon-remove
br
a(ng-click='modals.whyAds=true', tooltip='Why Ads?')
i.icon-question-sign
div(ng-if='list.type=="habit"', habitrpg-adsense)
script(async='async', src='//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js')