Add send a payment form, route and controller for Venmo API
This commit is contained in:
1
app.js
1
app.js
@ -124,6 +124,7 @@ app.get('/api/facebook', passportConf.isAuthenticated, passportConf.isAuthorized
|
||||
app.get('/api/github', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getGithub);
|
||||
app.get('/api/twitter', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getTwitter);
|
||||
app.get('/api/venmo', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getVenmo);
|
||||
app.post('/api/venmo', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.postVenmo);
|
||||
|
||||
/**
|
||||
* OAuth routes for sign-in.
|
||||
|
@ -1,6 +1,7 @@
|
||||
var secrets = require('../config/secrets');
|
||||
var User = require('../models/User');
|
||||
var querystring = require('querystring');
|
||||
var validator = require('validator');
|
||||
var async = require('async');
|
||||
var cheerio = require('cheerio');
|
||||
var request = require('request');
|
||||
@ -417,13 +418,55 @@ exports.postTwilio = function(req, res, next) {
|
||||
exports.getVenmo = function(req, res, next) {
|
||||
var token = _.findWhere(req.user.tokens, { kind: 'venmo' });
|
||||
var query = querystring.stringify({ access_token: token.accessToken });
|
||||
|
||||
// Get profile information
|
||||
request.get({ url: 'https://api.venmo.com/v1/me?' + query, json: true }, function(err, request, body) {
|
||||
if (err) return next(err);
|
||||
|
||||
res.render('api/venmo', {
|
||||
title: 'Venmo API',
|
||||
profile: body.data
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
exports.postVenmo = function(req, res, next) {
|
||||
req.assert('user', 'Phone, Email or Venmo User ID cannot be blank').notEmpty();
|
||||
req.assert('note', 'Please enter a message to accompany the payment').notEmpty();
|
||||
req.assert('amount', 'They amount you want to pay cannot be blank').notEmpty();
|
||||
|
||||
var errors = req.validationErrors();
|
||||
|
||||
if (errors) {
|
||||
req.flash('errors', errors);
|
||||
return res.redirect('/api/venmo');
|
||||
}
|
||||
|
||||
var token = _.findWhere(req.user.tokens, { kind: 'venmo' });
|
||||
var formData = {
|
||||
access_token: token.accessToken,
|
||||
note: req.body.note,
|
||||
amount: req.body.amount
|
||||
};
|
||||
|
||||
if (validator.isEmail(req.body.user)) {
|
||||
formData.email = req.body.user;
|
||||
} else if (validator.isLength(req.body.user, 7, 10)) {
|
||||
formData.phone = req.body.user;
|
||||
} else {
|
||||
formData.user_id = req.body.user;
|
||||
}
|
||||
|
||||
|
||||
// Send money
|
||||
request.post('https://api.venmo.com/v1/payments', { form: formData }, function(err, request, body) {
|
||||
if (err) return next(err);
|
||||
console.log(body);
|
||||
req.flash('success', 'Venmo money transfer complete');
|
||||
res.redirect('/api/venmo');
|
||||
});
|
||||
};
|
||||
|
||||
// remove thumb css
|
||||
// add venmo instructions
|
||||
// update auth optional instructions
|
@ -33,6 +33,7 @@
|
||||
"underscore": "~1.5.2",
|
||||
"paypal-rest-sdk": "~0.6.4",
|
||||
"connect-mongo": "~0.4.0",
|
||||
"twilio": "~1.5.0"
|
||||
"twilio": "~1.5.0",
|
||||
"validator": "~3.2.1"
|
||||
}
|
||||
}
|
||||
|
@ -18,32 +18,47 @@ block content
|
||||
| API Endspoints
|
||||
|
||||
h3 Venmo Profile
|
||||
//.col-sm-2
|
||||
// img(src='#{profile.user.profile_picture_url}')
|
||||
//.col-sm-8
|
||||
// .lead Balance:
|
||||
// strong $#{profile.balance}
|
||||
// .lead Display Name:
|
||||
// strong #{profile.user.display_name}
|
||||
// .lead Email:
|
||||
// strong #{profile.user.email}
|
||||
// .lead Phone:
|
||||
// strong #{profile.user.phone}
|
||||
//
|
||||
.row
|
||||
.col-sm-2
|
||||
img(src='#{profile.user.profile_picture_url}')
|
||||
.col-sm-8
|
||||
.row
|
||||
.col-sm-6
|
||||
strong #{profile.user.display_name}
|
||||
div Balance:
|
||||
strong $#{profile.balance}
|
||||
div Friends:
|
||||
strong #{profile.user.friends_count}
|
||||
.col-sm-6
|
||||
div Email:
|
||||
strong #{profile.user.email}
|
||||
div Phone:
|
||||
strong #{profile.user.phone}
|
||||
div ID:
|
||||
strong #{profile.user.id}
|
||||
p #{profile.user.about}
|
||||
|
||||
br
|
||||
|
||||
.row
|
||||
.col-sm-5
|
||||
h3 Make Payment
|
||||
form(role='form', method='POST')
|
||||
input(type='hidden', name='_csrf', value=token)
|
||||
.form-group
|
||||
label.control-label(for='user') Phone, Email or Venmo User ID
|
||||
input.form-control(type='text', name='user', id='user', autofocus=true)
|
||||
.form-group
|
||||
label.control-label(for='note') Note
|
||||
input.form-control(type='text', name='note', id='note')
|
||||
.form-group
|
||||
label.control-label(for='amount') Amount
|
||||
input.form-control(type='text', name='amount', id='amount')
|
||||
.form-group
|
||||
button.btn.btn-primary(type='submit')
|
||||
i.fa.fa-usd
|
||||
| Send
|
||||
br
|
||||
|
||||
h3 Recent Payments
|
||||
|
||||
form(role='form', method='POST')
|
||||
legend Make a payment
|
||||
input(type='hidden', name='_csrf', value=token)
|
||||
.form-group
|
||||
label.control-label(for='user') Email, Phone, or User ID
|
||||
input.form-control(type='text', name='user', id='user', autofocus=true)
|
||||
.form-group
|
||||
label.control-label(for='note') Note
|
||||
input.form-control(type='text', name='note', id='note')
|
||||
.form-group
|
||||
label.control-label(for='amount') Amount
|
||||
input.form-control(type='text', name='amount', id='amount')
|
||||
.form-group
|
||||
button.btn.btn-default(type='submit')
|
||||
i.fa.fa-usd
|
||||
| Send
|
||||
|
Reference in New Issue
Block a user