Two types of errors
Before implementing error handling, it’s important to understand the difference between validation errors and payment failures:| Type | When it occurs | How it’s handled |
|---|---|---|
| Validation errors | During form input (invalid card number, missing fields) | Handled automatically by input components; prevents form submission |
| Payment failures | After form submission (declined card, insufficient funds) | Requires explicit handling with error container or custom code |
Default error behavior
- Web
- Android
- iOS
The
<primer-error-message-container> specifically handles payment failures that occur after form submission, not card validation errors. Card validation is handled by the input components themselves and prevents form submission until valid.Built-in error display
- Web
- Android
- iOS
The For optimal user experience, place the error container:
<primer-error-message-container> provides a convenient way to display payment failures without writing custom code:- Prominently where it will be visible after a payment attempt
- Near the action where users will naturally look for feedback after submitting payment
- In context within the same visual area as the payment method it relates to
Error properties
Every error from the SDK includes diagnostic information to help identify and resolve issues.- Web
- Android
- iOS
| Property | Description |
|---|---|
code | Error code identifying the failure type |
message | Human-readable error message |
diagnosticsId | Reference ID for Primer support |
Custom error handling
- Web
- Android
- iOS
You can implement your own payment failure handling using the SDK callbacks and events. Choose one of the following approaches:This approach gives you complete control over payment failure presentation but requires you to implement the error handling logic yourself.
- Callbacks (primer:ready)
- State change event
Choosing the right approach
| Approach | Best for | Trade-offs |
|---|---|---|
| Built-in error display | Quick implementation, consistent styling | Less customization control |
| Custom error handling | Full control over UX and design | More code to maintain |
Best practices
See also
Error message container
Web component SDK reference
Android SDK reference
Android SDK API documentation
Events guide
Complete reference for all checkout events
Log Errors Guide
Capture and log payment errors for debugging