Skip to content

BECS Direct Debit Example ​

BECS (Bulk Electronic Clearing System) Direct Debit is Australia's primary direct debit payment system. This live demo shows the complete payment flow using the VueStripeAuBankAccountElement component.

Try the demo ​

The demo runs in Stripe test mode against the demo backend at backend.vuestripe.com. BECS Direct Debit needs an Australian Stripe account, and this demo's account is in the US, so choosing a product returns Stripe's au_becs_debit is invalid error; the demo stays as a working code reference. On an Australian test account, Stripe's test bank account is BSB 000000 with account number 000123456.

1Product
2Payment
Complete
0

Select a Product

Loading test products...

Source code ​

The code the demo above runs. Open it in StackBlitz to run and fork it with every file it imports, in Stripe test mode against the demo backend.

View source on GitHub
vue
<script setup lang="ts">
import { ref, computed } from 'vue'
import {
  VueStripeProvider,
  VueStripeElements,
  VueStripeAuBankAccountElement,
  type StripeElementChangeEvent
} from '@vue-stripe/vue-stripe'
import ProductSelector from './ProductSelector.vue'
import PaymentStatus from './PaymentStatus.vue'
import ConfirmBecsButton from './ConfirmBecsButton.vue'
import { useBackendApi, type Product } from '../../composables/useBackendApi'
import { useStripeConfig } from '../../composables/useStripeConfig'
import DocIcon from '../DocIcon.vue'

const { publishableKey } = useStripeConfig()
const { createBecsIntent, loading, error } = useBackendApi()

// Step management: Product → Payment → Complete
const step = ref<'select' | 'payment' | 'complete'>('select')

// State
const selectedProduct = ref<Product | null>(null)
const clientSecret = ref<string | null>(null)
const paymentIntentId = ref<string | null>(null)
const bankName = ref<string | null>(null)
const branchName = ref<string | null>(null)
const isComplete = ref(false)
const mandateAccepted = ref(false)
const customerName = ref('')
const customerEmail = ref('')
const confirming = ref(false)
const confirmError = ref<string | null>(null)

const canConfirm = computed(
  () =>
    !!clientSecret.value &&
    isComplete.value &&
    mandateAccepted.value &&
    customerName.value.trim() !== '' &&
    customerEmail.value.trim() !== '' &&
    !confirming.value
)

// Auto-create intent on product select
async function onProductSelected(product: Product) {
  selectedProduct.value = product
  confirmError.value = null

  try {
    const result = await createBecsIntent({
      amount: product.price.amount || 1000,
      description: `Payment for ${product.name}`
    })
    clientSecret.value = result.clientSecret
    paymentIntentId.value = result.paymentIntentId
    step.value = 'payment'
  } catch (err) {
    confirmError.value = err instanceof Error ? err.message : 'Failed to create payment intent'
  }
}

// Mirrors Stripe.js's StripeAuBankAccountElementChangeEvent.
type AuBankAccountChangeEvent = StripeElementChangeEvent & {
  bankName?: string
  branchName?: string
}

function onAuBankChange(event: AuBankAccountChangeEvent) {
  isComplete.value = event.complete
  if (event.bankName) bankName.value = event.bankName
  if (event.branchName) branchName.value = event.branchName
}

function reset() {
  step.value = 'select'
  selectedProduct.value = null
  clientSecret.value = null
  paymentIntentId.value = null
  bankName.value = null
  branchName.value = null
  isComplete.value = false
  mandateAccepted.value = false
  customerName.value = ''
  customerEmail.value = ''
  confirmError.value = null
}
</script>

