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 25
25
<script setup lang="ts">
26
26
import { loadStripe } from " @stripe/stripe-js"
27
27
import type {
28
+ Stripe ,
28
29
StripeCardElement ,
29
30
StripeCardElementOptions ,
30
31
StripeConstructorOptions ,
@@ -52,23 +53,24 @@ const stripeLoaded = ref(false)
52
53
53
54
const elementsComponent = useTemplateRef (" elementsComponent" )
54
55
const cardComponent = useTemplateRef (" cardComponent" )
56
+ const stripe = ref <Stripe | null >(null )
55
57
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
60
61
})
61
62
62
63
function handlePay() {
63
64
// You need to implement backend for creating PaymentIntent
64
65
// Learn more by reading https://docs.stripe.com/payments/card-element?lang=node
65
- const stripeInstance = elementsComponent .value ?.instance
66
66
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
67
69
68
70
// Let's skip to the point you got clientSecret
69
71
const clientSecret = " i_was_created_on_server"
70
72
71
- stripeInstance
73
+ stripe . value
72
74
?.confirmCardPayment (clientSecret , {
73
75
payment_method: {
74
76
card ,
You can’t perform that action at this time.
0 commit comments