Stripe payments 如何使用Wix http函数为条带创建Wix Webhook端点?

Stripe payments 如何使用Wix http函数为条带创建Wix Webhook端点?,stripe-payments,webhooks,velo,Stripe Payments,Webhooks,Velo,我在第节中使用此选项: 6:确认付款成功,从Stripe Dashboard测试webhook 更新:我已安装,并在Wix的软件包管理器中。这是我在Wix中为http-function.js编写的最新代码: import {ok, badRequest, response} from 'wix-http-functions'; import stripe from 'stripe'; import express from 'express'; import wixData from 'wix-

我在第节中使用此选项:

6:确认付款成功,从Stripe Dashboard测试webhook

更新:我已安装,并在Wix的软件包管理器中。这是我在Wix中为http-function.js编写的最新代码:

import {ok, badRequest, response} from 'wix-http-functions';
import stripe from 'stripe';
import express from 'express';
import wixData from 'wix-data';
import bodyparser from 'body-parser';

const key = require('stripe')('sk_test_XXXX'); //use your own Secret Key

const endpointSecret = 'whsec_XXXXXX'; //stripe webhook signing secret

const app = require('express')();

const bodyParser = require('body-parser');

let responseBody = {
          "status": 200,
        };

export function post_checkoutUpdate(request) {


//console.log("Running the function"); // this one works

    app.post('/webhook', bodyParser.raw({type: 'application/json'}), (request, response) => {
  const sig = request.headers['stripe-signature'];

  console('Inside app.post'); //the code doesn't reach here

  let event;

  try {
    event = key.webhooks.constructEvent(request.body, sig, endpointSecret);
  } catch (err) {
    return response.status(400).send(`Webhook Error: ${err.message}`);
  }


  // Handle the checkout.session.completed event
  if (event.type === 'checkout.session.completed') {
    const session = event.data.object;

   console('Checked'); //the code doesn't reach here too

  }

  // Return a response to acknowledge receipt of the event
  response.json({received: true});
});

app.listen(8000, () => console.log('Running on port 8000'));

return response(responseBody);

}
从Stripe Dashboard,我已向此webhook端点发送了一个测试事件:https://www/_functions/checkoutUpdate

现在,测试webhook已成功发送,我可以从服务器接收HTTP状态代码:200OK。但是,代码没有运行app.post,我从Wix站点监控工具收到以下错误:

"jsonPayload":{
"message":"["(node:1) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead."]"
}

任何帮助都将不胜感激,谢谢

您可以将try-catch合并到代码中,然后打开以开始记录后端日志。一旦得到更详细的响应,我们就可以开始调试正在发生的事情。

您不需要express,我就是这样做的:

import { ok, badRequest, response } from 'wix-http-functions';
import stripe from 'stripe';
import wixData from 'wix-data';

const key = require('stripe')('sk_test_XXXX'); //use your own Secret Key
const endpointSecret = 'whsec_XXXXXX'; //stripe webhook signing secret
let responseBody = {
   "status": 200,
};

export async function post_checkoutUpdate(request) {

    const sig = request.headers['stripe-signature'];
    let event;
    const rawBody = await request.body.text()

    try {
        event = key.webhooks.constructEvent(rawBody, sig, endpointSecret);
    } catch (err) {
        return response.status = 400
    }

   // Handle the checkout.session.completed event
   if (event.type === 'checkout.session.completed') {
      const session = event.data.object;
      console('Checked');
   }

   // Return a response to acknowledge receipt of the event
   response.status = 200
   return response(responseBody);
}

谢谢你的建议!我已经更新了代码并使用了站点监控工具。请参阅上述问题中的更新。