Skip to content

Commit

Permalink
Merge pull request #14 from coopflow/code-optimisation
Browse files Browse the repository at this point in the history
Code optimisation
  • Loading branch information
coopflow committed Sep 15, 2020
2 parents 75118a5 + ebfba85 commit 3a59767
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"coveralls": "npm run unit -- --cov",
"lint": "npm run lint:standard",
"lint:standard": "standard --verbose | snazzy",
"lint:standard-fix": "standard --fix | snazzy",
"test": "npm run lint && npm run unit",
"test:ci": "npm run unit -- --cov --coverage-report=lcov --no-browser",
"test:report": "npm run lint && npm run unit:report",
Expand Down Expand Up @@ -36,15 +37,15 @@
"node": ">=10"
},
"dependencies": {
"fastify-plugin": "^2.3.3"
"fastify-plugin": "^2.3.4"
},
"devDependencies": {
"coveralls": "^3.1.0",
"dotenv": "^8.2.0",
"fastify": "^3.3.0",
"fastify": "^3.4.1",
"snazzy": "^8.0.0",
"standard": "^14.3.4",
"stripe": "^8.90.0",
"stripe": "^8.96.0",
"tap": "^14.10.8"
},
"peerDependencies": {
Expand Down
16 changes: 8 additions & 8 deletions plugin.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
'use strict'

const fp = require('fastify-plugin')
const fs = require('fs')
const path = require('path')

function fastifyStripe (fastify, options, next) {
if (!options.apiKey) {
const { apiKey, name, ...stripeOptions } = options

if (!apiKey) {
return next(new Error('You must provide a Stripe API key'))
}

const name = options.name
delete options.name

const config = Object.assign(
{
appInfo: {
name: 'fastify-stripe',
url: 'https://github.com/coopflow/fastify-stripe',
version: require('./package.json').version
version: JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'))).version
}
},
options
stripeOptions
)
delete config.apiKey

const stripe = require('stripe')(options.apiKey, config)
const stripe = require('stripe')(apiKey, config)

if (name) {
if (!fastify.stripe) {
Expand Down

0 comments on commit 3a59767

Please sign in to comment.