Skip to main content
On this page

initElements opens a focused credential experience without requiring Payment Widget. Use it to vault a card, run Click to Pay, or launch a configured native wallet.

Choose an Elements type#

TypePurposeIdentity or order context
vaultTokenize or select a stored card. This is the default when types is omitted.userToken for an authenticated user, or userInfo; an orderToken can add amount and installment context.
click_to_payOpen the Click to Pay experience.Customer identity and merchant configuration are required.
APPLE_PAYLaunch Apple Pay after availability succeeds.Order context and configured wallet credentials.
GOOGLE_PAYLaunch Google Pay after availability succeeds.Order context and configured wallet credentials.

Vault a card#

JavaScript
await DeunaSDK.initElements({
  orderToken,
  userInfo: {
    firstName: 'Ada',
    lastName: 'Lovelace',
    email: 'ada@example.com',
  },
  types: [{name: 'vault'}],
  callbacks: {
    onSuccess: (credential) => useCredentialResult(credential),
    onError: ({type, metadata}) => showRecovery(type, metadata.code),
    onClosed: () => restorePaymentMethods(),
    onCardBinDetected: ({cardBin, cardBrand}) => updateCardOffers(cardBin, cardBrand),
    onInstallmentSelected: ({installmentPlanOptionId}) => rememberPlan(installmentPlanOptionId),
  },
});

Experience flow#

Flow diagram
1Initialize Web SDK2-- APPLE_PAY /GOOGLE_PAY3Enter or selectcredential4Complete Click toPay5Open native walletsheet6onSuccess credentialresult7Continue merchantbackend flow
Result or outcomeMerchant or customer

Preload Elements#

JavaScript
await DeunaSDK.initialize({
  publicApiKey: 'YOUR_PUBLIC_API_KEY',
  env: 'sandbox',
  preloadWidgets: [
    {
      widget: 'elements',
      params: {
        types: [{name: 'vault'}],
        language: 'en',
        callbacks,
      },
    },
  ],
});

// Add the order or user context and reveal the prepared experience.
await DeunaSDK.initElements({orderToken, userToken});

Initialization parameters and the later call are merged by the SDK. Put stable configuration in the preload entry and the freshest tokens in initElements.

Parameters#

ParameterRequiredPurpose
typesNoExperience selection; defaults to vault.
orderTokenFlow-dependentOrder context for amount, installments, payment, or wallet launch.
userTokenFlow-dependentAuthenticated DEUNA user context.
userInfoFlow-dependentPartial customer identity: firstName, lastName, and email.
callbacksNo, recommendedSuccess, error, close, event, resize, BIN, and installment handlers.
mode + targetNoEmbedded target presentation instead of the default modal.
walletConfigAdvancedApproved explicit Apple Pay or Google Pay configuration.
behaviorNoSupported tokenize, purchase, split-card, and visibility behavior.
language, styleFile, widgetExperienceNoLocalization and supported appearance overrides.
domainNoControlled host override; omit in standard production integrations.

Tokenize or purchase#

The credit-card Elements behavior supports tokenize or purchase:

JavaScript
behavior: {
  paymentMethods: {
    creditCard: {
      flow: 'tokenize',
    },
  },
}

Use tokenize when the merchant flow only needs a reusable credential. Use purchase only with the required order and merchant configuration. Keep the backend responsible for deciding how the credential may be used.

Native wallets#

Check availability before rendering your button, then launch the matching type directly from the customer gesture:

JavaScript
const wallets = await DeunaSDK.getWalletsAvailable({orderToken, userInfo});
applePayButton.hidden = !wallets.includes('APPLE_PAY');

applePayButton.addEventListener('click', () => {
  DeunaSDK.initElements({
    orderToken,
    userInfo,
    types: [{name: 'APPLE_PAY'}],
    callbacks,
  });
});

See Wallet availability for platform values, caching, and troubleshooting.

Embedded and controlled modes#

Use mode: 'target', target, and onResize for an embedded experience. When your page owns the primary action, set hidePayButton: true, call isValid(), then await submit(). Disable the outer button while submission is pending.

JavaScript
await DeunaSDK.initElements({
  orderToken,
  types: [{name: 'vault'}],
  mode: 'target',
  target: '#credential-entry',
  hidePayButton: true,
  callbacks: {
    onResize: ({height}) => {
      document.querySelector('#credential-entry').style.height = `${height}px`;
    },
    onSuccess: useCredentialResult,
    onError: showRecovery,
  },
});

Migrate legacy secure fields#

Earlier documentation described modularPaymentCredentialsStorage, mountPaymentCredentialStorage, and a separate sdk.deuna.io secure-field bundle. Those names are not present in the audited current Web SDK public types or implementation. Do not copy the legacy initialization or field-mounting snippets into a new integration.

The maintained credential surface is hosted Elements through DeunaSDK.initElements:

Flow diagram
1Legacy per-fieldintegration2Inventory identity,order, styling, andsubmit ownership3Initialize currentWeb SDK4Open types: [{name:'vault'}]5Handle dedicatedcallbacks6Continue through themerchant backend
Merchant or customer
Legacy responsibilityMaintained approach
Load sdk.deuna.io/.../main.min.jsLoad the pinned current cdn.deuna.io/web-sdk/.../index.js bundle from Get started
Initialize a Deuna or deunaSDK.init instanceCall DeunaSDK.initialize once with the public API key and explicit environment
Mount independent PAN, expiry, or CVV fieldsOpen hosted initElements({types: [{name: 'vault'}]}) in modal or embedded target mode
Own a merchant submit buttonUse hidePayButton, isValid(), and submit() in the supported controlled mode
Parse a legacy credential eventUse onSuccess, onError, onClosed, and the dedicated BIN/installment callbacks
Reuse a legacy checkout sessionPass the current orderToken, userToken, or userInfo required by the chosen flow

Hosted Elements owns the sensitive input UI. The current public SDK does not expose a one-to-one API for mounting each card field into unrelated merchant DOM nodes. If your approved PCI scope or product design requires independent field ownership, stop the migration and confirm a supported architecture with DEUNA before implementation.

When migrating, run the old and new experience only in separate controlled test cohorts. Never initialize both against the same customer action or attempt to copy values from legacy secure frames into Elements.

Security and operations#

  • Do not read, mirror, or log card fields rendered by Elements.
  • Send the result only to the merchant backend operation that needs it.
  • Expire merchant sessions and SDK state together when the customer signs out.
  • Reconcile an order after an interrupted purchase-mode flow.
  • Treat onSuccess as a client result, not permission to use a credential outside the customer’s consent and merchant contract.