Square Payment api error

While testing the Square CreateAsync API in .NET, I tried to simulate an error from the dashboard. The response I received was:
{
“errors”: [ ],
“payment”: {}
}
My question is: when the API returns an error, is it still possible to access the payment object from the .NET SDK?

:waving_hand: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Handling Errors
Take Payments
Develop for Japan

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

This did not help but i got the payment object from error.body .

When the Square API returns an error, the response typically includes an errors array with details about the error(s) encountered. In the case of the CreatePayment endpoint, if an error occurs, the payment object in the response is usually not populated with meaningful data, as the payment process was not successfully completed.

In your specific scenario, where the response shows an empty errors array and an empty payment object, it suggests that the API call did not succeed in creating a payment, and therefore, there is no payment object to access. The .NET SDK would reflect this by not providing a populated payment object in the response.

If you encounter an error during an API call, you should focus on the errors array to understand what went wrong. The payment object would only be meaningful if the payment was successfully created or partially processed, which does not seem to be the case here.

This answer was reviewed by @Bryan-Square.

In my scenario, I need the payment.id because it is returned in both success and error cases. I wanted to confirm whether this payment.id can be accessed even when the payment request fails. This is now resolved, so there’s no issue.