Skip to content

Instantly share code, notes, and snippets.

View samcorcos's full-sized avatar

Sam Corcos samcorcos

View GitHub Profile
@samcorcos
samcorcos / map.geojson
Created December 4, 2014 01:09
Kenya Central District
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@samcorcos
samcorcos / package.json
Last active May 31, 2016 07:40
Start script for sightline payments api
...
"scripts": {
"test": "npm test",
"start": "node index.js"
},
...
@samcorcos
samcorcos / index.html
Last active May 31, 2016 08:26
index.html part 1 for payment processor
<html>
<head>
<title>Page Title</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
</script>
<script>
var submit = function() {
$.ajax({
type: 'POST', url: '/api/purchase', data: {
token: "stripe-token"
@samcorcos
samcorcos / index.js
Last active May 31, 2016 08:59
Initial index.js file for payment processor
var express = require("express")
var app = express()
var cors = require("cors")
var path = require('path')
var bodyParser = require('body-parser')
var parseURLencoded = bodyParser.urlencoded({ extended: true })
app.use(cors())
app.get('/', function (req, res) {
@samcorcos
samcorcos / index.html
Last active May 31, 2016 08:26
index html part 2
<html>
<head>
<title>Page Title</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>
<script>
var amount = 1000
var submit = function(token) {
$.ajax({
type: 'POST', url: '/api/purchase', data: {
@samcorcos
samcorcos / stripeCharge.js
Last active May 31, 2016 08:27
stripe charge javascript file initial
exports.charge = function(token, amount) {
console.log("Charged");
console.log(token);
}
exports.subscribe = function(token, amount) {
console.log("Subscribed");
}
@samcorcos
samcorcos / index.js
Last active May 31, 2016 08:27
adding stripe integration for charge
...
var stripeCharge = require('./stripeCharge.js')
...
app.post('/api/purchase', parseURLencoded, function(req, res) {
var auth = req.headers['authorization']
if (auth !== "false") {
var token = req.body.token
var amount = req.body.amount
@samcorcos
samcorcos / stripeCharge.js
Last active May 31, 2016 08:28
updated stripecharge.js for customer charge
var stripe = require("stripe")("sk_test_lcuMG0QtsEvpQXaI6B8ExZ4j");
exports.charge = function(token, amount) {
var charge = stripe.charges.create({
amount: amount,
currency: "usd",
source: token.id,
description: "Example charge"
})
}
@samcorcos
samcorcos / auth.js
Last active May 31, 2016 09:39
Auth middleware
module.exports = function(req, res, next) {
console.log("Checking authorization header...")
var auth = req.headers['authorization']
if (auth !== "false") {
next()
} else {
res.status('401').send("Unauthorized")
}
@samcorcos
samcorcos / index.js
Created May 31, 2016 08:40
index updated with auth middleware
...
var auth = require('./auth')
...
app.post('/api/purchase', parseURLencoded, auth, function(req, res) {
var token = req.body.token
var amount = req.body.amount
stripeCharge.charge(token, amount)
res.status(201)