【发布时间】:2022-01-17 18:42:16
【问题描述】:
我看到了非常相似的问题,但我仍然看不出我的代码有什么问题。
我部署了一个 Firebase 函数,当按下特定按钮时我会从客户端调用该函数。
// Generate Payment URL
exports.paymentRequest = functions.https.onCall(async (data, context) => {
const clientAccessToken = data.clientAccessToken;
const recipientIban = data.recipientIban;
const recipientName = data.recipientName;
const paymentDescription = data.paymentDescription;
const paymentReference = data.paymentReference;
const productPrice = parseInt(data.productPrice);
const jsonData = {
"destinations": [
{
"accountNumber": recipientIban,
"type": "iban"
}
],
"amount": productPrice,
"currency": "EUR",
"market": "FR",
"recipientName": recipientName,
"sourceMessage": paymentDescription,
"remittanceInformation": {
"type": "UNSTRUCTURED",
"value": paymentReference
},
"paymentScheme": "SEPA_INSTANT_CREDIT_TRANSFER"
};
axios({
method: "post",
url: "https://api.endpoint.com/payment",
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${clientAccessToken}`,},
data: jsonData,
})
.then(response => {
//handle success
console.log(response.data);
return response.data;
})
.catch(response => {
//handle error
console.log(response);
});
})
这是我的颤振代码:
onPressed: () async {
HttpsCallable callable = FirebaseFunctions.instance
.httpsCallable('PaymentRequest');
final resp = await callable.call(
<String, dynamic>{
'clientAccessToken': 'myToken',
'recipientIban': ibanController.text,
'recipientName': nameController.text,
'paymentDescription': descriptionController.text,
'paymentReference': referenceController.text,
'productPrice': productPriceController.text
},
);
print("result: ${resp.data}");
}
我确实在 Firebase 控制台中收到了 200 和完整的预期 API 响应正文(这意味着我的函数中的 console.log(response.data); 有效),但我总是在 de 中收到“结果:null” Flutter 控制台,所以好像没有返回 response.data。
我尝试在我的函数中的axios 之前添加一个return,但它并没有改变任何东西。
我错过了什么?
谢谢
【问题讨论】: