我有一个firebase函数,它调用API来创建一个用户,它工作得很好。但是,我无法从Flutter应用程序中的函数中获得有效响应。无论我尝试什么,响应数据总是为null,即使函数返回的是响应,而不是错误。这段代码与文档中的示例几乎相同。有人能看出我哪里做错了吗?
功能
exports.stripeSignup = functions.https.onCall(async (data, context) => {
const uid = context.auth.uid;
console.log(`Received data ${JSON.stringify(data)}`);
stripe.accounts.create({
type: 'custom',
business_type: 'individual',
individual: {
email: data.email,
first_name: data.first_name,
last_name: data.last_name,
},
country: 'GB',
email: data.email,
requested_capabilities: ['card_payments', 'transfers']
})
.then((account) => {
console.log(`Stripe account: ${account.id}`);
return {
stripeId: account.id
};
})
.catch((err) => {
console.log(`Err: ${JSON.stringify(err)}`);
return null;
});
});
final HttpsCallable callable =
CloudFunctions.instance.getHttpsCallable(functionName: 'stripeSignup');
try {
final HttpsCallableResult res = await callable.call(<String, dynamic>{
'first_name': firstname,
'last_name': lastname,
'dob': dob,
'email': email,
'phone': phone,
});
print('Stripe response - ${res.data}');
String stripeId = res.data['stripeId'];
return stripeId;
} on CloudFunctionsException catch (e) {
return null;
}
1条答案
按热度按时间e1xvtsh31#
我认为你应该返回你的Promises链,如下所示: