Getting Started

Setup Application

Set up Elements or CheckoutElementsProvider in your Vue application

Setup Application

Vue Stripe provides two main ways to integrate Stripe into your application:

  1. Elements Provider - For flexible payment collection with Elements
  2. CheckoutElementsProvider - For building a checkout out of individual Elements with Checkout Sessions

Elements Provider Setup

The Elements provider allows you to use Element components and access the Stripe object in any nested component. Render an Elements provider at the root of your Vue app.

Basic Setup

<script setup>
import { loadStripe } from '@stripe/stripe-js'
import { Elements } from 'vue-stripe'
import CheckoutForm from './CheckoutForm.vue'

const stripePromise = loadStripe('pk_test_xxx')

const options = {
  // Optional Elements configuration
  appearance: {
    theme: 'stripe',
  },
}
</script>

<template>
  <Elements :stripe="stripePromise" :options="options">
    <CheckoutForm />
  </Elements>
</template>

With Payment Intent

<script setup>
import { loadStripe } from '@stripe/stripe-js'
import { Elements } from 'vue-stripe'
import CheckoutForm from './CheckoutForm.vue'

const stripePromise = loadStripe('pk_test_xxx')

const options = {
  // Passing the client secret obtained from the server
  clientSecret: '{{CLIENT_SECRET}}',
}
</script>

<template>
  <Elements :stripe="stripePromise" :options="options">
    <CheckoutForm />
  </Elements>
</template>

Props

PropTypeDescription
stripeStripe | PromiseLike<Stripe | null> | nullA Stripe object or a Promise resolving to a Stripe object. Can initially be null for SSR apps.
optionsStripeElementsOptionsOptional Elements configuration options. See available options.

CheckoutElementsProvider Setup

The CheckoutElementsProvider allows you to use Element components with Checkout Sessions. This is used when you want to lay out your own checkout from individual Elements. Stripe also offers CheckoutFormProvider for its single prebuilt Checkout form. See Checkout for both.

Basic Setup

<script setup>
import { loadStripe } from '@stripe/stripe-js'
import { CheckoutElementsProvider } from 'vue-stripe/checkout'

const stripePromise = loadStripe('pk_test_xxx')

function fetchClientSecret() {
  return fetch('/create-checkout-session', { method: 'POST' })
    .then(response => response.json())
    .then(data => data.clientSecret)
}
</script>

<template>
  <CheckoutElementsProvider
    :stripe="stripePromise"
    :options="{ clientSecret: fetchClientSecret }"
  >
    <CheckoutForm />
  </CheckoutElementsProvider>
</template>

Appearance and font options are nested under options.elementsOptions, not at the top level:

const options = {
  clientSecret: fetchClientSecret,
  elementsOptions: {
    appearance: { theme: 'stripe' },
  },
}

Props

PropTypeDescription
stripeStripe | PromiseLike<Stripe | null> | nullA Stripe object or a Promise resolving to a Stripe object. Can initially be null for SSR apps.
optionsStripeCheckoutElementsSdkOptionsCheckoutElementsProvider configuration options. See available options. You must provide the clientSecret (string or function that returns a Promise).

Read the session inside the provider with useCheckoutElements(). useCheckout() still works but is deprecated in favor of useCheckoutElements(). See Service Composables for details.

Using loadStripe

The loadStripe function from @stripe/stripe-js is the recommended way to initialize Stripe.js:

<script setup>
import { loadStripe } from '@stripe/stripe-js'

// Load Stripe asynchronously
const stripePromise = loadStripe('pk_test_xxx')
</script>

For detailed information about initializing Stripe.js, refer to the Stripe documentation.

Next Steps