
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
vue-stripe-js
Advanced tools
Vue 3 components for Stripe. Build advanced payment integrations quickly. Easy to start, friendly DX, minimal abstractions, and full control. It's a glue between Stripe.js and Vue component lifecycle. Works with Nuxt 3.
š¢ Live demo
Consider supporting efforts to make this project healthy and sustainable. Thank you!
npm i vue-stripe-js @stripe/stripe-js
<script setup lang="ts">
import { onBeforeMount, ref } from "vue"
import { loadStripe, type Stripe } from "@stripe/stripe-js"
const publishableKey = '' // use your publishable key
const stripe = ref<Stripe | null>(null)
onBeforeMount(async() => {
stripe.value = await loadStripe(publishableKey)
})
</script>
Alternatively, include a script tag. Make sure Stripe.js is loaded before you mount Vue components.
<script src="https://js.stripe.com/v3/"></script>
Based on ā deferred payment guide
<template>
<form
v-if="stripeLoaded"
@submit.prevent="handleSubmit"
>
<StripeElements
:stripe-key="stripeKey"
:instance-options="stripeOptions"
:elements-options="elementsOptions"
ref="elementsComponent"
>
<StripeElement
type="payment"
:options="paymentElementOptions"
ref="paymentComponent"
/>
</StripeElements>
<button
type="submit"
>
Submit
</button>
</form>
</template>
<script setup lang="ts">
import { onBeforeMount, ref } from "vue"
import { loadStripe } from "@stripe/stripe-js"
import { StripeElements, StripeElement } from "vue-stripe-js"
import type {
StripeElementsOptionsMode,
StripePaymentElementOptions,
} from "@stripe/stripe-js"
const stripeKey = "pk_test_f3duw0VsAEM2TJFMtWQ90QAT" // use your publishable key
const stripeOptions = ref({
// https://stripe.com/docs/js/initializing#init_stripe_js-options
})
const elementsOptions = ref<StripeElementsOptionsMode>({
// https://stripe.com/docs/js/elements_object/create#stripe_elements-options
mode: "payment",
amount: 1099,
currency: "usd",
appearance: {
theme: "flat",
},
})
const paymentElementOptions = ref<StripePaymentElementOptions>({
// https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options
})
const stripeLoaded = ref(false)
const clientSecret = ref("")
// Define component refs
const elementsComponent = ref()
const paymentComponent = ref()
onBeforeMount(() => {
loadStripe(stripeKey).then(() => {
stripeLoaded.value = true
// Good place to call your backend to create PaymentIntent
// Skipping to the point when you got client_secret
// clientSecret.value = client_secret
})
})
async function handleSubmit() {
// Confirm the PaymentIntent using the details collected by the Payment Element
const stripeInstance = elementsComponent.value?.instance
const elements = elementsComponent.value?.elements
if (stripeInstance) {
const { error } = await stripeInstance.confirmPayment({
elements,
clientSecret: clientSecret.value,
confirmParams: {
return_url: "https://example.com/order/123/complete",
},
})
if (error) {
// This point is only reached if there's an immediate error when
// confirming the payment. Show the error to your customer (for example, payment details incomplete)
console.log(error)
} else {
// Your customer is redirected to your `return_url`. For some payment
// methods like iDEAL, your customer is redirected to an intermediate
// site first to authorize the payment, then redirected to the `return_url`.
}
}
}
</script>
Thanks to the Provider Pattern used in StripeElements, you get minimalist tools with full access to Stripe.js methods and properties. This results in better developer experience (DX), simpler code, and fewer bugs.
These examples use Vue Composition API and TypeScript.
All features of Stripe.js are available in two components. The benefits of Vue solution: element is created and destroyed automatically, options are reactive, event listeners are attached to StripeElement. Simple and future-proof.
š„ Most important property is type š„
<StripeElements>
<StripeElement type="payment" />
</StripeElements>
Available types
type StripeElementType =
| 'address'
| 'affirmMessage'
| 'afterpayClearpayMessage'
| 'auBankAccount'
| 'card'
| 'cardNumber'
| 'cardExpiry'
| 'cardCvc'
| 'currencySelector'
| 'epsBank'
| 'expressCheckout'
| 'fpxBank'
| 'iban'
| 'idealBank'
| 'p24Bank'
| 'payment'
| 'paymentMethodMessaging'
| 'paymentRequestButton'
| 'linkAuthentication'
| 'shippingAddress'
| 'issuingCardNumberDisplay'
| 'issuingCardCvcDisplay'
| 'issuingCardExpiryDisplay'
| 'issuingCardPinDisplay'
| 'issuingCardCopyButton'
// Check actual element types in @stripe/stripe-js
<StripeElement @blur="doSomething" />
Following events are emitted on StripeElement
Add classes to components
<StripeElements class="border">
<StripeElement class="p-4" type="card" :options="cardOptions" />
</StripeElements>
Style element via options - read documentation
const cardOptions = ref<StripeCardElementOptions>({
style: {
base: {
iconColor: "green",
},
invalid: {
iconColor: "red",
},
},
})
FAQs
Vue 3 components for Stripe.js
The npm package vue-stripe-js receives a total of 8,884 weekly downloads. As such, vue-stripe-js popularity was classified as popular.
We found that vue-stripe-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.