Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript NodeJS,ExpressJS,Stripe-Error:Parse Error-on-payment_Javascript_Node.js_Express_Http_Stripe Payments - Fatal编程技术网

Javascript NodeJS,ExpressJS,Stripe-Error:Parse Error-on-payment

Javascript NodeJS,ExpressJS,Stripe-Error:Parse Error-on-payment,javascript,node.js,express,http,stripe-payments,Javascript,Node.js,Express,Http,Stripe Payments,在Windows上运行良好(Windows 10,节点v13.10.1,NPM 6.14.4) Linux上的错误(Ubuntu 18.04,节点v12.16.2,NPM 6.14.4) 当我使用LinuxWeb服务器使用条带活动密钥或测试密钥支付某些东西时,就会发生这种情况。 当我在本地Windows PC上使用测试键时,它工作正常 router.post('/stripe-webhook', async(req, res) => { try { // TODO: add

  • 在Windows上运行良好(Windows 10,节点v13.10.1,NPM 6.14.4)
  • Linux上的错误(Ubuntu 18.04,节点v12.16.2,NPM 6.14.4)
当我使用LinuxWeb服务器使用条带活动密钥或测试密钥支付某些东西时,就会发生这种情况。 当我在本地Windows PC上使用测试键时,它工作正常

router.post('/stripe-webhook', async(req, res) => {
  try {
    // TODO: add better validation
    if (!req.headers['stripe-signature']) return;

    const id = req.body.data.object.metadata.id;
    if (req.body.type === 'checkout.session.completed') {
      await giveUserPlus(id);
      return res.json({ success: true });
    }
    res.json({ received: true });
  } catch (error) { res.status(400).send(error); } 
});


修复:我更改了NodeJS版本以修复它。

console.log(req.headers)
或调试,以查找headers的值和要修改的内容。更新帖子以在购买时显示req正文。在linux上安装相同版本的node,然后检查。