feat(amazon-payments): wip on donations
This commit is contained in:
+3
-1
@@ -26,7 +26,9 @@
|
||||
"AMAZON_PAYMENTS_CLIENT_ID": "AMAZON_PAYMENTS_CLIENT_ID",
|
||||
"AMAZON_PAYMENTS": {
|
||||
"SELLER_ID": "SELLER_ID",
|
||||
"CLIENT_ID": "CLIENT_ID"
|
||||
"CLIENT_ID": "CLIENT_ID",
|
||||
"MWS_KEY": "",
|
||||
"MWS_SECRET": ""
|
||||
},
|
||||
"FLAG_REPORT_EMAIL": ["email@mod.com"],
|
||||
"EMAIL_SERVER": {
|
||||
|
||||
@@ -79,7 +79,8 @@ function($rootScope, User, $http, Content) {
|
||||
|
||||
var url = '/amazon/verifyAccessToken'
|
||||
$http.post(url, response).success(function(){
|
||||
console.log(arguments);
|
||||
Payments.amazonDonationLoggedIn = true;
|
||||
Payments.amazonDonationInitWidgets();
|
||||
}).error(function(res){
|
||||
alert(res.err);
|
||||
});
|
||||
@@ -87,11 +88,44 @@ function($rootScope, User, $http, Content) {
|
||||
},
|
||||
|
||||
onError: function(error) {
|
||||
console.error('amazon error ', error)
|
||||
console.error('amazon error ', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Payments.amazonDonationLoggedIn = false;
|
||||
Payments.amazonDonationPaymentSelected = false;
|
||||
Payments.amazonDonationOrderReferenceId;
|
||||
|
||||
Payments.amazonDonationInitWidgets = function(){
|
||||
new OffAmazonPayments.Widgets.Wallet({
|
||||
sellerId: window.env.AMAZON_PAYMENTS.SELLER_ID,
|
||||
onOrderReferenceCreate: function(orderReference) {
|
||||
Payments.amazonDonationOrderReferenceId = orderReference.getAmazonOrderReferenceId();
|
||||
},
|
||||
onPaymentSelect: function(orderReference) {
|
||||
$rootScope.$apply(function(){
|
||||
Payments.amazonDonationPaymentSelected = true;
|
||||
});
|
||||
},
|
||||
design: {
|
||||
designMode: 'responsive'
|
||||
},
|
||||
onError: function(error) {
|
||||
console.error('amazon error ', error.getErrorMessage());
|
||||
}
|
||||
}).bind('AmazonPayWalletDonation');
|
||||
}
|
||||
|
||||
Payments.amazonDonationCheckout = function(){
|
||||
var url = '/amazon/checkout'
|
||||
$http.post(url, {orderReferenceId: Payments.amazonDonationOrderReferenceId}).success(function(){
|
||||
console.log(arguments);
|
||||
}).error(function(res){
|
||||
alert(res.err);
|
||||
});
|
||||
}
|
||||
|
||||
// Needs to be called everytime the modal/router is accessed
|
||||
Payments.initAmazonSubscription = function(){
|
||||
|
||||
|
||||
@@ -1,13 +1,59 @@
|
||||
var amazonPayments = require('amazon-payments');
|
||||
var nconf = require('nconf');
|
||||
var async = require('async');
|
||||
var isProd = nconf.get("NODE_ENV") === 'production';
|
||||
|
||||
var payment = amazonPayments.connect({
|
||||
environment: amazonPayments.Environment.Production,
|
||||
sellerId: 'Amazon Seller ID',
|
||||
mwsAccessKey: 'MWS Access Key',
|
||||
mwsSecretKey: 'MWS Secret Key',
|
||||
clientId: 'Client ID'
|
||||
environment: amazonPayments.Environment.Sandbox,
|
||||
sellerId: nconf.get('AMAZON_PAYMENTS:SELLER_ID'),
|
||||
mwsAccessKey: nconf.get('AMAZON_PAYMENTS:MWS_KEY'),
|
||||
mwsSecretKey: nconf.get('AMAZON_PAYMENTS:MWS_SECRET'),
|
||||
clientId: nconf.get('AMAZON_PAYMENTS:CLIENT_ID')
|
||||
});
|
||||
|
||||
exports.verifyAccessToken = function(req, res, next){
|
||||
if(!req.body || !req.body['access_token']){
|
||||
return res.json(400, {err: 'Access token not supplied.'});
|
||||
}
|
||||
|
||||
payment.api.getTokenInfo(req.body['access_token'], function(err, tokenInfo){
|
||||
if(err) return next(err);
|
||||
|
||||
res.send(200);
|
||||
});
|
||||
};
|
||||
|
||||
exports.checkout = function(req, res, next){
|
||||
if(!req.body || !req.body['orderReferenceId']){
|
||||
return res.json(400, {err: 'Order Reference Id not supplied.'});
|
||||
}
|
||||
|
||||
async.series({
|
||||
setOrderReferenceDetails: function(cb){
|
||||
payment.offAmazonPayments.setOrderReferenceDetails({
|
||||
|
||||
}, cb);
|
||||
},
|
||||
|
||||
confirmOrderReference: function(cb){
|
||||
payment.offAmazonPayments.confirmOrderReference({
|
||||
|
||||
}, cb);
|
||||
},
|
||||
|
||||
authorize: function(cb){
|
||||
payment.offAmazonPayments.authorize({
|
||||
|
||||
}, cb);
|
||||
},
|
||||
|
||||
closeOrderReference: function(cb){
|
||||
payment.offAmazonPayments.closeOrderReference({
|
||||
|
||||
}, cb);
|
||||
}
|
||||
}, function(err, results){
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
@@ -7,6 +7,7 @@ var moment = require('moment');
|
||||
var isProduction = nconf.get("NODE_ENV") === "production";
|
||||
var stripe = require('./stripe');
|
||||
var paypal = require('./paypal');
|
||||
var amazon = require('./amazon');
|
||||
var members = require('../members')
|
||||
var async = require('async');
|
||||
var iap = require('./iap');
|
||||
@@ -169,5 +170,7 @@ exports.paypalCheckout = paypal.createPayment;
|
||||
exports.paypalCheckoutSuccess = paypal.executePayment;
|
||||
exports.paypalIPN = paypal.ipn;
|
||||
|
||||
exports.amazonVerifyAccessToken = amazon.verifyAccessToken;
|
||||
|
||||
exports.iapAndroidVerify = iap.androidVerify;
|
||||
exports.iapIosVerify = iap.iosVerify;
|
||||
|
||||
@@ -12,8 +12,6 @@ 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
|
||||
|
||||
@@ -17,6 +17,8 @@ router.post("/stripe/subscribe/edit", auth.auth, i18n.getUserLanguage, payments.
|
||||
//router.get("/stripe/subscribe", auth.authWithUrl, i18n.getUserLanguage, payments.stripeSubscribe); // checkout route is used (above) with ?plan= instead
|
||||
router.get("/stripe/subscribe/cancel", auth.authWithUrl, i18n.getUserLanguage, payments.stripeSubscribeCancel);
|
||||
|
||||
router.post('/amazon/verifyAccessToken', auth.auth, i18n.getUserLanguage, payments.amazonVerifyAccessToken);
|
||||
|
||||
router.post("/iap/android/verify", auth.authWithUrl, /*i18n.getUserLanguage, */payments.iapAndroidVerify);
|
||||
router.post("/iap/ios/verify", auth.auth, /*i18n.getUserLanguage, */ payments.iapIosVerify);
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ script(id='modals/buyGems.html', type='text/ng-template')
|
||||
.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#AmazonPayButtonDonation(ng-init="Payments.initAmazonDonation()")
|
||||
|
||||
div#AmazonPayWalletDonation(ng-show="Payments.amazonDonationLoggedIn", style="width: 400px; height: 228px;")
|
||||
a.btn.btn-warning(ng-show="Payments.amazonDonationPaymentSelected", ng-click="Payments.amazonDonationCheckout()") Checkout
|
||||
|
||||
div(ng-include="'partials/options.settings.subscription.html'")
|
||||
|
||||
.modal-footer
|
||||
|
||||
Reference in New Issue
Block a user