【发布时间】:2021-05-04 03:52:26
【问题描述】:
我知道以前有人问过这个问题,但在我的情况下如何解决这个问题 -
import Stripe
class MyAPIClient: NSObject, STPCustomerEphemeralKeyProvider {
let baseURL = "https://api.stripe.com"
func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
let url = self.baseURL.appendingPathComponent("ephemeral_keys") /*1st error - 'appendingPathComponent' is unavailable: Use appendingPathComponent on URL instead.*/
var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)! /*2nd error - Cannot convert value of type 'String' to expected argument type 'URL'*/
urlComponents.queryItems = [URLQueryItem(name: "api_version", value: apiVersion)]
var request = URLRequest(url: urlComponents.url!)
request.httpMethod = "POST"
let task = URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in
guard let response = response as? HTTPURLResponse,
response.statusCode == 200,
let data = data,
let json = ((try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]) as [String : Any]??) else {
completion(nil, error)
return
}
completion(json, nil)
})
task.resume()
}
}
i) 我正在使用
a) 迅速
b)火库
c) nodejs - 我应该使用其他东西来代替 node js 吗?
另外,我还应该做哪些其他修改?欢迎所有其他建议。
【问题讨论】:
-
baseURL是一个字符串。appendingPathComponent(_:)是(NS)URL方法,而不是字符串方法。init(url:resolvingAgainstBaseURL:)的第一个参数需要URL,而不是String。停止混合类型,仔细阅读它们。它们可能看起来很相似,但就像橘子和柑桔。不同。 -
@Larme 令人困惑的是,API 仍然存在于
NSString
标签: ios stripe-payments