<template>
  <div class="au-bank-payment-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>
      <PaymentStatus />

      <div class="account-note">
        <strong><DocIcon name="warning" /> Requires an Australian Stripe account.</strong>
        <p>
          BECS Direct Debit (<code>au_becs_debit</code>) is only available to Stripe accounts based
          in Australia. This public demo's account is in the US, so creating the PaymentIntent
          returns an
          <em>"au_becs_debit is invalid… your account is in US"</em> error. The example below is
          kept as a working code reference.
        </p>
      </div>

      <!-- Progress Steps -->
      <div class="progress-steps">
        <div
          class="progress-step"
          :class="{ active: step === 'select', completed: step !== 'select' }"
        >
          <span class="step-dot">1</span>
          <span class="step-label">Product</span>
        </div>
        <div class="progress-line" :class="{ completed: step !== 'select' }"></div>
        <div
          class="progress-step"
          :class="{ active: step === 'payment', completed: step === 'complete' }"
        >
          <span class="step-dot">2</span>
          <span class="step-label">Payment</span>
        </div>
        <div class="progress-line" :class="{ completed: step === 'complete' }"></div>
        <div class="progress-step" :class="{ active: step === 'complete' }">
          <span class="step-dot"><DocIcon name="check" :size="16" :stroke-width="3" /></span>
          <span class="step-label">Complete</span>
        </div>
      </div>

      <!-- Step 1: Select Product -->
      <div v-if="step === 'select'" class="step-content">
        <ProductSelector filter="one_time" @select="onProductSelected" />
        <div v-if="loading" class="loading-state">
          <span class="spinner"></span> Creating payment intent...
        </div>
        <div v-if="confirmError || error" class="error-box">
          <strong>Error:</strong> {{ confirmError || error }}
        </div>
      </div>

      <!-- Step 2: Payment (BECS Direct Debit) -->
      <div v-else-if="step === 'payment'" class="step-content">
        <div class="step-section">
          <div class="step-header">
            <h3>BECS Direct Debit (Australia)</h3>
            <button class="change-btn" @click="reset">Change Product</button>
          </div>

          <div class="product-summary">
            <span>{{ selectedProduct?.name }}</span>
            <span class="price"
              >AUD {{ ((selectedProduct?.price.amount || 0) / 100).toFixed(2) }}</span
            >
          </div>

          <!-- Customer Details -->
          <div class="customer-fields">
            <div class="field">
              <label for="name">Full Name <span class="required">*</span></label>
              <input
                id="name"
                v-model="customerName"
                type="text"
                placeholder="John Smith"
                required
              />
            </div>
            <div class="field">
              <label for="email">Email <span class="required">*</span></label>
              <input
                id="email"
                v-model="customerEmail"
                type="email"
                placeholder="john@example.com"
                required
              />
            </div>
          </div>

          <div class="stripe-container">
            <VueStripeProvider :publishable-key="publishableKey">
              <VueStripeElements :client-secret="clientSecret!">
                <div class="field">
                  <label>Bank Account (BSB & Account Number)</label>
                  <div class="au-bank-element-wrapper">
                    <VueStripeAuBankAccountElement
                      :options="{ iconStyle: 'solid' }"
                      @change="onAuBankChange"
                    />
                  </div>
                </div>

                <div v-if="bankName" class="bank-info">
                  <DocIcon name="landmark" :size="18" />
                  <div class="bank-details">
                    <strong>{{ bankName }}</strong>
                    <span v-if="branchName"> - {{ branchName }}</span>
                  </div>
                </div>

                <!-- Mandate Agreement -->
                <div class="mandate-section">
                  <label class="mandate-checkbox">
                    <input v-model="mandateAccepted" type="checkbox" />
                    <span class="mandate-text">
                      By providing your bank account details and confirming this payment, you agree
                      to this Direct Debit Request and the
                      <a
                        href="https://stripe.com/au-becs-dd-service-agreement/legal"
                        target="_blank"
                        rel="noopener"
                      >
                        Direct Debit Request service agreement </a
                      >.
                    </span>
                  </label>
                </div>

                <ConfirmBecsButton
                  :can-confirm="canConfirm"
                  :confirming="confirming"
                  :client-secret="clientSecret!"
                  :amount="selectedProduct?.price?.amount"
                  :customer-name="customerName"
                  :customer-email="customerEmail"
                  @confirm-start="confirming = true"
                  @confirm-end="confirming = false"
                  @success="step = 'complete'"
                  @error="(e) => (confirmError = e)"
                />
              </VueStripeElements>
            </VueStripeProvider>
          </div>

          <div v-if="confirmError" class="error-box">
            <strong>Payment Error:</strong> {{ confirmError }}
          </div>
        </div>
      </div>

      <!-- Step 3: Complete -->
      <div v-else-if="step === 'complete'" class="step-content">
        <div class="success-state">
          <span class="success-icon"><DocIcon name="check" :size="32" :stroke-width="2.5" /></span>
          <h3>Payment Initiated!</h3>
          <p>Thank you for your purchase of {{ selectedProduct?.name }}.</p>
          <p class="note">BECS Direct Debit payments typically settle in 3-4 business days.</p>
          <p v-if="paymentIntentId" class="payment-id">
            Payment ID: <code>{{ paymentIntentId }}</code>
          </p>
          <button class="reset-btn" @click="reset">Start Over</button>
        </div>
      </div>
    </template>
  </div>
