【发布时间】:2021-08-13 15:57:15
【问题描述】:
我正在尝试在他们的设置中列出用户的付款方式,以防他们想要编辑或删除它们。主要是想得到品牌、后4位和有效期。
这是我后端的函数:
exports.listPaymentMethods = functions.https.onCall(async (data, context) => {
const customerId = data.customer_id;
const paymentMethods = await stripe.paymentMethods.list({
customer: customerId,
type: "card",
});
});
我使用以下方法在客户端调用此函数:
func listPaymentMethods(customerID: String) {
FirebaseReferenceManager.functions.httpsCallable("listPaymentMethods").call(["customer_id": customerID]) { (response, error) in
if let error = error {
print("failed to list customer's payment methods: \(error.localizedDescription)")
}
if let response = (response?.data as? [String: Any]) {
print(response)
}
}
}
但是,我收到错误消息“无法读取数据,因为它的格式不正确”
任何帮助将不胜感激! :)
【问题讨论】:
-
我可能遗漏了一些东西,但您的后端似乎没有返回任何东西?您可能需要对
paymentMethods或return paymentMethods;做点什么?但更有可能您需要在形成 JSON 响应方面做更多工作,例如运行一些代码来映射paymentMethods.data并创建一个包含应用程序所需特定信息的数组,而不是原始条带节点响应对象。
标签: ios node.js swift google-cloud-functions stripe-payments