diff --git a/api/controller/cardsController.js b/api/controller/cardsController.js index 97b3ab1..1df264f 100644 --- a/api/controller/cardsController.js +++ b/api/controller/cardsController.js @@ -6,8 +6,8 @@ const cards = require('../../service/cards.js'); //const logger = require('../../app/logger'); const cardsControllers = { - createApplications: function(req, res){ - cards.createApplications(req, res, function (err, result) { + cardApplications: function(req, res){ + cards.cardApplications(req, res, function (err, result) { res.status(200).json({ 'status': 'OK', 'internal_return': 0, @@ -30,6 +30,18 @@ const cardsControllers = { console.log(r); }); }, + retrieveCard: function (req, res) { + cards.retrieveCard(req, res, function (err, result) { + res.status(200).json({ + 'status': 'OK', + 'internal_return': 0, + 'result_list': result.result, + 'total_record': result.total_record + }) + }).then(r =>{ + console.log(r); + }); + }, createCard: function (req, res) { cards.createCard(req, res, function (err, result) { res.status(200).json({ @@ -42,6 +54,30 @@ const cardsControllers = { console.log(r); }); }, + createCardWallet: function (req, res){ + cards.createCardWallet(req, res, function (err, dist) { + if (err) { + res.send(err); + } + res.status(200).json({ + 'status': 'OK', + 'result': dist, + 'internal_return': 0, + }) + }); + }, + listCards: function (req, res){ + cards.acceptCardTerms(req, res, function (err, dist) { + if (err) { + res.send(err); + } + res.status(200).json({ + 'status': 'OK', + 'result': dist, + 'internal_return': 0, + }) + }); + }, acceptCardTerms: function (req, res){ cards.acceptCardTerms(req, res, function (err, dist) { if (err) { diff --git a/api/routes/route.js b/api/routes/route.js index 04c6e27..17ddb9b 100644 --- a/api/routes/route.js +++ b/api/routes/route.js @@ -5,7 +5,7 @@ const cardsControllers = require('../controller/cardsController.js'); module.exports = function(app) { app.route('/cardapplications') - .post(cardsControllers.createApplications); + .post(cardsControllers.cardApplications); app.route('/createCardHolder') .post(cardsControllers.createCardHolder); app.route('/acceptterms') @@ -14,10 +14,12 @@ module.exports = function(app) { .post(cardsControllers.createCard); app.route('/activate') .post(cardsControllers.activateCard); - - app.route('/create') - .post(cardsControllers.acceptCardTerms); - + app.route('/cardwallet') + .post(cardsControllers.createCardWallet); + app.route('/listcards') + .post(cardsControllers.listCards); + app.route('/retrievecard') + .post(cardsControllers.retrieveCard); // app.route('/eventSendMoney') // .post(controller.activateCard); diff --git a/service/cards.js b/service/cards.js index 51145ef..b9088cc 100644 --- a/service/cards.js +++ b/service/cards.js @@ -9,11 +9,34 @@ const CARD_HOLDER_CREATED = 10; const CARD_OWNER_ACTIVE = 30; const CARD_ASSIGNED = 40; const CARD_ACTIVATE_CARD = 50; - +const CARD_WALLET_ADD = 60; //const User = require("../app/model/cardModel.js"); const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); var cards = { - createApplications: async function(req, res, next){ + createCardWallet: function(req, res, next){ + try { + logger.info(req.body); + var data = { + "request_uid": req.body.request_uid, + "request_id": req.body.request_id, + }; + let Qstring = " SELECT id AS request_id, uid AS request_uid, * FROM members_card_request WHERE status = "+CARD_ACTIVATE_CARD+" AND id="+data.request_id+" AND uid='"+data.request_uid+"' "; + logger.info(Qstring); + db.query(Qstring, async function (err, result) { + + if (err) throw err; + logger.info(result.rows); + let resultItem ={ + "result": result.rows, + "total_record": result.rows.length + } + next(null, resultItem); // pass control to the next handler + }); + } catch (error) { + res.status(500).json({error: `Internal Server error 002 ${error} `}); + } + }, + cardApplications: async function(req, res, next){ try { logger.info(req.body); var data = { @@ -154,6 +177,43 @@ var cards = { await res.status(500).json({error: `Internal Server error 002 ${error} `}); } }, + retrieveCard: async function (req, res, next) { + try { + logger.info(req.body); + var data = { + "member_id": req.body.member_id, + "wallet_id": req.body.wallet_id, + }; + + let Qstring = " SELECT card_last4,card_issue_id,card_id FROM members_wallet WHERE member_id= " + data.member_id +" AND id = " + data.wallet_id +" AND card_last4 IS NOT NULL"; + logger.info(Qstring); + db.query(Qstring, async function (err, result) { + try { + if (err) throw err; +// , , + const req_data = { + "card_id": result.rows[0].card_id.toString(), + "card_issue_id": result.rows[0].card_issue_id.toString(), + }; + + const card = await stripe.issuing.cards.retrieve('ic_1MvSieLkdIwHu7ixn6uuO0Xu'); + stripe.issuing.cards.retrieve(req_data.card_id).then((card)=>{ + let resultItem = { + "card": card, + "total_record": 0 + } + next(null, resultItem); // pass control to the next handler + }); + + } catch (e) { + next(e.message, null); // pass control to the next handler + } + }); + + } catch (error) { + await res.status(500).json({error: `Internal Server error 002 ${error} `}); + } + }, createCard: async function (req, res, next) { try { logger.info(req.body);