Error message PHP

When doing this:
$api_response = $client->getCustomersApi()->createCustomerCard($square_customer_id, $body);

There’s an error. With this command:
$errors = json_encode($api_response->getErrors());

I get:
[{“category”:“INVALID_REQUEST_ERROR”,“code”:“INVALID_CARD_DATA”,“detail”:“Invalid card data.”}]

Is there a PHP code that will get what EXACTLY the issue is? Like if it’s the card number that is wrong or zip etc?
Thanks.

Hey @Andrea! This INVALID_CARD_DATA error actually comes from the card issuer (usually a bank), not from Square itself. Square can only return an error that’s as specific as the details provided by the card issuer. You may find it helpful to handle this error by prompting your users to check their card details and try again, or contact their card issuer if they continue to get the error.

You can use $validator->messages() that returns an array which contains all the information about the validator, including errors. The json function takes the array and encodes it as a json string.

Hi @Alley69,

Can I do this you mean?
$errors = $api_response->messages()
or:
$errors = $validator->messages()