├── .gitignore ├── LICENSE ├── README.md ├── package-lock.json └── stripe-handler ├── function.json ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | ### OSX ### 2 | *.DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | # Icon must end with two 7 | Icon 8 | # Thumbnails 9 | ._* 10 | # Files that might appear in the root of a volume 11 | .DocumentRevisions-V100 12 | .fseventsd 13 | .Spotlight-V100 14 | .TemporaryItems 15 | .Trashes 16 | .VolumeIcon.icns 17 | .com.apple.timemachine.donotpresent 18 | # Directories potentially created on remote AFP share 19 | .AppleDB 20 | .AppleDesktop 21 | Network Trash Folder 22 | Temporary Items 23 | .apdisk 24 | 25 | ### Node ### 26 | # Logs 27 | logs 28 | *.log 29 | npm-debug.log* 30 | 31 | # Runtime data 32 | pids 33 | *.pid 34 | *.seed 35 | *.pid.lock 36 | 37 | # Directory for instrumented libs generated by jscoverage/JSCover 38 | lib-cov 39 | 40 | # Coverage directory used by tools like istanbul 41 | coverage 42 | 43 | # nyc test coverage 44 | .nyc_output 45 | 46 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 47 | .grunt 48 | 49 | # node-waf configuration 50 | .lock-wscript 51 | 52 | # Compiled binary addons (http://nodejs.org/api/addons.html) 53 | build/Release 54 | 55 | # Dependency directories 56 | node_modules 57 | jspm_packages 58 | 59 | # Optional npm cache directory 60 | .npm 61 | 62 | # Optional eslint cache 63 | .eslintcache 64 | 65 | # Optional REPL history 66 | .node_repl_history 67 | 68 | # Output of 'npm pack' 69 | *.tgz 70 | 71 | # Yarn Integrity file 72 | .yarn-integrity -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Sarah Drasner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sample Stripe Handler 2 | 3 | This small demo shows how to accept payments with stripe with Vue.js using an 4 | Azure Serverless Function. It's actually not that bad to set up! 5 | 6 | Live demo at 7 | [https://shoppity.azurewebsites.net/](https://shoppity.azurewebsites.net/) 8 | 9 | Articles explaining the demo will be available soon at 10 | [https://css-tricks.com/](https://css-tricks.com/) 11 | 12 | The shop code is all open source as well, which demos how to set it up with 13 | Vue.js. Available at this repo: 14 | [https://github.com/sdras/sample-vue-shop](https://github.com/sdras/sample-vue-shop) 15 | 16 | ![Vue stripe sample shop](https://image.ibb.co/hYi7nm/shop_demo.gif "Vue Stripe Sample Shop") 17 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sample-stripe-handler", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "bluebird": { 8 | "version": "3.5.1", 9 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", 10 | "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" 11 | }, 12 | "lodash.isplainobject": { 13 | "version": "4.0.6", 14 | "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", 15 | "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" 16 | }, 17 | "qs": { 18 | "version": "6.5.1", 19 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", 20 | "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" 21 | }, 22 | "safe-buffer": { 23 | "version": "5.1.1", 24 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", 25 | "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" 26 | }, 27 | "stripe": { 28 | "version": "5.3.0", 29 | "resolved": "https://registry.npmjs.org/stripe/-/stripe-5.3.0.tgz", 30 | "integrity": "sha512-qgcagrMyFCZ+MU1+yL6dPgzxWTZgIIsv3PAxmX85FL0++Y5CpIiBFOLNIJ9YsRURfYeQy/p6FSdF67HJqyw4Gw==", 31 | "requires": { 32 | "bluebird": "3.5.1", 33 | "lodash.isplainobject": "4.0.6", 34 | "qs": "6.5.1", 35 | "safe-buffer": "5.1.1" 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /stripe-handler/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "function", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "route": "charge", 9 | "methods": ["post"] 10 | }, 11 | { 12 | "type": "http", 13 | "direction": "out", 14 | "name": "res" 15 | } 16 | ], 17 | "disabled": false 18 | } 19 | -------------------------------------------------------------------------------- /stripe-handler/index.js: -------------------------------------------------------------------------------- 1 | var stripe = require('stripe')('sk_test_js5LRkmS7OsYHtVc7XYvK9OB'); 2 | // ^ this is a stripe testing key 3 | 4 | module.exports = function(context, req) { 5 | context.log('starting to get down'); 6 | 7 | //if we have a request body, an email, and a token, let's get started 8 | if ( 9 | req.body && 10 | req.body.stripeEmail && 11 | req.body.stripeToken && 12 | req.body.stripeAmt 13 | ) { 14 | stripe.customers 15 | .create({ 16 | email: req.body.stripeEmail, 17 | source: req.body.stripeToken 18 | }) 19 | .then(customer => { 20 | context.log('starting the stripe charges'); 21 | stripe.charges.create({ 22 | amount: req.body.stripeAmt, 23 | description: 'Sample Charge', 24 | currency: 'usd', 25 | customer: customer.id 26 | }); 27 | }) 28 | .then(charge => { 29 | context.log('finished the stripe charges'); 30 | context.res = { 31 | // status: 200 32 | body: 'This has been completed' 33 | }; 34 | context.done(); 35 | }) 36 | .catch(err => { 37 | context.log(err); 38 | context.done(); 39 | }); 40 | } else { 41 | context.log(req.body); 42 | context.res = { 43 | status: 400, 44 | body: "We're missing something" 45 | }; 46 | context.done(); 47 | } 48 | }; 49 | -------------------------------------------------------------------------------- /stripe-handler/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sample-stripe-handler", 3 | "version": "1.0.0", 4 | "description": "A simple Azure functions handler for Stripe\"", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/sdras/sample-stripe-handler.git" 12 | }, 13 | "keywords": [ 14 | "Azure", 15 | "Functions", 16 | "Azure", 17 | "Functions", 18 | "Azure", 19 | "Stripe" 20 | ], 21 | "author": "sdras", 22 | "license": "ISC", 23 | "bugs": { 24 | "url": "https://github.com/sdras/sample-stripe-handler/issues" 25 | }, 26 | "homepage": "https://github.com/sdras/sample-stripe-handler#readme", 27 | "dependencies": { 28 | "stripe": "^5.3.0" 29 | } 30 | } 31 | --------------------------------------------------------------------------------