项目作者: nealfennimore

项目描述 :
Express server for stripe api
高级语言: JavaScript
项目地址: git://github.com/nealfennimore/stripe-api-node-express.git
创建时间: 2017-03-17T03:48:19Z
项目社区:https://github.com/nealfennimore/stripe-api-node-express

开源协议:

下载


Stripe API Express Server

A simple express api server for creating Stripe charges.

Installation

  1. npm install
  2. npm install -g foreman # Install foreman globally

.env File Example

Update your .env file to look similar.

  1. {
  2. "server": {
  3. "ip": "0.0.0.0",
  4. "port": 3000
  5. },
  6. "auth": {
  7. "secret": "",
  8. "algorithm": "HS256"
  9. },
  10. "stripe": {
  11. "publishable_key": "",
  12. "secret_key": ""
  13. }
  14. }

Generate Keys

We’ll use a either a secret key or RSA public key for verifying using JSON Web Tokens for certain API requests.
Generate a private and public key using the below commands for RS256.

  1. # RS256 key
  2. openssl genrsa -out keys/priv.pem 1024
  3. openssl rsa -pubout -in keys/priv.pem -out keys/pub.pem

Get Access Token

Generate an access token and use it for authenticated API requests.

  1. # RS256
  2. const privateKey = fs.readFileSync('keys/priv.pem');
  3. const RS_256_ACCESS_TOKEN = jwt.sign({}, privateKey, { algorithm: 'RS256'})
  4. # HS256
  5. const HS256_ACCESS_TOKEN = jwt.sign({}, AUTH_SECRET);

The token should be in the Authorization Header.

  1. // Authorization: Bearer <token>
  2. req.headers['authorization'];

Starting API Server

  1. npm run start
  2. npm run develop # With nodemon