feat(amazon-payments): WIP add donations

This commit is contained in:
Matteo Pagliazzi 2015-07-05 20:49:42 +02:00
parent 8a97b597f5
commit de32461787
4 changed files with 25 additions and 19 deletions

View file

@ -29,15 +29,34 @@ exports.verifyAccessToken = function(req, res, next){
});
};
exports.createOrderReferenceId = function(req, res, next){
if(!req.body || !req.body.billingAgreementId){
return res.json(400, {err: 'Billing Agreement Id not supplied.'});
}
amzPayment.offAmazonPayments.createOrderReferenceForId({
Id: req.body.billingAgreementId,
IdType: 'BillingAgreement'
}, function(err, response){
if(err) return next(err);
if(!response.OrderReferenceDetails || !response.OrderReferenceDetails.AmazonOrderReferenceId){
return next(new Error('Missing attributes in Amazon response.'));
}
res.json({
orderReferenceId: response.OrderReferenceDetails.AmazonOrderReferenceId
});
});
};
exports.checkout = function(req, res, next){
if(!req.body || !req.body['billingAgreementId']){
if(!req.body || !req.body.orderReferenceId){
return res.json(400, {err: 'Billing Agreement Id not supplied.'});
}
var gift = req.body.gift;
var user = res.locals.user;
var billingAgreementId = req.body.billingAgreementId;
var orderReferenceId;
var orderReferenceId = req.body.orderReferenceId;
var amount = 5;
if(gift){
@ -49,21 +68,6 @@ exports.checkout = function(req, res, next){
}
async.series({
createOrderReferenceForId: function(cb){
amzPayment.offAmazonPayments.createOrderReferenceForId({
Id: billingAgreementId,
IdType: 'BillingAgreement'
}, function(err, response){
if(err) return cb(err);
if(!response.OrderReferenceDetails || !response.OrderReferenceDetails.AmazonOrderReferenceId){
return cb('Missing attributes in Amazon response.');
}
orderReferenceId = response.OrderReferenceDetails.AmazonOrderReferenceId;
return cb();
});
},
setOrderReferenceDetails: function(cb){
amzPayment.offAmazonPayments.setOrderReferenceDetails({
AmazonOrderReferenceId: orderReferenceId,

View file

@ -174,6 +174,7 @@ exports.paypalCheckoutSuccess = paypal.executePayment;
exports.paypalIPN = paypal.ipn;
exports.amazonVerifyAccessToken = amazon.verifyAccessToken;
exports.amazonCreateOrderReferenceId = amazon.createOrderReferenceId;
exports.amazonCheckout = amazon.checkout;
exports.amazonSubscribe = amazon.subscribe;
exports.amazonSubscribeCancel = amazon.subscribeCancel;

View file

@ -18,6 +18,7 @@ router.post("/stripe/subscribe/edit", auth.auth, i18n.getUserLanguage, payments.
router.get("/stripe/subscribe/cancel", auth.authWithUrl, i18n.getUserLanguage, payments.stripeSubscribeCancel);
router.post('/amazon/verifyAccessToken', auth.auth, i18n.getUserLanguage, payments.amazonVerifyAccessToken);
router.post('/amazon/createOrderReferenceId', auth.auth, i18n.getUserLanguage, payments.amazonCreateOrderReferenceId);
router.post('/amazon/checkout', auth.auth, i18n.getUserLanguage, payments.amazonCheckout);
router.post('/amazon/subscribe', auth.auth, i18n.getUserLanguage, payments.amazonSubscribe);
router.get('/amazon/subscribe/cancel', auth.authWithUrl, i18n.getUserLanguage, payments.amazonSubscribeCancel);

View file

@ -22,7 +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
//.btn.btn-default(ng-click="Payments.amazonPayments.init({type: 'donation'})") Amazon Payments
.btn.btn-default(ng-click="Payments.amazonPayments.init({type: 'donation'})") Amazon Payments
div(ng-include="'partials/options.settings.subscription.html'")