Nuxt.js Stripe Module
A Nuxt.js module for Stripe.js
Table of Contents
Install
$ yarn add nuxtjs-stripe // or npm install --save nuxtjs-stripe
Getting Started
Add nuxtjs-stripe
to modules
section of nuxt.config.ts
.
modules: 'nuxtjs-stripe' /* module options */ publishableKey: 'YOUR_STRIPE_PUBLISHABLE_KEY' version: 'v3' // Default defer: true // Default async: true // Default
or even
modules: 'nuxtjs-stripe' stripe: /* module options */ publishableKey: 'YOUR_STRIPE_PUBLISHABLE_KEY' version: 'v3' // Default defer: true // Default async: true // Default
TypeScript support
Add it to the "types"
of your tsconfig.json
after the @nuxt/types
:
Usage
You can use this module to inject in your application a $stripe
object, by setting the publishableKey instead of calling window.Stripe(PUBLISHABLE_KEY)
every time. Then you can use it in your application like:
Usage with Vuex:
...const actions: ActionTree<PaymentState RootState> = async { try const response = await this$stripe catch error // handle error }...
TIP
You can also use
$stripe
property on the nuxtContext
. Addingnuxtjs-stripe
to your types (see above) will import the types from the package and make typescript aware of the additions to theContext
interface.
See Stripe documentation for details: https://stripe.com/docs/stripe-js/reference