【发布时间】:2020-03-13 01:12:15
【问题描述】:
我正在尝试使用 HTTP POST 请求从云 Firebase 函数向 Stripe API 发出 API 请求。
必须传递的参数必须是x-www urlencoded格式。
const httpOptions = {
headers: new Headers({
Authorization: 'Bearer sk_test_***',
'Content-Type': 'application/x-www-form-urlencoded'
})
};
const params = 'amount=' + payment_intent.amount + '¤cy=' + payment_intent.currency;
const CHARGE_URL = 'https://api.stripe.com/v1/payment_intents';
try {
const snapshot: any = await Http.post(CHARGE_URL, params, httpOptions).toPromise();
const intent: any = {
id: snapshot.id,
client_secret: snapshot.client_secret
};
await customerClassService.savePaymentIntent(requestId, intent);
resp.status(200)
.send(await Promise.all(intent));
} catch (e) {
console.error(e);
resp.status(400)
.send('An error occurred and will be solved ASAP.');
}
但是没有用,谁能帮帮我
【问题讨论】:
-
你能告诉我你正在使用的角度版本吗?
-
它是firebase的云功能所以节点8作为引擎“typescript”:“^3.2.2”
-
我遇到了同样的问题。在 Vue 中,我将使用 post 参数实例化一个
FomData类型,然后将其放入请求的body中。但是打字稿似乎无法识别FormData类型。
标签: angular typescript firebase google-cloud-functions