</template>

<style scoped>
.au-bank-payment-example {
  padding: 1.5rem;
  background: var(--vp-c-bg);
  border: 1px solid var(--vp-c-divider);
  border-radius: 12px;
}
.account-note {
  margin-bottom: 1.25rem;
  padding: 0.875rem 1rem;
  background: var(--vp-c-yellow-soft);
  border: 1px solid var(--vp-c-yellow-1);
  border-radius: 8px;
  color: var(--vp-c-yellow-darker);
}
.account-note strong {
  display: block;
  margin-bottom: 0.25rem;
}
.account-note p {
  margin: 0;
  font-size: 0.85rem;
}
.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;
}
.warning-box code {
  padding: 0.125rem 0.375rem;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

.progress-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2rem;
  padding: 1rem 0;
}
.progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: var(--vp-c-bg-soft);
  border: 2px solid var(--vp-c-divider);
  border-radius: 50%;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--vp-c-text-2);
  transition: all 0.2s;
}
.progress-step.active .step-dot {
  background: var(--vp-c-brand-1);
  border-color: var(--vp-c-brand-1);
  color: white;
}
.progress-step.completed .step-dot {
  background: var(--vp-c-green-1);
  border-color: var(--vp-c-green-1);
  color: white;
}
.step-label {
  font-size: 0.75rem;
  color: var(--vp-c-text-2);
}
.progress-step.active .step-label {
  color: var(--vp-c-brand-1);
  font-weight: 500;
}
.progress-step.completed .step-label {
  color: var(--vp-c-green-1);
}
.progress-line {
  width: 4rem;
  height: 2px;
  background: var(--vp-c-divider);
  margin: 0 0.5rem;
  margin-bottom: 1.5rem;
  transition: background 0.2s;
}
.progress-line.completed {
  background: var(--vp-c-green-1);
}

.step-content {
  min-height: 200px;
}
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 1rem;
  background: var(--vp-c-bg-soft);
  border-radius: 8px;
  color: var(--vp-c-text-2);
}

.step-section {
  padding: 1.5rem;
  background: var(--vp-c-bg-soft);
  border-radius: 8px;
}
.step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.step-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}
.change-btn {
  padding: 0.25rem 0.75rem;
  background: transparent;
  border: 1px solid var(--vp-c-divider);
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--vp-c-text-2);
  cursor: pointer;
}
.change-btn:hover {
  border-color: var(--vp-c-brand-1);
  color: var(--vp-c-brand-1);
}

.product-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: var(--vp-c-bg);
  border-radius: 6px;
}
.product-summary .price {
  font-weight: 700;
  color: var(--vp-c-brand-1);
}

.customer-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
@media (max-width: 640px) {
  .customer-fields {
    grid-template-columns: 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.field label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--vp-c-text-1);
}
.field .required {
  color: var(--vp-c-danger-1);
}
.field input {
  padding: 0.75rem 1rem;
  border: 1px solid var(--vp-c-divider);
  border-radius: 6px;
  font-size: 1rem;
  background: var(--vp-c-bg);
  color: var(--vp-c-text-1);
}
.field input:focus {
  outline: none;
  border-color: var(--vp-c-brand-1);
}

.stripe-container {
  padding: 1rem;
  background: var(--vp-c-bg);
  border-radius: 8px;
}

.au-bank-element-wrapper {
  padding: 0.75rem;
  background: white;
  border: 1px solid var(--vp-c-divider);
  border-radius: 6px;
}
:root.dark .au-bank-element-wrapper {
  background: #1a1a1a;
}

