Skip to main content
This guide covers advanced layout customization techniques for when you need complete control over your checkout experience.

Fully custom implementation

For complete control, you can bypass <primer-main> entirely and provide your own implementation.Choose one error display approach:Option A: Built-in error container
Option B: Custom error element
Implementation responsibilityWhen using this approach:
  • You must handle state management yourself through events
  • You have complete freedom over the layout and user flow
  • You’re responsible for showing/hiding appropriate content based on checkout state
  • You need to handle payment failure display, either with the <primer-error-message-container> component or by implementing custom error handling with events

Events

When implementing a custom layout, you need to listen for events to manage checkout states. For comprehensive information on all available events, event payloads, and best practices, see the Events Guide.
  • primer:state-change - Fired when checkout state changes
  • primer:methods-update - Fired when available payment methods are loaded
  • primer:ready - Fired when the SDK is ready

Configuring payment methods

When customizing the payment method layout, you can include specific payment methods:
The type attribute specifies which payment method to display. If a payment method isn’t available in your Dashboard configuration, it simply won’t render.

Payment method filtering with include, exclude and type

The primer-payment-method-container component provides a declarative way to organize payment methods:
This approach automatically filters available payment methods without requiring event listeners or manual state management. See the Payment Method Container SDK Reference documentation for complete usage guide.

Dynamic rendering with events

You can also dynamically render payment methods by listening to the primer:methods-update event:
This approach ensures you only display payment methods that are actually available.

Avoiding duplicate card forms

When customizing your checkout layout, be careful not to render duplicate card forms. This commonly happens when:
  1. You create a custom card form using <primer-card-form>
  2. You also include <primer-payment-method type="PAYMENT_CARD"> in your layout
If you’re using a custom card form implementation, you should not include the PAYMENT_CARD payment method in your layout.
Important: If you’re using a custom card form, you should filter out the PAYMENT_CARD type to avoid duplicate card forms:

Best practices

  1. Listen for relevant events - Handle checkout state through event listeners (Web) or by observing checkout.state (Android)
  2. Design responsively - Ensure your layout works on all device sizes
  3. Test thoroughly - Validate behavior across different payment methods and scenarios
  4. Prevent component flash - Use CSS or JavaScript techniques to hide content until components are defined (Web), or observe PrimerCheckoutState.Ready before rendering (Android)
  5. Handle payment failures - Either use the <primer-error-message-container> component (Web) or match on PrimerCheckoutState.Failure from checkout.state (Android)

See also

Error handling

Handle payment failures and display error messages

Events guide

Complete reference for all checkout events