mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00:00
feat(subscriptions): implement partial paypal-recurring. It's having issues with cookies
This commit is contained in:
parent
e109128570
commit
d1a2fbbbd9
5 changed files with 60 additions and 3 deletions
|
|
@ -18,5 +18,8 @@
|
||||||
"STRIPE_PUB_KEY":"22223333444455556666777788889999",
|
"STRIPE_PUB_KEY":"22223333444455556666777788889999",
|
||||||
"PAYPAL_MERCHANT":"paypal-merchant@gmail.com",
|
"PAYPAL_MERCHANT":"paypal-merchant@gmail.com",
|
||||||
"NEW_RELIC_LICENSE_KEY":"NEW_RELIC_LICENSE_KEY",
|
"NEW_RELIC_LICENSE_KEY":"NEW_RELIC_LICENSE_KEY",
|
||||||
"GA_ID": "GA_ID"
|
"GA_ID": "GA_ID",
|
||||||
|
"PAYPAL_USERNAME": "PAYPAL_USERNAME",
|
||||||
|
"PAYPAL_PASSWORD": "PAYPAL_PASSWORD",
|
||||||
|
"PAYPAL_SIGNATURE": "PAYPAL_SIGNATURE"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
|
||||||
//debugger
|
//debugger
|
||||||
var data = {
|
var data = {
|
||||||
name:env.t('donationDesc'),
|
name:env.t('donationDesc'),
|
||||||
//env:window.env.NODE_ENV == 'production' ? '' : 'sandbox',
|
env:window.env.NODE_ENV == 'production' ? '' : 'sandbox',
|
||||||
quantity:1,
|
quantity:1,
|
||||||
amount:5,
|
amount:5,
|
||||||
currency:'USD',
|
currency:'USD',
|
||||||
|
|
@ -114,6 +114,10 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
|
||||||
PAYPAL.apps.ButtonFactory.create(window.env.PAYPAL_MERCHANT, data, 'buynow', document.getElementById('custom-paypal-button'));
|
PAYPAL.apps.ButtonFactory.create(window.env.PAYPAL_MERCHANT, data, 'buynow', document.getElementById('custom-paypal-button'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rootScope.paypalSubscribe = function(){
|
||||||
|
$http.get('/paypal/subscribe');
|
||||||
|
}
|
||||||
|
|
||||||
$rootScope.showStripe = function(subscription) {
|
$rootScope.showStripe = function(subscription) {
|
||||||
StripeCheckout.open({
|
StripeCheckout.open({
|
||||||
key: window.env.STRIPE_PUB_KEY,
|
key: window.env.STRIPE_PUB_KEY,
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,14 @@ var logging = require('./../logging');
|
||||||
var acceptablePUTPaths;
|
var acceptablePUTPaths;
|
||||||
var api = module.exports;
|
var api = module.exports;
|
||||||
|
|
||||||
|
var Paypal = require('paypal-recurring'),
|
||||||
|
paypal = new Paypal({
|
||||||
|
username: nconf.get('PAYPAL_USERNAME'),
|
||||||
|
password: nconf.get('PAYPAL_PASSWORD'),
|
||||||
|
signature: nconf.get('PAYPAL_SIGNATURE'),
|
||||||
|
environment: nconf.get("NODE_ENV") === "production" ? "production" : "sandbox"
|
||||||
|
});
|
||||||
|
|
||||||
// api.purchase // Shared.ops
|
// api.purchase // Shared.ops
|
||||||
|
|
||||||
api.getContent = function(req, res, next) {
|
api.getContent = function(req, res, next) {
|
||||||
|
|
@ -377,6 +385,39 @@ api.cancelSubscription = function(req, res, next) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api.paypalSubscribe = function(req,res,next) {
|
||||||
|
var uuid = req.query.uuid;
|
||||||
|
if (!uuid) return next("UUID required");
|
||||||
|
// Authenticate a future subscription of ~5 USD
|
||||||
|
paypal.authenticate({
|
||||||
|
RETURNURL: nconf.get('BASE_URL') + '/paypal/subscribe/success?uuid=' + uuid,
|
||||||
|
CANCELURL: nconf.get('BASE_URL') + '/paypal/subscribe/fail?uuid=' + uuid,
|
||||||
|
PAYMENTREQUEST_0_AMT: 5,
|
||||||
|
L_BILLINGAGREEMENTDESCRIPTION0: "HabitRPG Subscription"
|
||||||
|
}, function(err, data, url) {
|
||||||
|
// Redirect the user if everything went well with
|
||||||
|
// a HTTP 302 according to PayPal's guidelines
|
||||||
|
if (err) return next(err);
|
||||||
|
res.redirect(302, url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
api.paypalSubscribeSuccess = function(req,res,next) {
|
||||||
|
// Create a subscription of 10 USD every month
|
||||||
|
var uuid = req.query.uuid;
|
||||||
|
if (!uuid) return next("UUID required");
|
||||||
|
paypal.createSubscription(req.query.token, req.query.PayerId,{
|
||||||
|
AMT: 5,
|
||||||
|
DESC: "HabitRPG Subscription",
|
||||||
|
BILLINGPERIOD: "Month",
|
||||||
|
BILLINGFREQUENCY: 1,
|
||||||
|
}, function(err, data) {
|
||||||
|
if (err) return res.next(err);
|
||||||
|
res.send("You are now one of our customers!");
|
||||||
|
console.log("New customer with PROFILEID: " + data.PROFILEID)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
api.buyGemsPaypalIPN = function(req, res, next) {
|
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) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ var nconf = require('nconf');
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = new express.Router();
|
var router = new express.Router();
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var middleware = require('../middleware')
|
var middleware = require('../middleware');
|
||||||
|
var user = require('../controllers/user');
|
||||||
|
var auth = require('../controllers/auth');
|
||||||
|
|
||||||
// -------- App --------
|
// -------- App --------
|
||||||
router.get('/', middleware.locals, function(req, res) {
|
router.get('/', middleware.locals, function(req, res) {
|
||||||
|
|
@ -55,4 +57,9 @@ router.get('/static/extensions', function(req, res) {
|
||||||
res.redirect('http://habitrpg.wikia.com/wiki/App_and_Extension_Integrations');
|
res.redirect('http://habitrpg.wikia.com/wiki/App_and_Extension_Integrations');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// --------- PayPal --------
|
||||||
|
|
||||||
|
router.get('/paypal/subscribe', user.paypalSubscribe);
|
||||||
|
router.get('/paypal/subscribe/success', user.paypalSubscribeSuccess);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
@ -147,6 +147,8 @@ script(id='partials/options.settings.subscription.html',type='text/ng-template')
|
||||||
div(ng-include="'partials/options.settings.subscription.perks.html'")
|
div(ng-include="'partials/options.settings.subscription.perks.html'")
|
||||||
.btn.btn-primary(ng-click='showStripe(true)')=env.t('subscribe')
|
.btn.btn-primary(ng-click='showStripe(true)')=env.t('subscribe')
|
||||||
//-small.muted PayPal coming soon.
|
//-small.muted PayPal coming soon.
|
||||||
|
//a.btn.btn-warning(ng-click='paypalSubscribe()') PayPal
|
||||||
|
a.btn.btn-warning(href='/paypal/subscribe?uuid={{user._id}}') PayPal
|
||||||
|
|
||||||
div(ng-if='user.purchased.plan.customerId')
|
div(ng-if='user.purchased.plan.customerId')
|
||||||
.well
|
.well
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue