Skip to content

Advanced Integration

Learn about Vue components for Stripe.js and Stripe Elements.

Terminal window
npm install vue-stripe @stripe/stripe-js

The CheckoutProvider provider allows you to use Element components and access the Stripe object in any nested component.

<script setup>
import { loadStripe } from '@stripe/stripe-js'
import { Elements } from 'vue-stripe'
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>
<CheckoutForm />
</Elements>
</template>
PropDescription
stripeA Stripe object or a Promise resolving to a Stripe object.

Can initially be null for SSR apps.
optionsOptional Elements configuration options. See available options.

Element components provide a flexible way to securely collect payment information in your Vue app.

<script setup>
import { PaymentElement } from 'vue-stripe'
</script>
<template>
<form>
<PaymentElement />
<button>Submit</button>
</form>
</template>
PropDescription
idPasses through to the Element’s container.
classPasses through to the Element’s container.
optionsAn object containing Element configuration options. See available options for the Payment Element or available options for individual payment method Elements.
EventDescription
@blurTriggered when the Element loses focus.
@changeTriggered when data exposed by this Element is changed (for example, when there is an error).
@clickTriggered by the <PaymentRequestButtonElement> when it is clicked.
@escapeTriggered when the escape key is pressed within an Element.
@focusTriggered when the Element receives focus.
@loadererrorTriggered when the Element fails to load.

You only receive these events from the payment, linkAuthentication, address, and expressCheckout Elements.
@loaderstartTriggered when the loader UI is mounted to the DOM and ready to be displayed.

You only receive these events from the payment, linkAuthentication, address, and expressCheckout Elements.
@readyTriggered when the Element is fully rendered and can accept imperative element.focus() calls.

There are many different kinds of Elements, useful for collecting different kinds of payment information. These are the available Elements today.

ComponentUsage
AddressElementCollects address details for 236+ regional formats. See the Address Element docs.
AfterpayClearpayMessageElementDisplays installments messaging for Afterpay payments.
AuBankAccountElementCollects Australian bank account information (BSB and account number) for use with BECS Direct Debit payments.
CardCvcElementCollects the card‘s CVC number.
CardElementA flexible single-line input that collects all necessary card details.
CardExpiryElementCollects the card‘s expiration date.
CardNumberElementCollects the card number.
ExpressCheckoutElementAllows you to accept card or wallet payments through one or more payment buttons, including Apple Pay, Google Pay, Link, or PayPal. See the Express Checkout Element docs.
FpxBankElementThe customer’s bank, for use with FPX payments.
IbanElementThe International Bank Account Number (IBAN). Available for SEPA countries.
IdealBankElementThe customer’s bank, for use with iDEAL payments.
LinkAuthenticationElementCollects email addresses and allows users to log in to Link. See the Link Authentication Element docs.
PaymentElementCollects payment details for 25+ payment methods from around the globe. See the Payment Element docs.
PaymentRequestButtonElementAn all-in-one checkout button backed by either Apple Pay or the Payment Request API. See the Payment Request Button docs.

useElements(): Readonly<Ref<Elements | null>>{lang=“ts-type”}

To safely pass the payment information collected by the Payment Element to the Stripe API, access the Elements instance so that you can use it with stripe.confirmPayment.

<script setup>
import { PaymentElement, useElements, useStripe } from 'vue-stripe'
const stripe = useStripe()
const elements = useElements()
async function handleSubmit() {
if (!stripe.value || !elements.value) {
// Stripe.js hasn't yet loaded.
// Make sure to disable form submission until Stripe.js has loaded.
return
}
const result = await stripe.value.confirmPayment({
// `Elements` instance that was used to create the Payment Element
elements: elements.value,
confirmParams: {
return_url: 'https://example.com/order/123/complete',
},
})
if (result.error) {
// Show error to your customer (for example, payment details incomplete)
console.log(result.error.message)
}
else {
// Your customer will be redirected to your `return_url`. For some payment
// methods like iDEAL, your customer will be redirected to an intermediate
// site first to authorize the payment, then redirected to the `return_url`.
}
}
</script>
<template>
<form @submit.prevent="handleSubmit">
<PaymentElement />
<button :disabled="!stripe">
Submit
</button>
</form>
</template>

useStripe(): Readonly<Ref<Stripe | null>>{lang=“ts-type”}

The useStripe composable returns a reference to the Stripe instance passed to the Elements provider.

<script setup>
import { PaymentElement, useElements, useStripe } from 'vue-stripe'
const stripe = useStripe()
const elements = useElements()
async function handleSubmit() {
if (!stripe.value || !elements.value) {
// Stripe.js hasn't yet loaded.
// Make sure to disable form submission until Stripe.js has loaded.
return
}
const result = await stripe.value.confirmPayment({
// `Elements` instance that was used to create the Payment Element
elements: elements.value,
confirmParams: {
return_url: 'https://example.com/order/123/complete',
},
})
if (result.error) {
// Show error to your customer (for example, payment details incomplete)
console.log(result.error.message)
}
else {
// Your customer will be redirected to your `return_url`. For some payment
// methods like iDEAL, your customer will be redirected to an intermediate
// site first to authorize the payment, then redirected to the `return_url`.
}
}
</script>
<template>
<form @submit.prevent="handleSubmit">
<PaymentElement />
<button :disabled="!stripe">
Submit
</button>
</form>
</template>