app.post('/api/pay_for_palns_credit_card', function(req, res) {
console.log(req.body);
db = req.db;
var email = 'admin#qhop.com';
var amount = req.body.amount;
var firstname = req.body.firstname;
var lastname = req.body.lastname;
var cardtype = req.body.cardtype;
var cardnumber = req.body.cardnumber;
var expiremonth = req.body.expiremonth;
var expireyear = req.body.expireyear;
var cvv = req.body.cvv;
var payer = req.body.email;
var collection = db.get('paymentscollections');
var Paypal = require('paypal-adaptive');
var paypalSdk = new Paypal({
userId: 'id',
password: 'password',
signature: 'signatures',
sandbox: true //defaults to false
});
var payload = {
requestEnvelope: {
errorLanguage: 'en_US'
},
actionType: 'PAY',
currencyCode: 'USD',
feesPayer: payer,
memo: 'this is a test',
cancelUrl: 'http://test.com/cancel',
returnUrl: 'http://test.com/success',
receiverList: {
receiver: [{
email: email,
amount: amount,
primary: 'false'
}]
}
};
paypalSdk.pay(payload, function(err, response) {
console.log(payload);
if (err) {
console.log('in here');
console.log(err);
res.send(err);
} else {
collection.insert({
payload
}, function(err, doc) {
if (err) {
console.log(err);
// If it failed, return error
res.send(err);
} else {
console.log(doc);
res.send(doc);
}
});
}
});
});
I am getting the following error while using paypaladaptive.
These are all the details I have of error.
Error: Response ack is Failure. Check the response for more info.
at IncomingMessage. (D:\Qhoppaypal1\node_modules\paypal-adaptive\
Related
**model schema**
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var item = new Schema({
name:{type: String,
required: true},
price:{type: String}
})
var object=new Schema({
name:{type: String,
required: true},
items: [item]
});
api.js, posting data to server
router.post('/objectss', function(req, res){
var object= new Object(); **
how can i save array of objects in array
**
object.items.push({firstName: req.body.fname, lastName: req.body.lname});
object.name = req.body.name;
object.save(function (err) {
if(err) throw err;
res.json({success: true, message:'allahuakbar'});
});
// saved!
});
angularjs controller
$scope.addProduct = function(){
$scope.items.push({
fname: $scope.item.fname,
lname: $scope.item.lname
});
$scope.item = {};
}
$scope.submitx = function(inv, item){
console.log(inv);
var object = {
name:inv.name,
fname:items.fname,
totalValue: 0
}
PostBlog.createInvoice(objects).then(function(data){
console.log(data);
});
$scope.objects= {};
}
please see this code and help me! struggling over weeks . there is array of object like a["name":carrot, "price":24, "":, etc]
those who get stuck refer to this instead of using method
router.post('/invoices', function(req, res){ //by making route in from
var invoice = new Invoice();
for (var i = 0; i < req.body.length; i++) {
invoice.items.push({name:req.body.fname[i].fname});
}
invoice.name = req.body.name;
//invoice.items.insertMany(items, function(error, next) {
invoice.save(function (err) {
if(err) throw err;
res.json({success: true, message:'allahuakbar'});
});
// saved!
});
i want to get the object from my collection based on the quesListName which i send as a param to the server
here is my service
angular.module('hrPortalApp')
.service('getCandidateInterviewListService', function($http, ajaxServiceManager) {
var sUrlQuestions = "http://localhost:4000/onboardvue/questions/qListQuestions/";
return {
fnGetQuestions: function(qListName) {
return ajaxServiceManager.fnQuery({
sUrl: sUrlQuestions,
sMethod: "GET",
oData: null,
oParams: {
quesListName: qListName
}
});
},
};
});
below is my schema
var QuestionsSchema = new Schema({
topicName: String,
quesListName: String,
question:String
});
and the query which i wrote to get the object based on quesListName is
exports.query = function(req, res) {
Questions.find({quesListName:req.query.quesListName}, function(err, questions) {
if (err) {
return handleError(res, err);
}
return res.status(200).json(fnData(questions));
});
};
but i am getting 500 error
Right now i am writing data to json file and getting that back to html page to display. Now i want to do same with mongodb Database. I have tried something but, it doesn't working.
app.get('/', function(req, res){
url = 'http://www.amazon.in/Sony-Xperia-Z3-Copper-32GB/dp/B010V448ZC/ref=pd_rhf_se_s_cp_6?ie=UTF8&dpID=419rmomR%2BjL&dpSrc=sims&preST=_SL500_SR135%2C135_&refRID=19RT23W7T48Z99XNT6GK';
request(url, function(error, response, html){
if (!error) {
var $ = cheerio.load(html)
var json = {Product_Name : "", Brand : "", Color : "", Image : "", Price : "", Rating : ""};
var P_name = $('#title').children().text();
var brand = $('#brand').text();
var color = $('.a-row').find('span.selection').text();
var price = $('#price').find('span.a-size-medium').text();
var rating = $('#averageCustomerReviews').find('span.a-icon-alt').text();
var image = $('.imgTagWrapper').children().attr('src');
/*json.Product_Name = P_name;
json.Brand = brand.trim();
json.Color = color.trim();
json.Price = price.trim();
json.Rating = rating.trim();
json.Image = image.trim();
fs.writeFile('output.json', JSON.stringify(json, null, 4), function(err){
console.log('File successfully written! - Check your project directory for the output.json file');
})*/
var insertDocument = function(db, callback) {
db.collection('proInfo').insertOne( {
"Product_Name": P_name,
"Brand":brand,
"Color":color,
"Price":price,
"Rating":rating,
"Image":image
}, function(err, result) {
assert.equal(err, null);
console.log("Inserted a document into the proInfo collection.");
callback(result);
});
};
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
insertDocument(db, function() {
db.close();
});
});
res.send('Check your console!')
} else {
console.log("We’ve encountered an error: " + error);
}
})
})
It shows some error in console.log
D:\Hemanth\Node Js\web scraper\node_modules\mongodb\lib\url_parser.js:20
throw new Error('invalid schema, expected mongodb');
^
Error: invalid schema, expected mongodb
at module.exports
Can anybody help me to fix this issue?
Use module export in your node js routes and define the method inside the module.export as mentioned below :
module.export {}
and then call the method, apply routes in the server.js under node application :
erc(app,
{
controllers: __dirname + '/routes',
routes:{'/methodnametobecalled': { action: 'routesfilename#methodname'}
}
});
Initialize Mongoose and Schema
var mongoose = require('mongoose');
mongoose.connect('mongodb://YOURVALUES.mongolab.com:11111/NAME');
var schema = new mongoose.Schema({ name: 'string', account: 'string', date: 'string' });
var accountz = mongoose.model('accountz', schema);
Create
var small = new accountz({
name: "SAMZ",
account: "Monthly",
date: "29/12/2015"
});
small.save(function (err) {
if (err){
console.log("Error in Save");
}else{
console.log("Save Sucessfully");
}
});
Read
accountz.find().exec(function(err, data){
if (err){
console.log("Error in Reading");
}else{
console.log("The value = " + data);
}
});
Update
accountz.findOne({ "_id": "0023"}, function (err, doc){
doc.name = editObj.name;
doc.account = editObj.account;
doc.date = editObj.date;
doc.save(function (err) {
if (err){
console.log("Error in Updating");
}else{
console.log("Updated Sucessfully");
}
});
});
Delete
accountz.remove({ "_id": "0023"}).exec(function(err, data){
if (err){
console.log("Error in Deleting");
}else{
console.log("Deleting Sucessfully");
}
});
Ref This link https://shiyamexperience.wordpress.com/2015/12/29/mongodb-crud-using-mongoose/
In the view html page there is a form with a table and when i submit the form two objects are created cvm and schedules for form and table. i somehow want schedules(which is an array) to be related to cvm form. so i tried this way...
Here is the defined model
$scope.addSchedule=function(schedule)
{
console.log(schedule.startDate);
console.log(schedule.location);
$scope.schedules.push({
startDate: schedule.startDate,
location: schedule.location
});
schedule.startDate='';
schedule.location='';
};
var inData={'cvm': $scope.cvm,'schedules': $scope.schedules};
$scope.addCvm=function()
{
console.log($scope.cvm);
console.log($scope.schedules);
$http.post('/cvmApi',inData).success(function(response) {
console.log(response);
refresh();
});
};
sever side Connection
i guess somthing i missed in this part
/* POST */
router.post('/', function(req, res, next)
{
console.log("Cvm api post '/'");
console.log("retrieving:: " + req.body);
cvmModel.create(req.body, function (err, post) {
console.log("saving:: " + post);
if (err) return next(err);
res.json(post);
});
});
Here is my schema for mongodb
'use strict';
var mongoose = require('mongoose');
var cvmSchema = new mongoose.Schema({
visitOrganization: { type: String },
visitAgenda: { type: String },
accountManager: { type: String },
visitCoordinator: { type: String },
schedules:[{
startDate: String,
location: String
}]
});
module.exports = mongoose.model('visit', cvmSchema);
plz help !! thanks in advance
I think you should try with below change :
//Change addCvm function
$scope.addCvm = function(){
var inData = $scope.cvm;
inData.schedules = $scope.schedules;
console.log(inData);
$http.post('/cvmApi',inData).success(function(response) {
console.log(response);
refresh();
});
};
// Server Side API Code
router.post('/cvmApi', function(req, res, next) {
console.log("Cvm api post '/'");
console.log("retrieving:: " + req.body);
cvmModel.create(req.body, function (err, post) {
console.log("saving:: " + post);
if (err) return next(err);
res.json(post);
});
});
The thing is i dint realize my variable startDate was not in type string in my html page as i was using some date plugins....
soo ya thats it worked brilliantly ...
addCvm function in controller thanks to rana ;-)
$scope.schedules=[];
$scope.addCvm = function(){
var inData = $scope.cvm;
inData.schedules = $scope.schedules;
console.log(inData);
$http.post('/cvmApi',inData).success(function(response) {
console.log(response);
refresh();
});
};
server side Api
router.post('/', function(req, res, next) {
console.log("Cvm api post '/'");
console.log("retrieving:: " + req.body);
cvmModel.create(req.body, function (err, post) {
console.log("saving:: " + post);
if (err) return next(err);
res.json(post);
});
});
may be not required but i changed my schema though....
var cvmSchema = new mongoose.Schema({
visitOrganization: { type: String },
visitAgenda: { type: String },
accountManager: { type: String },
visitCoordinator: { type: String },
schedules: [{
dateStart: { type:String },
locationHere: { type: String }
}]
});
We have a website which has to be authenticated with windows active directory. I am using passport-ldapauth as middleware.
Authentication does not proceed ahead and whenever I click the submit button the following message gets printed to the console.
{Message : 'Missing credentials'}
this is the code:
login.jade
.login-form(ng-controller="LoginCtrl")
form
input(type="text" ng-model="username" placeholder="Enter employee number")
input(type="password" ng-model="password" placeholder="Enter Password")
button.show-bu-btn.btn.btn-primary(ng-click="submit()") Submit
logincontroller.js
'use strict';
angular.module('someapp').controller('LoginCtrl', function ($scope, $http, $rootScope, Service) {
$scope.submit = function () {
$http.post('/Login', {uname: $scope.username}).success(function (res) {
console.log('login OK ', res);
sessionStorage.userAccessInfo = JSON.stringify(res.userAccessInfo);
sessionStorage.dataQuery = JSON.stringify(res.userAccessInfo);
location.hash = '#/main';
}).error(function (res) {
});
};
});
routes.js
module.exports.routes = {
'post /Login' : 'AuthController.process',
};
AuthController.js
module.exports = {
process: function(req, res) {
var emp = req.body.uname;
Acl.findOne({empid: emp}).exec(function(err, user) {
//console.log(user);
if(user) {
passport.authenticate('ldapauth', function(err, user, info) {
console.log(info);
if(err || !user) {
return res.redirect('/login');
}
req.logIn(user, function(err)
{
if (err)
{
res.redirect('/login');
return;
}
});
})(req, res);
}
else {
res.json({userAccessInfo: undefined});
//console.log('Something is wrong');
}
});
}
};
Acl.js
Data resides in a flat file
module.exports = {
attributes: {
empid: {
type: 'string',
columnName: 'empid'
},
designation: {
type: 'string',
columnName: 'designation'
},
email: {
type: 'string',
columnName: 'email'
}
}
};
Passport.js
var passport = require('passport');
var express = require('express');
var LdapStrategy = require('passport-ldapauth').Strategy;
var app = express();
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
Acl.findOne({id:id}).exec(function(err, user) {
done(err, user);
});
});
passport.use(
new LdapStrategy({
server: {
url: 'ldap://xxxx.xx.xx:389',
adminDn: 'serviceadmin',
adminPassword: 'servicepassword',
searchFilter: '(sAMAccountName={{username}})',
searchBase: 'DC=xxxx,DC=xx,DC=xx'
},
passReqToCallback: true
},
function(user, done) {
if(!user) {
return done(null, false, {message: 'Unknown user'});
}
Acl.findOne({username:user.uid}).exec(function(err,user) {
if(err) {
return done(err);
}
return done(null, user);
});
}
)
);
Any ideas on why I am getting the message are highly appreciated. Please correct if there is some mistake.