How to get card errors before createPayment is called?

Logically, my code runs in this order:

  1. Create customer
  2. Create card (want to save card to customer’s profile)
  3. Create payment

However, I notice that when using the test cards here from the section “Error state values”

The helpful error messages only pop up during step #3, which means that in my order of operations, step #2 will fail, but with a very generic “invalid card data” error regardless of what the problem actually is. To be fair this all follows the docs… but it doesn’t make logical sense to me, because “invalid card data” isn’t really helpful to the user. Like, the helpful user error messages only happen if Step #3 were hit, but the process will fail in Step #2.

When a card is saved on file it isn’t validated like it is when a payment is made. The stored card information is saved within Square and not fully validated like it is when you create a payment which is why you get the detailed error message at step 3. :slightly_smiling_face:

but then is there anything wrong with my flow? because if my flow is correct then that + what you just said implies that whenever the API is used in a context to create a customer & card before charging, no granular error messages will ever bubble up to the customer… which seems like really bad UX

No there’s nothing wrong with your flow and that is the recommended flow. At this time no granular error message is available when saving the card on file cause it’s not being verified by the card network. Once it hits the card network then the information is available. :slightly_smiling_face: