繁体   English   中英

Create subscription with Stripe in Lambda function 失败并出现内部服务器错误

[英]Create subscription with Stripe in Lambda function fails with internal server error

我在使用 lambda function 创建带有条带的订阅时遇到问题,此代码在本地运行良好但在发布到 lambda 时返回“内部服务器错误”,cloudwatch 中没有日志。

lambda function 的代码如下

    exports.handler = async (event, context, callback) => {
  // GET ITEMS
  const { productId, customerId, currency = "gbp" } = JSON.parse(event.body);
  let paymentMethods;
  
try {
  paymentMethods = await stripe.paymentMethods.list({
  customer: customerId,
  type: 'card',
});
} catch (e) {
   return {
    statusCode: 200, // http status code
    body: JSON.stringify({
     "error" : true,
     "msg" : "error retrieving payment method",
      "data" : null
    })
  };
}

console.log(paymentMethods)
  


  
  
// Setup subscription
  try {
    const subscription = await stripe.subscriptions.create({
      customer: customerId,
      default_payment_method: paymentMethods.data[0].id,
      items: [
        {price: productId},
      ],
    });
    
    console.log(subscription)
    
  
  // SUCCESS
  return {
    statusCode: 200, // http status code
    body: JSON.stringify({
      "data" :  "success",
      "error" : false,
      "msg" : null
    })
  };
  
  // ERROR
} catch (e) {
  console.log(e);
    return {
    statusCode: 200, // http status code
    body: JSON.stringify({
     "error" : true,
     "msg" : "error",
      "data" : null
    })
  };
}
  
  
};

我可以看到付款方式的日志,但从未显示订阅的日志,但是,这确实在条带门户中针对该客户正确创建了订阅,但没有从 aws 中找到任何响应,只是一个 500 内部服务器错误。

任何帮助将不胜感激。

结果我把我的 lambda function 设置为 3 秒超时,一旦我增加它,function 工作正常,希望如此。 这可能会帮助某人解决同样的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM