State management
Manage checkout state carefully to avoid re-initialization and stale data. Keep configuration objects stable and observe state changes with lifecycle-aware collectors.- Web
- Android
- iOS
Define options outside functions
Create options objects once and reuse them to avoid unnecessary re-initialization:The SDK performs deep comparison to detect actual changes in the
options object. Using stable references (the GOOD pattern above) minimizes comparison overhead and remains the recommended best practice for optimal performance.Error handling
Log diagnostics IDs and handle failures gracefully. Every error from the SDK includes identifiers that help Primer support diagnose issues.- Web
- Android
- iOS
Performance
Minimize unnecessary re-renders and keep configuration stable. Initialize the SDK as early as possible so it can prefetch configuration while the user navigates.- Web
- Android
- iOS
Security
Never expose API keys in client code. Keep configuration minimal and handle sensitive data on your server.- Web
- Android
- iOS
Distinguish between component properties and SDK options
Component Properties are HTML attributes that configure the component container. SDK Options are configuration settings for the SDK itself.Component Properties (usesetAttribute()):client-token- API authenticationcustom-styles- Visual themingloader-disabled- Loader behavior
options object):locale- UI language- Payment method configuration
- Feature settings
- Merchant domain and API settings
Keep options simple and focused
Only configure what you need:Testing
Use sandbox mode with test cards to verify your integration before going to production.- Web
- Android
- iOS
Test your checkout in a sandbox environment. Verify that:
- Options are applied correctly
- Events fire as expected
- Error handling works for declined cards
- All payment methods render properly