【发布时间】:2020-12-21 21:36:00
【问题描述】:
所以我已经在我的项目中实现了 Stripe。一切都按预期工作。但是,我确实希望使用一些可用的配置选项。例如,将默认付款国家/地区设置为“英国”。但是,这会导致我的应用程序在找到 nil 值时崩溃。我也在尝试使用其他一些设置,如下所示:
self.config.requiredBillingAddressFields = .full
self.config.appleMerchantIdentifier = "dummy-merchant-id"
self.config.cardScanningEnabled = true
self.config.applePayEnabled = true
视图中唯一我可以改变的是.requiredBillingAddressFields。其他一切似乎都没有注册。我的代码如下,为了清楚起见,我已经删除了与 Stripe 无关的内容:
struct CheckOutView: View {
@StateObject var paymentContextDelegate: PaymentContextDelegate
let config = STPPaymentConfiguration()
@State private var paymentContext: STPPaymentContext!
var body: some View {
HStack {
BorderedButton(text: "Pay Now") {
self.paymentContext.requestPayment()
}
Spacer()
}
HStack {
BorderedButton(text: paymentContextDelegate.paymentMethodButtonTitle) {
self.paymentContext.presentPaymentOptionsViewController()
}
Spacer()
}
.onAppear() {
DispatchQueue.main.async {
self.paymentContextConfiguration()
}
}
}
//MARK: - Configuration
func paymentContextConfiguration() {
self.config.requiredBillingAddressFields = .full
self.config.appleMerchantIdentifier = "dummy-merchant-id"
self.config.cardScanningEnabled = true
self.config.applePayEnabled = true
self.config.verifyPrefilledShippingAddress = true
self.config.canDeletePaymentOptions = true
self.paymentContext = STPPaymentContext(customerContext: customerContext, configuration: self.config, theme: .defaultTheme)
self.paymentContext.delegate = self.paymentContextDelegate
let keyWindow = UIApplication.shared.connectedScenes
.filter({$0.activationState == .foregroundActive})
.map({$0 as? UIWindowScene})
.compactMap({$0})
.first?.windows
.filter({$0.isKeyWindow}).last
self.paymentContext.hostViewController = keyWindow?.rootViewController
}
}
任何帮助将不胜感激!谢谢。
【问题讨论】:
标签: swift swiftui stripe-payments