swift - SwiftUI - Stripe STPPaymentContext 视图未使用 STPPaymentConfiguration 更新
问题描述
所以我已经在我的项目中实现了 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
}
}
任何帮助,将不胜感激!谢谢你。
解决方案
这更像是一个猜测,但也许配置选项正在应用,但只是没有满足它们启用的功能的其他要求?您如何确定除帐单地址以外的所有其他内容均未注册?
例如applePayEnabled
,仅当设备本身支持 Apple Pay 时才会显示 Apple Pay 选项(在钱包中有真实卡的物理设备上它可以工作(但您必须有一个真实的 Apple Merchant ID),在模拟器上可以斑驳的)。
因为cardScanningEnabled
也许您没有在您的应用程序中启用权利?https://github.com/stripe/stripe-ios#card-scanning-beta
检查配置是否适用的一种简单方法可能是设置requiredShippingAddressFields
,因为它是独立的并且非常直观。
推荐阅读
- python - 使用 QItemDelegate 在 QTableview 中创建一列可编辑的复选框
- javascript - 在日期选择器中显示今天的日期
- android - 如何比较 Firebase 中的子值?
- reactjs - 为 react 安装 react-redux@5.0.7 时出错
- html - Bootstrap 4 数据表CSS修改?
- python - Winsound减慢python程序
- telegram-bot - 如何在使用 Bots.Business 创建的机器人中单击链接后检查网站访问情况
- javascript - 如何在Vue的JS文件中导入文件变量?
- python - CTC 损失计算不正确
- python - 使用 tabula.py 从 PDF 格式读取没有标题的表格