Advanced Usage

Custom Element Configurations

Define a custom set and order of payment elements if <NekudaPaymentForm> doesn’t fit your needs. This feature relies on you providing an elementId to your element instances that matches the elementId specified in the configuration here.

Custom Placeholders

Provide custom placeholder text for elements. You can set these globally on <NekudaWalletProvider> using the placeholders prop (targeting by element type or by a specific elementId), or directly on an individual element instance via its placeholder prop or options.placeholder. Beyond visual styles, you can also customize the placeholder text for form inputs. This can be done globally using the placeholders prop on the <NekudaWalletProvider> (see the Custom Placeholders subsection under Advanced Usage for details), or for individual elements using their options prop. For example, to set a placeholder for a specific CardNumberElement:
<CardNumberElement options={{ placeholder: "Enter your card number" }} />
Refer to the documentation for each element to see available styling selectors and properties.

Advanced Card Management Patterns

Integrating Card Management with Checkout Flows

Create a seamless checkout experience by combining saved cards with new payment options:

Programmatic Card Management

Use the API service directly for custom card management implementations:

Multi-step Forms with Card Selection

Implement complex checkout flows with card selection as a step:

Subscription Management with Saved Cards

Handle recurring payments and subscription updates:

Prefilling Form Data

The Nekuda SDK provides a clean, programmatic API for prefilling form fields with customer data. This eliminates the need for manual DOM queries or understanding internal iframe communication. The prefill API is exposed through the elements object from the useNekudaWallet hook:
const { elements } = useNekudaWallet();

API Methods

prefill(data: Partial<CardFormData>)
function
Prefills multiple fields at once with a data object.
elements.prefill({
  email: "john@example.com",
  billingAddress: "123 Main St",
  city: "New York",
  state: "NY",
  zipCode: "10001",
  phoneNumber: "+1234567890",
});
prefillField(fieldType: NekudaElementType, value: string)
function
Prefills a specific field by its type.
elements.prefillField("email", "john@example.com");
clearField(fieldType: NekudaElementType)
function
Clears a specific field.
elements.clearField("email");
clearAll()
function
Clears all form fields.
elements.clearAll();

Field Types

The following field types are supported for prefilling. The key in the prefill method corresponds to the CardFormData type, which maps to a NekudaElementType.
  • email - Email address
  • billingAddress - Billing address
  • city - City
  • state - State/Province
  • zipCode - ZIP/Postal code
  • phoneNumber - Phone number

Example Usage

Best Practices

  1. Wait for SDK Readiness: Ensure the SDK is loaded and iframes are ready before calling prefill methods. You may need to add a small delay.
  2. Security: When handling sensitive data like card numbers, ensure it is transmitted securely to the frontend and cleared from memory as soon as it’s passed to the SDK.
  3. User Experience: Consider prefilling non-sensitive fields (email, address) automatically, while letting users enter sensitive card details manually for security peace of mind.
  4. Validation: The SDK will validate prefilled data. Invalid data will be rejected by the secure iframes, and the fields will show an error state.

Migration from Direct DOM Access

If you were previously using document.querySelectorAll to find iframes and send messages directly: The new API provides several advantages:
  • Handles iframe communication internally
  • Manages secure origins properly
  • Provides type safety for field names
  • Works consistently across different environments
  • Simplifies error handling and validation feedback