EXPECTED_INTEGER — Issues with Square payment portal

无人久伴 提交于 2019-12-02 02:19:02

问题


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.

回答1:


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.




回答2:


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'
        },


来源:https://stackoverflow.com/questions/46078084/expected-integer-issues-with-square-payment-portal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!