EXPECTED_INTEGER — Issues with Square payment portal

后端 未结 2 913
借酒劲吻你
借酒劲吻你 2021-01-21 17:16

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

2条回答
  •  佛祖请我去吃肉
    2021-01-21 17:58

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

提交回复
热议问题