Skip to main content

Confirm Card Setup With Elements

@peakgateway/web-sdk exposes elements.confirmCardSetup(clientSecret, cardElement) for the current SetupIntent browser flow:

  1. tokenize card details through the hosted Elements iframe
  2. call the public SetupIntent confirm endpoint with the one-time token plus clientSecret
  3. return the SetupIntent response when no redirect challenge is required

Runtime Contract

This helper depends on the public SetupIntent confirm route being available at:

POST /api/v1/public/setup-intents/{id}/confirm
GET /api/v1/public/setup-intents/{id}?clientSecret=...

If that route is not deployed in your environment yet, the helper fails with SetupIntentApiError.

Example

import {
PeakGateway,
SetupIntentActionRequiredError,
SetupIntentApiError,
} from '@peakgateway/web-sdk'

const peak = new PeakGateway({
sessionId,
sessionToken,
})

const elements = peak.elements()
const card = elements.create('card')

card.mount('#card-element')

try {
const setupIntent = await elements.confirmCardSetup(clientSecret, card)

switch (setupIntent.status) {
case 'SUCCEEDED':
console.log('Card saved', setupIntent.paymentMethodId)
break
case 'REQUIRES_ACTION':
// Current helper behavior for non-redirect next_action shapes until
// the SI-14 follow-up flow is shipped.
console.log('Additional action required', setupIntent.nextAction)
break
default:
console.log('SetupIntent returned', setupIntent.status)
}
} catch (err) {
if (err instanceof SetupIntentActionRequiredError) {
// The helper already started the redirect for redirect_to_url actions.
// On the return page, re-fetch the latest state:
// const latest = await elements.retrieveSetupIntent(clientSecret)
return
}
if (err instanceof SetupIntentApiError) {
console.error(err.status, err.responseBody)
return
}
throw err
}

Current SI-14 Boundary

The helper intentionally stops at the currently shipped browser/runtime contract:

  • redirect_to_url starts a browser redirect and throws SetupIntentActionRequiredError
  • the return page can call elements.retrieveSetupIntent(clientSecret) to inspect the latest state
  • non-redirect nextAction payloads are returned to the caller unchanged
  • there is no public action-complete helper yet for processor-driven 3DS callback completion

That deeper callback flow still depends on the remaining SI-14 runtime wiring.