.bank-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--vp-c-green-soft);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--vp-c-green-1);
}
.bank-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.mandate-section {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--vp-c-bg-soft);
  border-radius: 6px;
}
.mandate-checkbox {
  display: flex;
  gap: 0.75rem;
  cursor: pointer;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--vp-c-text-2);
}
.mandate-checkbox input {
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.125rem;
}
.mandate-text a {
  color: var(--vp-c-brand-1);
  text-decoration: underline;
}

.confirm-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 1rem;
  padding: 0.875rem 1.5rem;
  background: #002d5b;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.confirm-btn:hover:not(.disabled) {
  opacity: 0.9;
}
.confirm-btn.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-box {
  margin-top: 1rem;
  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;
}

.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;
}
.success-state p {
  margin: 0.5rem 0;
  color: var(--vp-c-text-2);
}
.success-state .note {
  font-style: italic;
}
.payment-id {
  margin-top: 1rem;
}
.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);
}

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--vp-c-divider);
  border-top-color: var(--vp-c-brand-1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
</style>
vue
<script setup lang="ts">
// Rendered inside VueStripeElements so useStripeElements/useConfirmAuBecsDebitPayment can inject the Stripe context.
import { computed } from 'vue'
import { useConfirmAuBecsDebitPayment, useStripeElements } from '@vue-stripe/vue-stripe'

const props = defineProps<{
  canConfirm: boolean
  confirming: boolean
  clientSecret: string
  amount?: number | null | undefined
  customerName?: string | undefined
  customerEmail?: string | undefined
}>()

const emit = defineEmits<{
  'confirm-start': []
  'confirm-end': []
  success: []
  error: [message: string | null]
}>()

const { getElement } = useStripeElements()
const { confirmAuBecsDebitPayment } = useConfirmAuBecsDebitPayment()

function formatPrice(amount: number | null | undefined) {
  if (!amount) return ''
  return `AUD ${(amount / 100).toFixed(2)}`
}

const disabled = computed(() => !props.canConfirm || props.confirming)

async function confirmPayment() {
  emit('confirm-start')
  emit('error', null)
  try {
    const auBankElement = getElement('auBankAccount')
    if (!auBankElement) throw new Error('AU Bank Account element not found')

    const { error, paymentIntent } = await confirmAuBecsDebitPayment(props.clientSecret, {
      payment_method: {
        au_becs_debit: auBankElement,
        billing_details: {
          name: props.customerName || '',
          email: props.customerEmail || ''
        }
      }
    })
    if (error) throw new Error(error.message)
    if (paymentIntent?.status === 'processing') emit('success')
  } catch (err) {
    emit('error', err instanceof Error ? err.message : 'Payment failed')
  } finally {
    emit('confirm-end')
  }
}
</script>

<template>
  <button :class="['confirm-btn', { disabled }]" :disabled="disabled" @click="confirmPayment">
    {{ confirming ? 'Processing...' : `Pay ${formatPrice(amount)} with BECS` }}
  </button>
</template>
ts
import { ref, readonly } from 'vue'
import { useStripeConfig } from './useStripeConfig'

// Types
export interface ProductPrice {
  id: string
  amount: number | null
  currency: string
  interval: string | null
  intervalCount: number | null
}

export interface Product {
  id: string
  name: string
  description: string | null
  images: string[]
  type: 'one_time' | 'recurring'
  price: ProductPrice
  metadata: Record<string, string>
}

export interface PaymentIntentResult {
  clientSecret: string
  paymentIntentId: string
  amount: number
  currency: string
}

export interface CheckoutSessionResult {
  /** Stripe-hosted page URL (`uiMode: 'hosted'`), otherwise null. */
  url: string | null
  sessionId: string
  /** Client secret for `elements`, `embedded_page` and `form` sessions, otherwise null. */
  clientSecret: string | null
}

export interface SubscriptionResult {
  subscriptionId: string
  clientSecret: string | null
  status: string
  customerId: string
}

export interface SetupIntentResult {
  clientSecret: string
  setupIntentId: string
}

export interface IdentitySessionResult {
  clientSecret: string
  verificationSessionId: string
}

/** Error body returned by the backend on non-2xx responses. */
interface ApiErrorResponse {
  error?: string
}

interface ProductsResponse {
  products?: Product[]
}

/** Parse a JSON response body as the expected backend response shape. */
async function parseJson<T>(response: Response): Promise<T> {
  return (await response.json()) as T
}

/** Throw an Error carrying the backend's error message (or the HTTP status). */
async function throwApiError(response: Response): Promise<never> {
  const data = await parseJson<ApiErrorResponse>(response).catch((): ApiErrorResponse => ({}))
  throw new Error(data.error || `API Error: ${response.status}`)
}

export function useBackendApi() {
  const { apiUrl } = useStripeConfig()
  const loading = ref(false)
  const error = ref<string | null>(null)

  /**
   * Fetch all available products from the backend
   */
  async function getProducts(): Promise<Product[]> {
    loading.value = true
    error.value = null

    try {
      const response = await fetch(`${apiUrl.value}/api/products`)

      if (!response.ok) {
        await throwApiError(response)
      }

      const data = await parseJson<ProductsResponse>(response)
      return data.products || []
    } catch (err) {
      error.value = err instanceof Error ? err.message : 'Failed to fetch products'
      throw err
    } finally {
      loading.value = false
    }
  }

  /**
   * Create a payment intent for a one-time payment
   */
  async function createPaymentIntent(
    options: {
      /** Amount in cents; null/omitted uses the backend default. */
      amount?: number | null
      currency?: string
      priceId?: string
      description?: string
      metadata?: Record<string, string>
    } = {}
  ): Promise<PaymentIntentResult> {
    loading.value = true
    error.value = null

    try {
      const response = await fetch(`${apiUrl.value}/api/payment-intent`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(options)
      })

      if (!response.ok) {
        await throwApiError(response)
      }

      return await parseJson<PaymentIntentResult>(response)
    } catch (err) {
      error.value = err instanceof Error ? err.message : 'Failed to create payment intent'
      throw err
    } finally {
      loading.value = false
    }
  }

  /**
   * Create a regional PaymentIntent (SEPA Direct Debit / BECS / ACH Direct Debit).
   * The backend routes share the same request/response shape.
   */
  async function createRegionalIntent(
    path: 'sepa-debit-intent' | 'becs-intent' | 'ach-debit-intent',
    options: {
      amount?: number
      currency?: string
      description?: string
      metadata?: Record<string, string>
    } = {}
  ): Promise<PaymentIntentResult> {
    loading.value = true
    error.value = null

    try {
      const response = await fetch(`${apiUrl.value}/api/${path}`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(options)
      })

      if (!response.ok) {
        await throwApiError(response)
      }

      return await parseJson<PaymentIntentResult>(response)
    } catch (err) {
      error.value = err instanceof Error ? err.message : `Failed to create ${path}`
      throw err
    } finally {
      loading.value = false
    }
  }

  const createSepaIntent = (options: { amount?: number; metadata?: Record<string, string> } = {}) =>
    createRegionalIntent('sepa-debit-intent', options)
  // BECS Direct Debit (AUD only - Australia)
  const createBecsIntent = (
    options: { amount?: number; description?: string; metadata?: Record<string, string> } = {}
  ) => createRegionalIntent('becs-intent', options)
  // ACH Direct Debit (USD only - United States), bank account linked with Financial Connections
  const createAchIntent = (
    options: { amount?: number; description?: string; metadata?: Record<string, string> } = {}
  ) => createRegionalIntent('ach-debit-intent', options)

  /**
   * Create a checkout session for Stripe hosted checkout
   */
  async function createCheckoutSession(
    options: {
      amount?: number
      currency?: string
      priceId?: string
      productName?: string
      productDescription?: string
      quantity?: number
      mode?: 'payment' | 'subscription' | 'setup'
      successUrl?: string
      cancelUrl?: string
      customerEmail?: string
      metadata?: Record<string, string>
      /** `hosted` (default) returns `url`; the other modes return `clientSecret`. */
      uiMode?: 'hosted' | 'elements' | 'embedded_page' | 'form'
      /** Where Stripe sends the customer after a non-hosted session completes. */
      returnUrl?: string
      taxIdCollection?: boolean
    } = {}
  ): Promise<CheckoutSessionResult> {
    loading.value = true
    error.value = null

    try {
      const response = await fetch(`${apiUrl.value}/api/checkout-session`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(options)
      })

      if (!response.ok) {
        await throwApiError(response)
      }

      return await parseJson<CheckoutSessionResult>(response)
    } catch (err) {
      error.value = err instanceof Error ? err.message : 'Failed to create checkout session'
      throw err
    } finally {
      loading.value = false
    }
  }

  /**
   * Create a subscription
   */
  async function createSubscription(options: {
    priceId: string
    customerEmail: string
    paymentMethodId?: string
    name?: string
    metadata?: Record<string, string>
  }): Promise<SubscriptionResult> {
    loading.value = true
    error.value = null

    try {
      const response = await fetch(`${apiUrl.value}/api/subscription`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(options)
      })

      if (!response.ok) {
        await throwApiError(response)
      }

      return await parseJson<SubscriptionResult>(response)
    } catch (err) {
      error.value = err instanceof Error ? err.message : 'Failed to create subscription'
      throw err
    } finally {
      loading.value = false
    }
  }

  /**
   * Create a setup intent for saving payment methods
   */
  async function createSetupIntent(
    options: {
      customerId?: string
      description?: string
      metadata?: Record<string, string>
    } = {}
  ): Promise<SetupIntentResult> {
    loading.value = true
    error.value = null

    try {
      const response = await fetch(`${apiUrl.value}/api/setup-intent`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(options)
      })

      if (!response.ok) {
        await throwApiError(response)
      }

      return await parseJson<SetupIntentResult>(response)
    } catch (err) {
      error.value = err instanceof Error ? err.message : 'Failed to create setup intent'
      throw err
    } finally {
      loading.value = false
    }
  }

  /**
   * Create a Stripe Identity VerificationSession (document check)
   */
  async function createIdentitySession(): Promise<IdentitySessionResult> {
    loading.value = true
    error.value = null

    try {
      const response = await fetch(`${apiUrl.value}/api/identity-session`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({})
      })

      if (!response.ok) {
        await throwApiError(response)
      }

      return await parseJson<IdentitySessionResult>(response)
    } catch (err) {
      error.value = err instanceof Error ? err.message : 'Failed to create verification session'
      throw err
    } finally {
      loading.value = false
    }
  }

  /**
   * Format price for display
   */
  function formatPrice(amount: number | null, currency: string): string {
    if (amount === null) return 'Price not available'

    return new Intl.NumberFormat('en-US', {
      style: 'currency',
      currency: currency.toUpperCase()
    }).format(amount / 100)
  }

  return {
    // State
    loading: readonly(loading),
    error: readonly(error),
    apiUrl,

    // Methods
    getProducts,
    createPaymentIntent,
    createSepaIntent,
    createBecsIntent,
    createAchIntent,
    createCheckoutSession,
    createSubscription,
    createSetupIntent,
    createIdentitySession,

    // Helpers
    formatPrice
  }
}

How the demo works ​

  1. The product step loads the demo account's one-time products from the backend.
  2. Choosing a product asks the backend to create a BECS Direct Debit PaymentIntent in Australian dollars for the product's amount. On this demo's US account, this is the step that fails.
  3. VueStripeElements gets the client secret and wraps VueStripeAuBankAccountElement (with iconStyle: 'solid'), which collects the BSB and account number. Its change event reports complete, and the bank and branch names once Stripe recognizes the BSB; the demo shows them.
  4. The Pay button needs a name, an email address and the Direct Debit Request mandate checkbox. The mandate text links Stripe's BECS service agreement.
  5. The button gets the mounted element with getElement('auBankAccount') from useStripeElements() and calls confirmAuBecsDebitPayment() from useConfirmAuBecsDebitPayment() with payment_method: { au_becs_debit: element, billing_details: { name, email } }.
  6. Stripe returns the PaymentIntent in processing, and the demo shows its ID.

Settlement Time

BECS Direct Debit payments don't confirm instantly like cards. They typically settle in 3-4 business days. You'll need to use webhooks to track the final payment status.

See also

How-to guide: Accept BECS Direct Debit. Reference: VueStripeAuBankAccountElement.