Confirm Card Setup With Elements
@peakgateway/web-sdk exposes elements.confirmCardSetup(clientSecret, cardElement) for the current SetupIntent browser flow:
- tokenize card details through the hosted Elements iframe
- call the public SetupIntent confirm endpoint with the one-time token plus
clientSecret - return the
SetupIntentresponse 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_urlstarts a browser redirect and throwsSetupIntentActionRequiredError- the return page can call
elements.retrieveSetupIntent(clientSecret)to inspect the latest state - non-redirect
nextActionpayloads are returned to the caller unchanged - there is no public
action-completehelper yet for processor-driven 3DS callback completion
That deeper callback flow still depends on the remaining SI-14 runtime wiring.