Merge branch 'master' of https://github.com/tmcpro/hackathon-starter
# By Tyler McIntyre # Via Tyler McIntyre * 'master' of https://github.com/tmcpro/hackathon-starter: Added to Readme file Stripe API finished stripe API added Conflicts: package.json views/api/index.jade
This commit is contained in:
@ -210,6 +210,13 @@ app.get('/auth/facebook/callback', passport.authenticate('facebook', { successRe
|
||||
|
||||
<hr>
|
||||
|
||||
<img src="https://stripe.com/img/about/logos/logos/black@2x.png" width="200">
|
||||
- [Sign up](http://stripe.com) or log into your your [dashboard](https://manage.stripe.com)
|
||||
- Click on your profile and click on Account Settings
|
||||
- Then click on [API Keys](https://manage.stripe.com/account/apikeys)
|
||||
- Copy the **Secret Key**. and add this into `config/secrets.js`
|
||||
<hr>
|
||||
|
||||
<img src="https://www.paypalobjects.com/webstatic/developer/logo_paypal-developer_beta.png" width="200">
|
||||
- Visit [PayPal Developer](https://developer.paypal.com/)
|
||||
- Log in to your PayPal account
|
||||
@ -316,6 +323,7 @@ List of Packages
|
||||
| passport-linkedin-oauth2 | Sign-in with LinkedIn plugin. |
|
||||
| passport-oauth | Allows you to set up your own OAuth 1.0a and OAuth 2.0 strategies. |
|
||||
| request | Simplified HTTP request library. |
|
||||
| stripe | Offical Stripe API library. |
|
||||
| tumblr.js | Tumblr API library. |
|
||||
| underscore | Handy JavaScript utlities library. |
|
||||
| uglify-js | Dependency for connect-assets library. |
|
||||
|
5
app.js
5
app.js
@ -131,6 +131,11 @@ app.get('/api/paypal', apiController.getPayPal);
|
||||
app.get('/api/paypal/success', apiController.getPayPalSuccess);
|
||||
app.get('/api/paypal/cancel', apiController.getPayPalCancel);
|
||||
app.get('/api/steam', apiController.getSteam);
|
||||
app.get('/api/stripe', apiController.getStripe);
|
||||
app.get('/api/stripe/onetime', apiController.getStripeOnetime);
|
||||
app.post('/api/stripe/onetime', apiController.postStripeOnetime);
|
||||
app.get('/api/stripe/newsubscriber', apiController.getStripeNewSubscriber);
|
||||
app.post('/api/stripe/newsubscriber', apiController.postStripeNewSubscriber);
|
||||
app.get('/api/scraping', apiController.getScraping);
|
||||
app.get('/api/twilio', apiController.getTwilio);
|
||||
app.post('/api/twilio', apiController.postTwilio);
|
||||
|
@ -13,6 +13,7 @@ var foursquare = require('node-foursquare')({ secrets: secrets.foursquare });
|
||||
var Github = require('github-api');
|
||||
var Twit = require('twit');
|
||||
var paypal = require('paypal-rest-sdk');
|
||||
var stripe = require('stripe')(secrets.stripe.apiKey);
|
||||
var twilio = require('twilio')(secrets.twilio.sid, secrets.twilio.token);
|
||||
var Linkedin = require('node-linkedin')(secrets.linkedin.clientID, secrets.linkedin.clientSecret, secrets.linkedin.callbackURL);
|
||||
var clockwork = require('clockwork')({key: secrets.clockwork.apiKey});
|
||||
@ -385,6 +386,154 @@ exports.getSteam = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* GET /api/stripe
|
||||
* Stripe API example.
|
||||
*/
|
||||
|
||||
exports.getStripe = function(req, res, next) {
|
||||
//Create a token for the CC
|
||||
res.render('api/stripe/index', {
|
||||
title: 'Stripe API'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* GET /api/onetime
|
||||
* Stripe One Time Charge API example.
|
||||
*/
|
||||
exports.getStripeOnetime = function(req, res, next) {
|
||||
//Create a token for the CC
|
||||
res.render('api/stripe/onetime', {
|
||||
title: 'Stripe API'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* POST /api/stripe/onetime
|
||||
* @param ccNumber
|
||||
* @param expMonth
|
||||
* @param expYear
|
||||
* @param ccNumber
|
||||
* @param expMonth
|
||||
* @param expYear
|
||||
* @param customerName
|
||||
* @param email
|
||||
* @param chargeAmount
|
||||
*/
|
||||
exports.postStripeOnetime = function(req, res, next) {
|
||||
stripe.tokens.create({
|
||||
card: {
|
||||
"number": req.body.ccNumber,
|
||||
"exp_month": req.body.expMonth,
|
||||
"exp_year": req.body.expYear,
|
||||
"cvc": req.body.cvc
|
||||
}
|
||||
}, function(err, token) {
|
||||
if (err) {
|
||||
req.flash('errors', { msg: err.message });
|
||||
return res.redirect('/api/stripe/onetime');
|
||||
}
|
||||
//Create a new customer
|
||||
stripe.customers.create({
|
||||
card: token.id,
|
||||
description: req.body.customerName,
|
||||
email: req.body.email
|
||||
}).then(function(customer) {
|
||||
//charge the customer
|
||||
stripe.charges.create({
|
||||
amount: req.body.chargeAmount * 100, // amount in cents
|
||||
currency: "usd",
|
||||
customer: customer.id
|
||||
}, function(err, charge) {
|
||||
if (err) {
|
||||
req.flash('errors', { msg: err.message });
|
||||
return res.redirect('/api/stripe/onetime');
|
||||
}else{
|
||||
req.flash('success', { msg: 'Charged Successfully'});
|
||||
res.render('api/stripe/onetime', {
|
||||
title: 'Stipe API',
|
||||
customer: customer,
|
||||
charge: charge
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* GET /api/newsubscriber
|
||||
* Stripe Subscription API example.
|
||||
*/
|
||||
exports.getStripeNewSubscriber = function(req, res, next) {
|
||||
stripe.plans.list(function(err, plans) {
|
||||
res.render('api/stripe/newsubscriber', {
|
||||
title: 'Stripe API',
|
||||
plans: _.pluck(plans.data, 'name')
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* POST /api/stripe/newsubscriber
|
||||
* @param ccNumber
|
||||
* @param expMonth
|
||||
* @param expYear
|
||||
* @param ccNumber
|
||||
* @param expMonth
|
||||
* @param expYear
|
||||
* @param customerName
|
||||
* @param email
|
||||
* @param plantype
|
||||
*/
|
||||
exports.postStripeNewSubscriber = function(req, res, next) {
|
||||
console.log(req.body.plantype);
|
||||
|
||||
stripe.tokens.create({
|
||||
card: {
|
||||
"number": req.body.ccNumber,
|
||||
"exp_month": req.body.expMonth,
|
||||
"exp_year": req.body.expYear,
|
||||
"cvc": req.body.cvc
|
||||
}
|
||||
}, function(err, token) {
|
||||
if (err) {
|
||||
req.flash('errors', { msg: err.message });
|
||||
return res.redirect('/api/stripe/newsubscriber');
|
||||
}
|
||||
//Create a new customer
|
||||
stripe.customers.create({
|
||||
card: token.id,
|
||||
description: req.body.customerName,
|
||||
email: req.body.email
|
||||
}).then(function(customer) {
|
||||
//charge the customer
|
||||
stripe.customers.createSubscription(
|
||||
customer.id,
|
||||
{plan: req.body.plantype},
|
||||
function(err, subscription) {
|
||||
if (err) {
|
||||
req.flash('errors', { msg: err.message });
|
||||
return res.redirect('/api/stripe/newsubscriber');
|
||||
}else{
|
||||
stripe.plans.list(function(err, plans) {
|
||||
req.flash('success', { msg: 'Subscribed Successfully'});
|
||||
res.render('api/stripe/newsubscriber', {
|
||||
title: 'Stipe API',
|
||||
customer: customer,
|
||||
subscription: subscription,
|
||||
plans: _.pluck(plans.data, 'name')
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* GET /api/twilio
|
||||
* Twilio API example.
|
||||
@ -410,7 +559,7 @@ exports.postTwilio = function(req, res, next) {
|
||||
};
|
||||
twilio.sendMessage(message, function(err, responseData) {
|
||||
if (err) return next(err.message);
|
||||
req.flash('success', { msg: 'Text sent to ' + responseData.to + '.'})
|
||||
req.flash('success', { msg: 'Text sent to ' + responseData.to + '.'});
|
||||
res.redirect('/api/twilio');
|
||||
});
|
||||
};
|
||||
|
@ -4,6 +4,7 @@ block content
|
||||
h2 API Examples
|
||||
hr
|
||||
|
||||
<<<<<<< HEAD
|
||||
.row.api-examples
|
||||
.col-sm-4
|
||||
.panel.panel-default
|
||||
@ -55,6 +56,11 @@ block content
|
||||
.panel-body
|
||||
img(src='http://th08.deviantart.net/fs4/200H/i/2004/242/4/7/Steam_Icon.png', height=40)
|
||||
a(href='/api/steam') Steam
|
||||
.col-sm-4
|
||||
.panel.panel-default
|
||||
.panel-body
|
||||
img(src='https://stripe.com/img/open-graph/logo.png', height=40)
|
||||
a(href='/api/stripe') Stripe
|
||||
.col-sm-4
|
||||
.panel.panel-default
|
||||
.panel-body
|
||||
@ -79,4 +85,4 @@ block content
|
||||
.panel.panel-default
|
||||
.panel-body
|
||||
img(src='http://www.mevvy.com/wp-content/uploads/2013/09/Venmo-Logo-on-Mevvy.com_.png', height=40)
|
||||
a(href='/api/venmo') Venmo
|
||||
a(href='/api/venmo') Venmo
|
10
views/api/stripe.jade
Normal file
10
views/api/stripe.jade
Normal file
@ -0,0 +1,10 @@
|
||||
extends ../layout
|
||||
|
||||
block content
|
||||
h2 Stripe API
|
||||
|
||||
ol
|
||||
li
|
||||
a(href='/api/stripe/onetime') One Time Charges
|
||||
li
|
||||
a(href='/api/stripe/newsubscriber') New Subscriber
|
Reference in New Issue
Block a user