Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
"scripts": { | |
"test": "npm test", | |
"start": "node index.js" | |
}, | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.charge = function(token, amount) { | |
console.log("Charged"); | |
console.log(token); | |
} | |
exports.subscribe = function(token, amount) { | |
console.log("Subscribed"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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) |
OlderNewer