【问题标题】:How to pass a parameter into an https function when it's called from swift?从swift调用时如何将参数传递给https函数?
【发布时间】:2021-07-27 05:38:42
【问题描述】:

我一直在使用 typescript 在我的应用程序中实现条带化,并且具有以下功能:

exports.deleteStripeCustomer = functions.https.onCall((data, context) => { 
  const deleted = await stripe.customers.del(
    "I need to add the customers ID here"
  );
});

在我需要添加客户 ID 的那个字符串中,我想从我已经在侦听该 ID 的 swift 代码中添加客户 ID,并在调用它时将其添加到函数中。

很快,这将是这样完成的:

func sayHello(name: string) {
    print("hello \(name)")
}

然后当函数被调用时,id 从其他地方传入,如下所示:

sayHello(name: usersName)

知道这是如何在 typescript 中完成的吗?

在此先感谢,感谢您的帮助!

【问题讨论】:

    标签: node.js swift typescript stripe-payments


    【解决方案1】:

    在 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 的文档,我可以提供进一步的帮助,但一般来说,因为您通常会问,这就是它的完成方式。

    【讨论】:

      猜你喜欢
      • 2021-01-05
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      • 2022-01-25
      • 2020-05-06
      • 1970-01-01
      相关资源
      最近更新 更多