'use strict'; const request = require('request'); const db = require('../app/db') const logger = require('../app/logger'); //const User = require("../app/model/cardModel.js"); const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); var cards = { createCard: async function (req, res, next) { try { //logger.info(req.query); logger.info(req.body); var data = { "request_uid": req.body.request_uid, "request_id": req.body.request_id, }; let Qstring = " SELECT r.*,m.firstname,m.lastname FROM members_card_request r " + " LEFT JOIN members m ON m.id=r.member_id " + " WHERE r.uid::text = '" + data.request_uid +"'"; logger.info(Qstring); db.query(Qstring, async function (err, result) { try { if (err) throw err; const cardholder = await stripe.issuing.cardholders.create({ name: 'Jenny Rosen', email: 'jenny.rosen@example.com', phone_number: '+18008675309', status: 'active', type: 'individual', individual: { first_name: 'Jenny', last_name: 'Rosen', dob: {day: 1, month: 11, year: 1981}, }, billing: { address: { line1: '123 Main Street', city: 'San Francisco', state: 'CA', postal_code: '94111', country: 'US', }, }, }); console.log(cardholder); let resultItem = { "result": cardholder, "total_record": 0 } next(null, resultItem); // pass control to the next handler } catch (e) { next(e.message, null); // pass control to the next handler } }); // // const cardholder = await stripe.issuing.cardholders.create({ // name: 'Jenny Rosen', // email: 'jenny.rosen@example.com', // phone_number: '+18008675309', // status: 'active', // type: 'individual', // individual: { // first_name: 'Jenny', // last_name: 'Rosen', // dob: {day: 1, month: 11, year: 1981}, // }, // billing: { // address: { // line1: '123 Main Street', // city: 'San Francisco', // state: 'CA', // postal_code: '94111', // country: 'US', // }, // }, // }); // console.log(cardholder); // let resultItem = { // "result":cardholder, // "total_record":0 // } // next(null, resultItem); // pass control to the next handler // res.status(200).json(saveUser); } catch (error) { await res.status(500).json({error: `Internal Server error 002 ${error} `}); } // let resultItem ={ // "result": bannerArray, // "total_record": 4 // } // next(null, resultItem ); // pass control to the next handler }, activateCard: function (req, res, next) { let resultItem ={ "result": [], "total_record": 5 } next(null, resultItem ); // pass control to the next handler }, }; module.exports = cards;