Skip to content

Commit

Permalink
refactor: Recommend using restricted API key (#23)
Browse files Browse the repository at this point in the history
* refactor: Rename API key param

BREAKING CHANGE: Now called stripe_key

* docs: Update README

Add note recommending restricted key usage

* docs: Additional README context
  • Loading branch information
ynnoj authored Feb 8, 2021
1 parent 3aa5b43 commit cfaf335
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ yarn add next-stripe@beta

Create a `[...nextstripe].js` catch-all route in your project's `pages/api/stripe` directory.

> ⚠️ PLEASE NOTE: It is recommended you use a [restricted key](https://stripe.com/docs/keys#limit-access) with limited API access with this library. These keys can be created and configured with the required access in the Stripe Dashboard.
```js
import NextStripe from 'next-stripe'

export default NextStripe({
secret_key: process.env.STRIPE_SECRET_KEY
})
stripe_key: process.env.STRIPE_RESTRICTED_KEY
```
## Usage
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/confirm/payment-intent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Stripe from 'stripe'

export default async function confirmPaymentIntent(req, res, options) {
try {
const stripe = new Stripe(options.secret_key)
const stripe = new Stripe(options.stripe_key)

const { id, body } = req.body

Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/create/billing-portal-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Stripe from 'stripe'

export default async function createBillingPortalSession(req, res, options) {
try {
const stripe = new Stripe(options.secret_key)
const stripe = new Stripe(options.stripe_key)

const session = await stripe.billingPortal.sessions.create(req.body)

Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/create/checkout-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Stripe from 'stripe'

export default async function createCheckoutSession(req, res, options) {
try {
const stripe = new Stripe(options.secret_key)
const stripe = new Stripe(options.stripe_key)

const session = await stripe.checkout.sessions.create(req.body)

Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/create/payment-intent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Stripe from 'stripe'

export default async function createPaymentIntent(req, res, options) {
try {
const stripe = new Stripe(options.secret_key)
const stripe = new Stripe(options.stripe_key)

const paymentIntent = await stripe.paymentIntents.create(req.body)

Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/retrieve/payment-intent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Stripe from 'stripe'

export default async function retrievePaymentIntent(req, res, options) {
try {
const stripe = new Stripe(options.secret_key)
const stripe = new Stripe(options.stripe_key)

const paymentIntent = await stripe.paymentIntents.retrieve(req.body.id)

Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/update/payment-intent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Stripe from 'stripe'

export default async function updatePaymentIntent(req, res, options) {
try {
const stripe = new Stripe(options.secret_key)
const stripe = new Stripe(options.stripe_key)

const { id, body } = req.body

Expand Down

0 comments on commit cfaf335

Please sign in to comment.