[英]stripe SDK integration using swift
I am attempting to add the stripe SDK to my iOS swift project and have many instances with this error "the Use of undeclared type 'STPContactField'" as shown below: 我正在尝试将条纹SDK添加到我的iOS swift项目中,并且有很多实例出现此错误“使用未声明的类型'STPContactField'”,如下所示:
I have already attempted: 我已经尝试过:
after downloading the stripe files from https://github.com/stripe/stripe-ios I am using the files speciffically from this link here: https://github.com/stripe/stripe-ios/tree/master/Example/Standard%20Integration%20(Swift) 从https://github.com/stripe/stripe-ios下载条带文件后,我在以下链接中专门使用这些文件: https : //github.com/stripe/stripe-ios/tree/master/Example/标准%20Integration%20(SWIFT)
all of the code from the view controller with issues is here: 来自视图控制器的所有有问题的代码都在这里:
import UIKit
import Stripe
import Alamofire
struct Settings {
let theme: STPTheme
let additionalPaymentMethods: STPPaymentMethodType
let requiredBillingAddressFields: STPBillingAddressFields
let requiredShippingAddressFields: Set<STPContactField>
let shippingType: STPShippingType
}
class SettingsViewController: UITableViewController {
var settings: Settings {
return Settings(theme: self.theme.stpTheme,
additionalPaymentMethods: self.applePay.enabled ? .all : STPPaymentMethodType(),
requiredBillingAddressFields: self.requiredBillingAddressFields.stpBillingAddressFields,
requiredShippingAddressFields: self.requiredShippingAddressFields.stpContactFields,
shippingType: self.shippingType.stpShippingType)
}
private var theme: Theme = .Default
private var applePay: Switch = .Enabled
private var requiredBillingAddressFields: RequiredBillingAddressFields = .None
private var requiredShippingAddressFields: RequiredShippingAddressFields = .PostalAddressPhone
private var shippingType: ShippingType = .Shipping
fileprivate enum Section: String {
case Theme = "Theme"
case ApplePay = "Apple Pay"
case RequiredBillingAddressFields = "Required Billing Address Fields"
case RequiredShippingAddressFields = "Required Shipping Address Fields"
case ShippingType = "Shipping Type"
case Session = "Session"
init(section: Int) {
switch section {
case 0: self = .Theme
case 1: self = .ApplePay
case 2: self = .RequiredBillingAddressFields
case 3: self = .RequiredShippingAddressFields
case 4: self = .ShippingType
default: self = .Session
}
}
}
fileprivate enum Theme: String {
case Default = "Default"
case CustomLight = "Custom – Light"
case CustomDark = "Custom – Dark"
init(row: Int) {
switch row {
case 0: self = .Default
case 1: self = .CustomLight
default: self = .CustomDark
}
}
var stpTheme: STPTheme {
switch self {
case .Default:
return STPTheme.default()
case .CustomLight:
let theme = STPTheme()
theme.primaryBackgroundColor = UIColor(red:0.96, green:0.96, blue:0.95, alpha:1.00)
theme.secondaryBackgroundColor = UIColor(red:1.00, green:1.00, blue:1.00, alpha:1.00)
theme.primaryForegroundColor = UIColor(red:0.35, green:0.35, blue:0.35, alpha:1.00)
theme.secondaryForegroundColor = UIColor(red:0.66, green:0.66, blue:0.66, alpha:1.00)
theme.accentColor = UIColor(red:0.09, green:0.81, blue:0.51, alpha:1.00)
theme.errorColor = UIColor(red:0.87, green:0.18, blue:0.20, alpha:1.00)
theme.font = UIFont(name: "ChalkboardSE-Light", size: 17)
theme.emphasisFont = UIFont(name: "ChalkboardSE-Bold", size: 17)
return theme
case .CustomDark:
let theme = STPTheme()
theme.primaryBackgroundColor = UIColor(red:0.16, green:0.23, blue:0.31, alpha:1.00)
theme.secondaryBackgroundColor = UIColor(red:0.22, green:0.29, blue:0.38, alpha:1.00)
theme.primaryForegroundColor = UIColor(red:1.00, green:1.00, blue:1.00, alpha:1.00)
theme.secondaryForegroundColor = UIColor(red:0.60, green:0.64, blue:0.71, alpha:1.00)
theme.accentColor = UIColor(red:0.98, green:0.80, blue:0.00, alpha:1.00)
theme.errorColor = UIColor(red:0.85, green:0.48, blue:0.48, alpha:1.00)
theme.font = UIFont(name: "GillSans", size: 17)
theme.emphasisFont = UIFont(name: "GillSans", size: 17)
return theme
}
}
}
fileprivate enum Switch: String {
case Enabled = "Enabled"
case Disabled = "Disabled"
init(row: Int) {
self = (row == 0) ? .Enabled : .Disabled
}
var enabled: Bool {
return self == .Enabled
}
}
fileprivate enum RequiredBillingAddressFields: String {
case None = "None"
case Zip = "Zip"
case Full = "Full"
init(row: Int) {
switch row {
case 0: self = .None
case 1: self = .Zip
default: self = .Full
}
}
var stpBillingAddressFields: STPBillingAddressFields {
switch self {
case .None: return .none
case .Zip: return .zip
case .Full: return .full
}
}
}
private enum RequiredShippingAddressFields: String {
case None = "None"
case Email = "Email"
case PostalAddressPhone = "(PostalAddress|Phone)"
case All = "All"
init(row: Int) {
switch row {
case 0: self = .None
case 1: self = .Email
case 2: self = .PostalAddressPhone
default: self = .All
}
}
var stpContactFields: Set<STPContactField> {
switch self {
case .None: return []
case .Email: return [.emailAddress]
case .PostalAddressPhone: return [.postalAddress, .phoneNumber]
case .All: return [.postalAddress, .phoneNumber, .emailAddress, .name]
}
}
}
private enum ShippingType: String {
case Shipping = "Shipping"
case Delivery = "Delivery"
init(row: Int) {
switch row {
case 0: self = .Shipping
default: self = .Delivery
}
}
var stpShippingType: STPShippingType {
switch self {
case .Shipping: return .shipping
case .Delivery: return .delivery
}
}
}
convenience init() {
self.init(style: .grouped)
}
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Settings"
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismiss as () -> Void))
}
@objc func dismiss() {
self.dismiss(animated: true, completion: nil)
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 6
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch Section(section: section) {
case .Theme: return 3
case .ApplePay: return 2
case .RequiredBillingAddressFields: return 3
case .RequiredShippingAddressFields: return 4
case .ShippingType: return 2
case .Session: return 1
}
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return Section(section: section).rawValue
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
switch Section(section: (indexPath as NSIndexPath).section) {
case .Theme:
let value = Theme(row: (indexPath as NSIndexPath).row)
cell.textLabel?.text = value.rawValue
cell.accessoryType = value == self.theme ? .checkmark : .none
case .ApplePay:
let value = Switch(row: (indexPath as NSIndexPath).row)
cell.textLabel?.text = value.rawValue
cell.accessoryType = value == self.applePay ? .checkmark : .none
case .RequiredBillingAddressFields:
let value = RequiredBillingAddressFields(row: (indexPath as NSIndexPath).row)
cell.textLabel?.text = value.rawValue
cell.accessoryType = value == self.requiredBillingAddressFields ? .checkmark : .none
case .RequiredShippingAddressFields:
let value = RequiredShippingAddressFields(row: indexPath.row)
cell.textLabel?.text = value.rawValue
cell.accessoryType = value == self.requiredShippingAddressFields ? .checkmark : .none
case .ShippingType:
let value = ShippingType(row: indexPath.row)
cell.textLabel?.text = value.rawValue
cell.accessoryType = value == self.shippingType ? .checkmark : .none
case .Session:
cell.textLabel?.text = "Log out"
cell.accessoryType = .none
}
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
switch Section(section: (indexPath as NSIndexPath).section) {
case .Theme:
self.theme = Theme(row: (indexPath as NSIndexPath).row)
case .ApplePay:
self.applePay = Switch(row: (indexPath as NSIndexPath).row)
case .RequiredBillingAddressFields:
self.requiredBillingAddressFields = RequiredBillingAddressFields(row: (indexPath as NSIndexPath).row)
case .RequiredShippingAddressFields:
self.requiredShippingAddressFields = RequiredShippingAddressFields(row: (indexPath as NSIndexPath).row)
case .ShippingType:
self.shippingType = ShippingType(row: (indexPath as NSIndexPath).row)
case .Session:
let cookieStore = HTTPCookieStorage.shared
for cookie in cookieStore.cookies ?? [] {
cookieStore.deleteCookie(cookie)
}
}
tableView.reloadSections(IndexSet(integer: (indexPath as NSIndexPath).section), with: .automatic)
}
}
Podfile: Podfile:
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'ChefEV' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for ChefEV
pod 'Firebase/Core'
pod ‘Firebase/Auth’
pod 'Firebase/Auth'
pod ‘Firebase/Database’
pod 'Stripe'
pod 'Alamofire'
target 'ChefEVTests' do
inherit! :search_paths
# Pods for testing
end
target 'ChefEVUITests' do
inherit! :search_paths
# Pods for testing
end
end
any help in resolving this issue is greatly appreciated. 非常感谢您对解决此问题的任何帮助。
solved this problem by updating the stripe podfiles. 通过更新条带podfile解决了此问题。 apparently installing the Stripe pod files does not give you the up-to-date version 显然,安装Stripe Pod文件不会为您提供最新版本
type: pod update Stripe
into project terminal and should solve this issue. 类型: pod update Stripe
到项目终端,应解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.