mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
wip amazon payments
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
"version": "0.0.0-152",
|
"version": "0.0.0-152",
|
||||||
"main": "./website/src/server.js",
|
"main": "./website/src/server.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"amazon-payments": "0.0.4",
|
||||||
"async": "~0.9.0",
|
"async": "~0.9.0",
|
||||||
"aws-sdk": "^2.0.25",
|
"aws-sdk": "^2.0.25",
|
||||||
"babel": "^5.5.4",
|
"babel": "^5.5.4",
|
||||||
|
|||||||
@@ -20,14 +20,11 @@ function($scope, $rootScope, User, $http, Notification, ApiUrl) {
|
|||||||
JS files not needed right away (google charts) or entirely optional (analytics)
|
JS files not needed right away (google charts) or entirely optional (analytics)
|
||||||
Each file gets loaded async via $.getScript, so it doesn't bog page-load
|
Each file gets loaded async via $.getScript, so it doesn't bog page-load
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$scope.deferredScripts = function(){
|
$scope.deferredScripts = function(){
|
||||||
|
|
||||||
// Amazon Payments
|
// Amazon Payments
|
||||||
$.getScript('https://static-na.payments-amazon.com/OffAmazonPayments/us/sandbox/js/Widgets.js?sellerId=' + window.env.AMAZON_PAYMENTS.SELLER_ID, function(){
|
$.getScript('https://static-na.payments-amazon.com/OffAmazonPayments/us/sandbox/js/Widgets.js');
|
||||||
window.onAmazonLoginReady = function() {
|
|
||||||
amazon.Login.setClientId(window.env.AMAZON_PAYMENTS.CLIENT_ID);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// Stripe
|
// Stripe
|
||||||
$.getScript('//checkout.stripe.com/v2/checkout.js');
|
$.getScript('//checkout.stripe.com/v2/checkout.js');
|
||||||
|
|||||||
@@ -4,6 +4,12 @@ angular.module('habitrpg').factory('Payments',
|
|||||||
['$rootScope', 'User', '$http', 'Content',
|
['$rootScope', 'User', '$http', 'Content',
|
||||||
function($rootScope, User, $http, Content) {
|
function($rootScope, User, $http, Content) {
|
||||||
var Payments = {};
|
var Payments = {};
|
||||||
|
var isAmazonReady = false;
|
||||||
|
|
||||||
|
window.onAmazonLoginReady = function(){
|
||||||
|
isAmazonReady = true;
|
||||||
|
amazon.Login.setClientId(window.env.AMAZON_PAYMENTS.CLIENT_ID);
|
||||||
|
};
|
||||||
|
|
||||||
Payments.showStripe = function(data) {
|
Payments.showStripe = function(data) {
|
||||||
var sub =
|
var sub =
|
||||||
@@ -55,6 +61,42 @@ function($rootScope, User, $http, Content) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Needs to be called everytime the modal/router is accessed
|
||||||
|
Payments.initAmazonDonation = function(){
|
||||||
|
if(!isAmazonReady) return;
|
||||||
|
|
||||||
|
OffAmazonPayments.Button('AmazonPayButtonDonation', window.env.AMAZON_PAYMENTS.SELLER_ID, {
|
||||||
|
type: 'PwA',
|
||||||
|
color: 'Gold',
|
||||||
|
size: 'small',
|
||||||
|
|
||||||
|
authorization: function(){
|
||||||
|
amazon.Login.authorize({
|
||||||
|
scope: 'payments:widget',
|
||||||
|
popup: true
|
||||||
|
}, function(response){
|
||||||
|
if(response.error) return alert(response.error);
|
||||||
|
|
||||||
|
var url = '/amazon/verifyAccessToken'
|
||||||
|
$http.post(url, response).success(function(){
|
||||||
|
console.log(arguments);
|
||||||
|
}).error(function(res){
|
||||||
|
alert(res.err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onError: function(error) {
|
||||||
|
console.error('amazon error ', error)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Needs to be called everytime the modal/router is accessed
|
||||||
|
Payments.initAmazonSubscription = function(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Payments.cancelSubscription = function(){
|
Payments.cancelSubscription = function(){
|
||||||
if (!confirm(window.env.t('sureCancelSub'))) return;
|
if (!confirm(window.env.t('sureCancelSub'))) return;
|
||||||
window.location.href = '/' + User.user.purchased.plan.paymentMethod.toLowerCase() + '/subscribe/cancel?_id=' + User.user._id + '&apiToken=' + User.user.apiToken;
|
window.location.href = '/' + User.user.purchased.plan.paymentMethod.toLowerCase() + '/subscribe/cancel?_id=' + User.user._id + '&apiToken=' + User.user.apiToken;
|
||||||
|
|||||||
13
website/src/controllers/payments/amazon.js
Normal file
13
website/src/controllers/payments/amazon.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
var amazonPayments = require('amazon-payments');
|
||||||
|
|
||||||
|
var payment = amazonPayments.connect({
|
||||||
|
environment: amazonPayments.Environment.Production,
|
||||||
|
sellerId: 'Amazon Seller ID',
|
||||||
|
mwsAccessKey: 'MWS Access Key',
|
||||||
|
mwsSecretKey: 'MWS Secret Key',
|
||||||
|
clientId: 'Client ID'
|
||||||
|
});
|
||||||
|
|
||||||
|
exports.verifyAccessToken = function(req, res, next){
|
||||||
|
|
||||||
|
};
|
||||||
@@ -12,6 +12,8 @@ router.get('/', i18n.getUserLanguage, middleware.locals, function(req, res) {
|
|||||||
if (!req.headers['x-api-user'] && !req.headers['x-api-key'] && !(req.session && req.session.userId))
|
if (!req.headers['x-api-user'] && !req.headers['x-api-key'] && !(req.session && req.session.userId))
|
||||||
return res.redirect('/static/front')
|
return res.redirect('/static/front')
|
||||||
|
|
||||||
|
console.log('Starting to render');
|
||||||
|
|
||||||
return res.render('index', {
|
return res.render('index', {
|
||||||
title: 'HabitRPG | Your Life, The Role Playing Game',
|
title: 'HabitRPG | Your Life, The Role Playing Game',
|
||||||
env: res.locals.habitrpg
|
env: res.locals.habitrpg
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ if (cores!==0 && cluster.isMaster && (isDev || isProd)) {
|
|||||||
app.use(express.compress());
|
app.use(express.compress());
|
||||||
app.set("views", __dirname + "/../views");
|
app.set("views", __dirname + "/../views");
|
||||||
app.set("view engine", "jade");
|
app.set("view engine", "jade");
|
||||||
|
app.set("view cache", true);
|
||||||
app.use(express.favicon(publicDir + '/favicon.ico'));
|
app.use(express.favicon(publicDir + '/favicon.ico'));
|
||||||
app.use(middleware.cors);
|
app.use(middleware.cors);
|
||||||
app.use(middleware.forceSSL);
|
app.use(middleware.forceSSL);
|
||||||
|
|||||||
@@ -22,24 +22,7 @@ script(id='modals/buyGems.html', type='text/ng-template')
|
|||||||
small.muted=env.t('paymentMethods')
|
small.muted=env.t('paymentMethods')
|
||||||
.btn.btn-primary(ng-click='Payments.showStripe({})')=env.t('card')
|
.btn.btn-primary(ng-click='Payments.showStripe({})')=env.t('card')
|
||||||
a.btn.btn-warning(href='/paypal/checkout?_id={{user._id}}&apiToken={{user.apiToken}}') PayPal
|
a.btn.btn-warning(href='/paypal/checkout?_id={{user._id}}&apiToken={{user.apiToken}}') PayPal
|
||||||
div#AmazonPayButton
|
div#AmazonPayButtonDonation(ng-init="Payments.initAmazonDonation()")
|
||||||
script(type='text/javascript').
|
|
||||||
var authRequest;
|
|
||||||
OffAmazonPayments.Button('AmazonPayButton', window.env.AMAZON_PAYMENTS.SELLER_ID, {
|
|
||||||
type: 'PwA',
|
|
||||||
color: 'Gold',
|
|
||||||
size: 'small',
|
|
||||||
|
|
||||||
authorization: function() {
|
|
||||||
loginOptions =
|
|
||||||
{scope: 'payments:widget', popup: true};
|
|
||||||
authRequest = amazon.Login.authorize (loginOptions,
|
|
||||||
'https://habitrpg.com');
|
|
||||||
},
|
|
||||||
onError: function(error) {
|
|
||||||
console.error('amazon payments error ', error)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
div(ng-include="'partials/options.settings.subscription.html'")
|
div(ng-include="'partials/options.settings.subscription.html'")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user