提问人:Swifty 提问时间:11/13/2023 最后编辑:Swifty 更新时间:11/13/2023 访问量:106
难以从服务器 PHP 文件中检索 Stripe 中已连接账户的 URL
Struggling to retrieve the url for connected accounts in Stripe from server PHP file
问:
我正在使用此文档将 Connected Stripe 账户合并到我的 iOS 应用程序中。当我们调用“OURFILE.PHP“文件,它会在输出的 JSON 数据中输出 ”url”。我们正在尝试使用此 url 并将其设置为“accountURL”并在 Safari 中打开。
import UIKit
import SafariServices
let BackendAPIBaseURL: String = “OURFILE.PHP”
class ConnectOnboardViewController: UIViewController {
// ...
override func viewDidLoad() {
super.viewDidLoad()
let connectWithStripeButton = UIButton(type: .system)
connectWithStripeButton.setTitle("Connect with Stripe", for: .normal)
connectWithStripeButton.addTarget(self, action: #selector(didSelectConnectWithStripe), for: .touchUpInside)
view.addSubview(connectWithStripeButton)
// ...
}
@objc
func didSelectConnectWithStripe() {
if let url = URL(string: BackendAPIBaseURL)?.appendingPathComponent("onboard-user") {
print(url)
var request = URLRequest(url: url)
request.httpMethod = "POST"
print("hi0")
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
guard let data = data,
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any],
let accountURLString = json["url"] as? String,
let accountURL = URL(string: accountURLString)
else {
// handle error
print("hi")
print(error)
print(response)
print(data)
return
}
let safariViewController = SFSafariViewController(url: accountURL)
safariViewController.delegate = self
DispatchQueue.main.async {
self.present(safariViewController, animated: true, completion: nil)
}
}
}
}
// ...
}
extension ConnectOnboardViewController: SFSafariViewControllerDelegate {
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
// the user may have closed the SFSafariViewController instance before a redirect
// occurred. Sync with your backend to confirm the correct state
}
}
但是,代码似乎跳过了此块
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
guard let data = data,
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any],
let accountURLString = json["url"] as? String,
let accountURL = URL(string: accountURLString)
else {
// handle error
print("hi")
print(error)
print(response)
print(data)
return
}
我们在不同的视图中有这个按钮:
Button {
self.isLoading = true
ConnectOnboardViewController().didSelectConnectWithStripe()
self.isLoading = false
}
我们已经为此工作了几个小时,试图进行调试,并想知道是否有人也遇到过同样的问题?
答: 暂无答案
评论
task.resume()
task
didSelectConnectWithStripe