From cc4812712a2a29e742db4ea5301bd7ce4faa0c84 Mon Sep 17 00:00:00 2001 From: Negue Date: Sun, 23 Nov 2014 01:50:03 +0100 Subject: [PATCH] dummy iap verify routes --- config.json.example | 3 +- src/controllers/payments/iap.js | 63 +++++++++++++++++++++++++++++++ src/controllers/payments/index.js | 7 +++- src/routes/payments.js | 3 ++ 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 src/controllers/payments/iap.js diff --git a/config.json.example b/config.json.example index d8bb67b62e..caedcf3ae9 100644 --- a/config.json.example +++ b/config.json.example @@ -41,5 +41,6 @@ "mode":"sandbox", "client_id":"client_id", "client_secret":"client_secret" - } + }, + "IAP_GOOGLE_KEYDIR": "/path/to/google/public/key/dir/" } diff --git a/src/controllers/payments/iap.js b/src/controllers/payments/iap.js new file mode 100644 index 0000000000..f4c91b663f --- /dev/null +++ b/src/controllers/payments/iap.js @@ -0,0 +1,63 @@ +var iap = require('in-app-purchase'); +var async = require('async'); +var payments = require('./index'); + +/* +For google iap, you need to name your public key file as: +iap-sanbox or iap-live +*/ +iap.config({ + googlePublicKeyPath: "/path/to/google/public/key/dir/" +}); + +exports.androidVerify = function(req, res, next) { + console.info(req.body); + + var token = req.body.id; + var user = res.locals.user; + +iap.setup(function (error) { + if (error) { + console.error('something went wrong...'); + console.error(error); + + return; + } + /* + google receipt must be provided as an object + { + "data": "{stringified data object}", + "signature": "signature from google" + } + */ + // iap is ready + /*iap.validate(iap.GOOGLE, googleReceipt, function (err, googleRes) { + if (err) { + return console.error(err); + } + if (iap.isValidated(googleRes)) { + // yay good! + } + });*/ +}); + +/* + async.waterfall([ + function(response, cb) { + payments.buyGems(user, {customerId: response.id, paymentMethod: 'IAP'}); + + user.save(cb); + } + ], function(err, saved){ + if (err) return res.send(500, err.toString()); // don't json this, let toString() handle errors + res.send(200); + user = token = null; + });*/ +}; + +exports.iosVerify = function(req, res, next) { + console.info(req.body); + + var token = req.body.id; + var user = res.locals.user; +}; \ No newline at end of file diff --git a/src/controllers/payments/index.js b/src/controllers/payments/index.js index 176098b4c5..b0c59f643c 100644 --- a/src/controllers/payments/index.js +++ b/src/controllers/payments/index.js @@ -7,9 +7,9 @@ var moment = require('moment'); var isProduction = nconf.get("NODE_ENV") === "production"; var stripe = require('./stripe'); var paypal = require('./paypal'); -var User = require('mongoose').model('User'); var members = require('../members') var async = require('async'); +var iap = require('./iap'); function revealMysteryItems(user) { _.each(shared.content.gear.flat, function(item) { @@ -123,4 +123,7 @@ exports.paypalSubscribeSuccess = paypal.executeBillingAgreement; exports.paypalSubscribeCancel = paypal.cancelSubscription; exports.paypalCheckout = paypal.createPayment; exports.paypalCheckoutSuccess = paypal.executePayment; -exports.paypalIPN = paypal.ipn; \ No newline at end of file +exports.paypalIPN = paypal.ipn; + +exports.iapAndroidVerify = iap.androidVerify; +exports.iapIosVerify = iap.iosVerify; diff --git a/src/routes/payments.js b/src/routes/payments.js index c34d77b24b..8cd6b37ef7 100644 --- a/src/routes/payments.js +++ b/src/routes/payments.js @@ -17,4 +17,7 @@ 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("/iap/android/verify", auth.authWithUrl, i18n.getUserLanguage, payments.iapAndroidVerify); +router.post("/iap/ios/verify", auth.authWithUrl, i18n.getUserLanguage, payments.iapIosVerify); + module.exports = router; \ No newline at end of file