Payment Request Example
Your own button opens the browser's payment sheet (Apple Pay, Google Pay, Link or a saved card). usePaymentRequest() creates the PaymentRequest and checks canMakePayment(); when the customer authorizes, the paymentmethod handler creates a PaymentIntent on the server and confirms it with useConfirmCardPayment().
Prefer the Express Checkout Element
For new integrations Stripe recommends the Express Checkout Element, which renders the wallet buttons for you. Use usePaymentRequest to keep an existing custom-button integration working.
Try the demo
The demo runs in Stripe test mode against the demo backend at backend.vuestripe.com, so nothing is charged. The demo takes a $10.99 test payment. The button only appears when this browser has a wallet or a saved card and the page is served over HTTPS. Otherwise the demo shows the canMakePayment result, No wallet in this browser.
Pay with the browser's payment sheet
Source code
<script setup lang="ts">
import { ref } from 'vue'
import { VueStripeProvider } from '@vue-stripe/vue-stripe'
import PaymentRequestPanel from './PaymentRequestPanel.vue'
import { useStripeConfig } from '../../composables/useStripeConfig'
import DocIcon from '../DocIcon.vue'
const { publishableKey } = useStripeConfig()
const paymentIntentId = ref<string | null>(null)
</script>
<template>
<div class="payment-request-example">
<div v-if="!publishableKey" class="warning-box">
<strong><DocIcon name="warning" /> Missing Configuration</strong>
<p>Please set <code>VITE_STRIPE_PUBLISHABLE_KEY</code> in your <code>.env</code> file.</p>
</div>
<template v-else>
<div v-if="!paymentIntentId" class="step-section">
<h3>Pay with the browser's payment sheet</h3>
<VueStripeProvider :publishable-key="publishableKey">
<PaymentRequestPanel @success="(id: string) => (paymentIntentId = id)" />
</VueStripeProvider>
</div>
<div v-else class="success-state">
<span class="success-icon"><DocIcon name="check" :size="32" :stroke-width="2.5" /></span>
<h3>Payment Successful</h3>
<p class="payment-id">
Payment ID: <code>{{ paymentIntentId }}</code>
</p>
<button class="reset-btn" @click="paymentIntentId = null">Start Over</button>
</div>
</template>
</div>
</template>
<style scoped>
.payment-request-example {
padding: 1.5rem;
background: var(--vp-c-bg);
border: 1px solid var(--vp-c-divider);
border-radius: 12px;
}
.warning-box {
padding: 1rem;
background: var(--vp-c-yellow-soft);
border: 1px solid var(--vp-c-yellow-1);
border-radius: 8px;
color: var(--vp-c-yellow-darker);
}
.warning-box strong {
display: block;
margin-bottom: 0.5rem;
}
.warning-box p {
margin: 0;
font-size: 0.875rem;
}
.step-section {
padding: 1.5rem;
background: var(--vp-c-bg-soft);
border-radius: 8px;
}
.step-section h3 {
margin: 0 0 1rem;
font-size: 1rem;
font-weight: 600;
}
.success-state {
text-align: center;
padding: 2rem;
}
.success-icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 4rem;
height: 4rem;
background: var(--vp-c-green-1);
color: white;
border-radius: 50%;
font-size: 2rem;
margin-bottom: 1rem;
}
.success-state h3 {
margin: 0 0 0.5rem 0;
font-size: 1.25rem;
}
.payment-id code {
padding: 0.25rem 0.5rem;
background: var(--vp-c-bg-soft);
border-radius: 4px;
font-size: 0.75rem;
}
.reset-btn {
margin-top: 1.5rem;
padding: 0.75rem 1.5rem;
background: var(--vp-c-bg-soft);
border: 1px solid var(--vp-c-divider);
border-radius: 6px;
font-size: 0.875rem;
cursor: pointer;
}
.reset-btn:hover {
border-color: var(--vp-c-brand-1);
color: var(--vp-c-brand-1);
}
</style><script setup lang="ts">
// Rendered inside VueStripeProvider: usePaymentRequest and useConfirmCardPayment only need
// the Stripe instance. The browser's own payment sheet collects the card or wallet.
import { computed, ref } from 'vue'
import { usePaymentRequest, useConfirmCardPayment } from '@vue-stripe/vue-stripe'
import { useBackendApi } from '../../composables/useBackendApi'
const AMOUNT = 1099
const emit = defineEmits<{
success: [paymentIntentId: string]
}>()
const { createPaymentIntent } = useBackendApi()
const { confirmCardPayment } = useConfirmCardPayment()
const { canMakePayment, loading, error, show, on } = usePaymentRequest({
country: 'US',
currency: 'usd',
total: { label: 'Vue Stripe demo', amount: AMOUNT },
requestPayerName: true,
requestPayerEmail: true
})
const payError = ref<string | null>(null)
// Which wallets the browser offers, e.g. "googlePay, link".
const wallets = computed(() =>
canMakePayment.value
? Object.entries(canMakePayment.value)
.filter(([, available]) => available)
.map(([name]) => name)
.join(', ')
: ''
)
on('paymentmethod', async (event) => {
payError.value = null
try {
const { clientSecret } = await createPaymentIntent({ amount: AMOUNT, currency: 'usd' })
// Confirm without handling actions so the browser sheet can close first.
const { paymentIntent, error: confirmError } = await confirmCardPayment(
clientSecret,
{ payment_method: event.paymentMethod.id },
{ handleActions: false }
)
event.complete(confirmError ? 'fail' : 'success')
if (confirmError || !paymentIntent) {
payError.value = confirmError?.message ?? 'Payment failed'
return
}
// 3D Secure and other next actions run after the sheet has closed.
const final =
paymentIntent.status === 'requires_action'
? (await confirmCardPayment(clientSecret)).paymentIntent
: paymentIntent
if (final?.status === 'succeeded') emit('success', final.id)
} catch (err) {
event.complete('fail')
payError.value = err instanceof Error ? err.message : 'Payment failed'
}
})
</script>
<template>
<div class="payment-request-panel">
<dl class="wallet-state" data-test="can-make-payment">
<dt>canMakePayment</dt>
<dd>
<template v-if="loading">Checking for a wallet...</template>
<template v-else-if="canMakePayment">{{ wallets || 'a browser-saved card' }}</template>
<template v-else>No wallet in this browser</template>
</dd>
</dl>
<button v-if="canMakePayment" class="confirm-btn" data-test="payment-request-pay" @click="show">
Pay $10.99
</button>
<p v-else-if="!loading" class="hint">
The Payment Request API needs HTTPS, a wallet (Apple Pay, Google Pay or Link) or a saved card
in this browser. Headless and private windows usually have none. Try the
<a href="/live-demo/express-checkout">Express Checkout Element</a> demo for wallet buttons.
</p>
<div v-if="error || payError" class="error-box">
<strong>Error:</strong> {{ error || payError }}
</div>
</div>
</template>
<style scoped>
.payment-request-panel {
display: flex;
flex-direction: column;
gap: 1rem;
}
.wallet-state {
display: grid;
grid-template-columns: auto 1fr;
gap: 0.25rem 1rem;
margin: 0;
padding: 0.75rem 1rem;
background: var(--vp-c-bg);
border-radius: 6px;
font-size: 0.875rem;
}
.wallet-state dt {
font-family: var(--vp-font-family-mono);
color: var(--vp-c-text-2);
}
.wallet-state dd {
margin: 0;
font-weight: 600;
}
.hint {
margin: 0;
font-size: 0.8125rem;
color: var(--vp-c-text-2);
}
.confirm-btn {
width: 100%;
padding: 0.875rem 1.5rem;
background: #635bff;
color: white;
border: none;
border-radius: 6px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: opacity 0.2s;
}
.confirm-btn:hover {
opacity: 0.9;
}
.error-box {
padding: 0.75rem 1rem;
background: var(--vp-c-danger-soft);
border: 1px solid var(--vp-c-danger-1);
border-radius: 6px;
color: var(--vp-c-danger-1);
font-size: 0.875rem;
}
</style>How the demo works
usePaymentRequest()creates aPaymentRequestfor $10.99 (countryUS, currencyusd) that asks for the payer's name and email, and runscanMakePayment(). The demo prints the result: the wallets this browser offers, orNo wallet in this browser.- The Pay $10.99 button calls
show(), which opens the browser's payment sheet. - When the customer authorizes the payment, the request emits
paymentmethod. The handler, registered withon('paymentmethod', ...), asks the backend to create a PaymentIntent for $10.99. - It then calls
confirmCardPayment()fromuseConfirmCardPayment()with the new PaymentMethod ID andhandleActions: false, so the sheet can close before any 3D Secure step. - The handler closes the sheet with
event.complete('success')orevent.complete('fail'). If the PaymentIntent needs an action such as 3D Secure, it callsconfirmCardPayment()again to run it. - When the PaymentIntent status is
succeeded, the demo shows the PaymentIntent ID.
See also
How-to guide: Add Apple Pay, Google Pay and Link buttons, with the Express Checkout Element that replaces this API. Reference: usePaymentRequest and useConfirmCardPayment.
