wip amazon payments

This commit is contained in:
Matteo Pagliazzi
2015-06-08 18:55:15 +02:00
parent b0643e7177
commit 6faef6f737
7 changed files with 62 additions and 23 deletions

View File

@@ -4,6 +4,7 @@
"version": "0.0.0-152",
"main": "./website/src/server.js",
"dependencies": {
"amazon-payments": "0.0.4",
"async": "~0.9.0",
"aws-sdk": "^2.0.25",
"babel": "^5.5.4",

View File

@@ -20,14 +20,11 @@ function($scope, $rootScope, User, $http, Notification, ApiUrl) {
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
*/
$scope.deferredScripts = function(){
// Amazon Payments
$.getScript('https://static-na.payments-amazon.com/OffAmazonPayments/us/sandbox/js/Widgets.js?sellerId=' + window.env.AMAZON_PAYMENTS.SELLER_ID, function(){
window.onAmazonLoginReady = function() {
amazon.Login.setClientId(window.env.AMAZON_PAYMENTS.CLIENT_ID);
};
});
$.getScript('https://static-na.payments-amazon.com/OffAmazonPayments/us/sandbox/js/Widgets.js');
// Stripe
$.getScript('//checkout.stripe.com/v2/checkout.js');

View File

@@ -4,6 +4,12 @@ angular.module('habitrpg').factory('Payments',
['$rootScope', 'User', '$http', 'Content',
function($rootScope, User, $http, Content) {
var Payments = {};
var isAmazonReady = false;
window.onAmazonLoginReady = function(){
isAmazonReady = true;
amazon.Login.setClientId(window.env.AMAZON_PAYMENTS.CLIENT_ID);
};
Payments.showStripe = function(data) {
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(){
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;

View 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){
};

View File

@@ -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))
return res.redirect('/static/front')
console.log('Starting to render');
return res.render('index', {
title: 'HabitRPG | Your Life, The Role Playing Game',
env: res.locals.habitrpg

View File

@@ -95,6 +95,7 @@ if (cores!==0 && cluster.isMaster && (isDev || isProd)) {
app.use(express.compress());
app.set("views", __dirname + "/../views");
app.set("view engine", "jade");
app.set("view cache", true);
app.use(express.favicon(publicDir + '/favicon.ico'));
app.use(middleware.cors);
app.use(middleware.forceSSL);

View File

@@ -22,24 +22,7 @@ script(id='modals/buyGems.html', type='text/ng-template')
small.muted=env.t('paymentMethods')
.btn.btn-primary(ng-click='Payments.showStripe({})')=env.t('card')
a.btn.btn-warning(href='/paypal/checkout?_id={{user._id}}&apiToken={{user.apiToken}}') PayPal
div#AmazonPayButton
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#AmazonPayButtonDonation(ng-init="Payments.initAmazonDonation()")
div(ng-include="'partials/options.settings.subscription.html'")