我正在使用本教程通过firebase将我的应用程序与stripe连接-
https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=payment-sheet&uikit-swiftui=swiftui
我找不到paymentsheet。为什么它这么说,如何排序出来?我只是想连接条纹到我的应用程序使用firebase。什么是paymentsheet。我必须写某种形式的工作表?什么应该是其他代码与之相关?我已经附上了截图的错误,以及写在它的粗体字。
下面是错误的屏幕截图:-
现在,我的视图控制器是:
import Stripe
import SwiftUI
class MyBackendModel: ObservableObject {
let backendCheckoutUrl = URL(string: "Your backend endpoint")! // Your backend endpoint
@Published var paymentSheet: PaymentSheet?//**Cannot find type 'PaymentSheet' in scope**
@Published var paymentResult: PaymentSheetResult?//**Cannot find type 'PaymentSheet' in scope**
init() {
STPAPIClient.shared.publishableKey =
"pk_test_51HmAsMFzRM1fSBZ2tTT1SxPxRBzParFfjm6s0aXD0F5dYLeOSVCKtiZ4lq0TGwJxPhHpsq6Hga7I0QzRWisPYMdj00bDxAMTKf"
}
func preparePaymentSheet() {
// MARK: Fetch the PaymentIntent and Customer information from the backend
var request = URLRequest(url: backendCheckoutUrl)
request.httpMethod = "POST"
let task = URLSession.shared.dataTask(with: request, completionHandler: { [weak self] (data, response, error) in
guard let data = data,
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any],
let customerId = json["customer"] as? String,
let customerEphemeralKeySecret = json["ephemeralKey"] as? String,
let paymentIntentClientSecret = json["paymentIntent"] as? String,
let self = self else {
// Handle error
return
}
// MARK: Create a PaymentSheet instance
var configuration = PaymentSheet.Configuration()
configuration.merchantDisplayName = "Example, Inc."
configuration.customer = .init(id: customerId, ephemeralKeySecret: customerEphemeralKeySecret)
DispatchQueue.main.async {
self.paymentSheet = PaymentSheet(paymentIntentClientSecret: paymentIntentClientSecret, configuration: configuration)
}
})
task.resume()
}
func onPaymentCompletion(result: PaymentSheetResult) {
self.paymentResult = result
}
}
struct CheckoutView: View {
@ObservedObject var model = MyBackendModel()
var body: some View {
VStack {
if let paymentSheet = model.paymentSheet {
PaymentSheet.PaymentButton(
paymentSheet: paymentSheet,
onCompletion: model.onPaymentCompletion
) {
Text("Buy")
}
} else {
Text("Loading…")
}
if let result = model.paymentResult {
switch result {
case .completed:
Text("Payment complete")
case .failed(let error):
Text("Payment failed: \(error.localizedDescription)")
case .canceled:
Text("Payment canceled.")
}
}
}.onAppear { model.preparePaymentSheet() }
}
}
请协助我。我一直在尝试这么长时间来连接我的应用程序到条纹,但不成功。我只是想我的客户ID。显示条纹 Jmeter 板和其他信息也。
2条答案
按热度按时间vaj7vani1#
PaymentSheet已添加到Stripe版本21.5.0中。如果您使用的是低于此版本的Stripe版本,则会出现此错误。此问题可以通过提供更高的部署目标并重新安装Pod来解决。
https://github.com/stripe/stripe-ios/releases
az31mfrm2#
导入条带工资单
就能解决问题