├── .env.sample ├── .gitignore ├── LICENSE ├── README.md ├── index.html ├── package.json └── server.js /.env.sample: -------------------------------------------------------------------------------- 1 | MODE= DEVELOPMENT or PRODUCTION or whatever_you_want_to_set_it_to 2 | TEST_STRIPE_SECRET_KEY=your_test_secret_key 3 | TEST_STRIPE_PUBLISHABLE_KEY=your_test_publishable_key 4 | LIVE_STRIPE_SECRET_KEY=your_live_secret_key 5 | LIVE_STRIPE_PUBLISHABLE_KEY=your_live_publishable_key 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | logs 2 | *.log 3 | node_modules 4 | .DS_Store 5 | .env 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-stripe-node 2 | Quick demo for implementing stripe checkout in Vue.js and Node/Express 3 | 4 | Super simple. Intentionally not using any task-runners or module-loading tools. Good ol' npm and external libraries loading via a CDN. Not fancy (obviously, not even production ready) but should be a VERY clear demo. 5 | 6 | ## To Install 7 | 1. clone 8 | 2. npm install 9 | 3. create file *.env* based on *.env.sample* with your own Stripe credentials 10 | 4. *node server.js* or *nodemon* or whatever-you-like-to-use 11 | 5. navigate your favorite browser to http://localhost:9002 12 | 13 | ## Stripe Reference Docs 14 | 15 | https://stripe.com/docs/checkout#integration-custom 16 | 17 | Note: if you want to run Stripe in *live mode*, this example must be deployed to a server with SSL cert. My own preferences in this matter lie squarely with https://letsencrypt.org/ 18 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Demo Stripe-Vue-Node 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Test Item 2 Sell

13 | 14 |

Magna minim tempor eiusmod reprehenderit cillum adipisicing elit incididunt. Minim ex incididunt anim consequat nisi aute do mollit. Ipsum proident esse consectetur anim ullamco dolor id labore magna incididunt enim occaecat ut aute sit magna.

15 |

${{price / 100}}

16 | 17 |

Order Status {{order_status}}

18 |
19 | 20 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-stripe-node", 3 | "version": "0.0.1", 4 | "description": "quick stripe and vue demo", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "test", 8 | "start": "node server.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/infinite-industries/vue-stripe-node.git" 13 | }, 14 | "keywords": [ 15 | "node", 16 | "stripe", 17 | "vue" 18 | ], 19 | "author": "dima strakovsky", 20 | "license": "ISC", 21 | "bugs": { 22 | "url": "https://github.com/infinite-industries/vue-stripe-node/issues" 23 | }, 24 | "homepage": "https://github.com/infinite-industries/vue-stripe-node#readme", 25 | "dependencies": { 26 | "body-parser": "^1.15.2", 27 | "dotenv": "^2.0.0", 28 | "express": "^4.14.0", 29 | "stripe": "^4.11.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var app = express(); 3 | var dotenv = require('dotenv'); 4 | var bodyParser = require('body-parser'); 5 | 6 | dotenv.load(); //get cofiguration file from .env 7 | 8 | app.use(bodyParser.json()); 9 | 10 | var stripe = require("stripe")(process.env.TEST_STRIPE_SECRET_KEY); 11 | 12 | app.get('/', function(req,res){ 13 | res.sendFile(__dirname +'/index.html'); 14 | }) 15 | 16 | app.post('/process_payment', function(req,res){ 17 | 18 | var token_id = req.body.token_id; 19 | var purchase_price = req.body.price; 20 | 21 | //console.log(token.id +"\n"+purchase_price); 22 | 23 | var charge = stripe.charges.create({ 24 | amount: purchase_price, // Amount in cents 25 | currency: "usd", 26 | source: token_id, 27 | description: "Example charge" 28 | }, function(err, charge) { 29 | if (err && err.type === 'StripeCardError') { 30 | // The card has been declined 31 | res.json({"status":"failure", "reason":"card was declined"}); 32 | } 33 | else{ 34 | console.log(charge); 35 | res.json({"status":"success"}); 36 | } 37 | }); 38 | }) 39 | 40 | var appPort=9002; 41 | 42 | app.listen(appPort, function () { 43 | console.log("Magic on port %d",appPort); 44 | }); 45 | --------------------------------------------------------------------------------