我一直在用typescript在我的应用程序中实现stripe,我有以下功能:
exports.deleteStripeCustomer = functions.https.onCall((data, context) => {
const deleted = await stripe.customers.del(
"I need to add the customers ID here"
);
});
在我需要添加customerID的字符串中,我想从我已经在监听该ID的swift代码中添加客户ID,并在调用该ID时将其添加到函数中。
在swift中,这将是这样做的:
func sayHello(name: string) {
print("hello (name)")
}
然后当函数被调用时,id会从其他地方传入,比如
sayHello(name: usersName)
你知道打字是怎么做到的吗?
提前感谢,任何帮助都将不胜感激!
在TypeScript函数中,您只需从data
参数中获取它。
exports.deleteStripeCustomer = functions.https.onCall((data, context) => {
const userId = data.userId
});
在Swift通话中,你会这样传递:
let payload = [
"userId": "u456"
]
SomeAPI.httpsCallable("deleteStripeCustomer").call(payload) { (_, error) in
if let error = error {
print(error)
}
}
我从未使用过Stripe,我不知道他们的客户端API是如何配置的(或服务器端(,但我认为这与我过去使用过的其他TypeScript-Swift接口一样,这就是它的工作方式。如果你将我链接到他们关于这个API的文档,我可以提供进一步的帮助,但一般来说,由于你问了一般的问题,这就是它的工作方式。