如何在完成从 express 中剥离 api 后发出另一个 post 请求?

how to make another post request after one is done to stripe api from express?

我正在尝试订阅 stripe,为此我需要先创建一个用户 - 完成。 创建用户后,如何自动继续为给定用户进行订阅?

到目前为止我的代码

const stripe = require('./../constants/stripe');

const postStripeCharge = res => (stripeErr, stripeRes) => {
  if (stripeErr) {
    res.status(500).send({
      error: stripeErr
    });
  }
  else {
    res.status(200).send({
      success: stripeRes
    });
  }
}

const paymentApi = app => {
  app.get('/', (req, res) => {
    res.send({
      message: 'Hello Stripe checkout server!',
      timestamp: new Date().toISOString()
    })
  });

  app.post('/', (req, res) => {
    console.log('request in server', req);

    // stripe.charges.create(req.body, postStripeCharge(res));
    stripe.customers.create({
      description: 'customer for ' + req.body.email,
      source: req.body.token
    }, postStripeCharge(res))
  });

  return app;
};

module.exports = paymentApi;

这是我想在创建用户后调用的代码:

stripe.subscriptions.create({
          customer: req.id,
          items: [{
            plan: 'plan_CyQRCVcrEztYI7'
          }],
        }

修复了它:它不是 req.body.token 而是 req.body.source,然后它就可以正常工作了。