File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 2525<script setup lang="ts">
2626import { loadStripe } from " @stripe/stripe-js"
2727import type {
28+ Stripe ,
2829 StripeCardElement ,
2930 StripeCardElementOptions ,
3031 StripeConstructorOptions ,
@@ -52,23 +53,24 @@ const stripeLoaded = ref(false)
5253
5354const elementsComponent = useTemplateRef (" elementsComponent" )
5455const cardComponent = useTemplateRef (" cardComponent" )
56+ const stripe = ref <Stripe | null >(null )
5557
56- onBeforeMount (() => {
57- loadStripe (publishableKey .value ).then (() => {
58- stripeLoaded .value = true
59- })
58+ onBeforeMount (async () => {
59+ stripe .value = await loadStripe (publishableKey .value )
60+ stripeLoaded .value = true
6061})
6162
6263function handlePay() {
6364 // You need to implement backend for creating PaymentIntent
6465 // Learn more by reading https://docs.stripe.com/payments/card-element?lang=node
65- const stripeInstance = elementsComponent .value ?.instance
6666 const card = cardComponent .value ?.stripeElement as StripeCardElement
67+ // You can also access stripe instance from the component
68+ const stripeInstance = elementsComponent .value ?.instance // same as stripe.value
6769
6870 // Let's skip to the point you got clientSecret
6971 const clientSecret = " i_was_created_on_server"
7072
71- stripeInstance
73+ stripe . value
7274 ?.confirmCardPayment (clientSecret , {
7375 payment_method: {
7476 card ,
You can’t perform that action at this time.
0 commit comments