条带API的POST只能从前端而不是lambda工作



我想使用请求库发布到stripe API,只有当我通过应用程序的前端发布时,我的代码才成功(我只是为了测试目的才这样做(。显然,我想通过lambda来实现这一点,这样我就可以在后台使用stripe API密钥来实现安全目的。这是我的前端代码:

await request({
url: 'https://api.stripe.com/v1/customers?email=' + currentSessionEmail + "&description=" + sessionUsername,
method: 'POST',
headers: {
'Authorization': 'Bearer my_key4534343432',
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Access-Control-Allow-Origin': "*",
"Access-Control-Allow-Credentials": true
},
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log('BODY: ', body);
//var jsonResponse = JSON.parse(body); // turn response into JSON

// do stuff with the response and pass it to the callback...
//console.log(JSON.stringify(response));

}else{
alert(error);
}
}); 

我的lambda函数内部有相同的代码,它使用200进行解析,但它没有正确执行Stripe API,否则我会看到在我的Stripe仪表板中创建客户,但事实并非如此。

您不想从前端发出POST请求,因为它需要您的密钥。您可能想要使用https://github.com/stripe/stripe-node在您的lambda函数中实现这一点。

最新更新