EXPECTED_INTEGER - Square支付门户的问题

时间:2017-09-06 14:38:15

标签: integer payment square-connect

我遇到通过我的电子商务网站接受付款的问题。这似乎只是随机发生的,我已经接受了以前没有问题的付款,但每次都经常发生这种情况。 Square API没有任何带有错误代码的描述。

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.

2 个答案:

答案 0 :(得分:0)

每当您尝试使用非整数值(例如小数或浮点数)的数量进行充电时,就会发生此错误。你可以做的一件事就是检查并确保你收取的金额类型是一个整数。

此外,感谢您对Square&#39的开发人员文档的反馈。我们会根据此类反馈不断改进产品,因此我们一定会与相应的团队分享您的想法。

答案 1 :(得分:0)

我有类似的问题。我的输入字段传递的数字被读取为字符串而不是整数。即使前端控制台中的输出看起来像一个整数,我也注意到后端req.body后面的数字用引号引起来。解决方法是使用parseInt去除引号。我的代码基于后端的Node / Express和前端的Handlebars。我希望这个例子对您有帮助:

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