Logically, my code runs in this order:
- Create customer
- Create card (want to save card to customer’s profile)
- Create payment
However, I notice that when using the test cards here from the section “Error state values” https://developer.squareup.com/docs/devtools/sandbox/payments
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.
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.