I'm having issues accepting payment through my ecommerce site. This only seems to happen randomly, I've accepted payment previous without issue but every so often this happens. Square API didn't have any description with the error code.
Array
(
[0] => stdClass Object
(
[category] => INVALID_REQUEST_ERROR
[code] => EXPECTED_INTEGER
[detail] => Expected an integer value.
[field] => amount_money.amount
)
)
Order status changed from Pending payment to Failed.
This error occurs whenever you try to charge with an amount that is not an integer value, such as a decimal or a floating point number. One thing you can do to prevent this is to check and make sure the type of amount you're charging is a whole number.
Additionally, thank you for the feedback about Square's Developer Doc. We are constantly improving the product based on feedback like this, so I’ll be sure to share your thoughts with the appropriate team.
I had a similar problem. The numbers that were being passed by my input field were being read as strings instead of integers. Even though the output in the front end console read like an integer, I noticed on the backend the numbers coming back form req.body had quotes around them. The fix was to use parseInt to strip the quotes away. My code is based on Node/Express on the backend and Handlebars on the frontend. I hope this example helps:
//the name chargeAmount is passed to the server holding contain the value of the input
<input name="chargeAmount">
// on the backend req.body is set to a variable and then that variable
// is passed to another variable and parsed where the foo object contains
// the amount I want to charge. The parseInt() method insures that the " "
// are removed from the string and allows the integer to be passed into the
// object. When you're running your tests, make sure that the integer does
// not have quotes around it. If it does, then the back end reads that data
// as a string and not an integer
var foo = req.body;
var bar = parseInt(foo.chargeAmount)
var request_body = {
card_nonce: foo.nonce,
amount_money: {
amount: bar,
currency: 'USD'
},