【问题标题】:Cannot find type 'configuration' in scope在范围内找不到类型“配置”
【发布时间】:2021-12-02 17:14:07
【问题描述】:

我尽我所能,在网上搜了答案,但找不到答案,这就是我打扰你的原因。如果能得到你们的帮助,我将非常高兴:-

嗨,我正在关注这个 github 链接 - https://github.com/stripe-samples/firebase-mobile-paymentshttps://github.com/stripe/stripe-ios/blob/21.8.1/Stripe/PaymentSheet.swift#L33-L152。它显示错误-“找不到范围内的配置”和其他错误,如下所示-

    import UIKit
    import Foundation
    import Firebase
     import Stripe
 
    public class PaymentSheet {
/// This contains all configurable properties of PaymentSheet
   public let configuration: Configuration **// Error - Cannot find type 'Configuration' in scope**

    /// The most recent error encountered by the customer, if any.
   public private(set) var mostRecentError: Error?

   /// Initializes a PaymentSheet
   /// - Parameter paymentIntentClientSecret: The [client secret](https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret) of a Stripe   PaymentIntent object
      /// - Note: This can be used to complete a payment - don't log it, store it, or expose it to anyone other than the customer.
    /// - Parameter configuration: Configuration for the PaymentSheet. e.g. your business name, Customer details, etc.
        public convenience init(paymentIntentClientSecret: String, configuration: Configuration) { **// Error - Cannot find type 'Configuration' in scope**

        self.init(
        intentClientSecret: .paymentIntent(clientSecret:    paymentIntentClientSecret),**//Error - Cannot infer contextual base in reference to member 'paymentIntent'**
        configuration: configuration
        )
      }

       /// Initializes a PaymentSheet
       /// - Parameter setupIntentClientSecret: The [client secret](https://stripe.com /docs/api/setup_intents/object#setup_intent_object-client_secret) of a Stripe SetupIntent    object
      /// - Parameter configuration: Configuration for the PaymentSheet. e.g. your business name, Customer details, etc.
      public convenience init(setupIntentClientSecret: String, configuration: Configuration) { **// Error - Cannot find type 'Configuration' in scope**
    self.init(
          intentClientSecret: .setupIntent(clientSecret: setupIntentClientSecret),**//Error - Cannot infer contextual base in reference to member 'setupIntent**
        configuration: configuration
       )
     }

      required init(intentClientSecret: IntentClientSecret, configuration: Configuration) {**// Error - Cannot find type 'Configuration' in scope**

        STPAnalyticsClient.sharedClient.addClass(toProductUsageIfNecessary: PaymentSheet.self)**// Error - Cannot find 'STPAnalyticsClient' in scope**
    self.intentClientSecret = intentClientSecret
    self.configuration = configuration
    STPAnalyticsClient.sharedClient.logPaymentSheetInitialized(configuration: configuration)
   }

    /// Presents a sheet for a customer to complete their payment
    /// - Parameter presentingViewController: The view controller to present a payment sheet
     /// - Parameter completion: Called with the result of the payment after the payment sheet is dismissed
    @available(iOSApplicationExtension, unavailable)
    @available(macCatalystApplicationExtension, unavailable)
    public func present(
    from presentingViewController: UIViewController,
    completion: @escaping (PaymentSheetResult) -> () **//Error - Cannot find type 'PaymentSheetResult' in scope**
    ) {
       // Overwrite completion closure to retain self until called
        let completion: (PaymentSheetResult) -> () = { status in
        // Dismiss if necessary
        if self.bottomSheetViewController.presentingViewController != nil {
            self.bottomSheetViewController.dismiss(animated: true) {
                completion(status)
            }
        } else {
            completion(status)
        }
        self.completion = nil
    }
    self.completion = completion

    // Guard against basic user error
      guard presentingViewController.presentedViewController == nil else {
        assertionFailure("presentingViewController is already presenting a view controller")
        let error = PaymentSheetError.unknown( **// Error - cannot find 'PaymentSheetError' in scope**
            debugDescription: "presentingViewController is already presenting a view controller"
        )
        completion(.failed(error: error))
        return
    }

    // Configure the Payment Sheet VC after loading the PI/SI, Customer, etc.
    PaymentSheet.load(
        apiClient: configuration.apiClient,
        clientSecret: intentClientSecret,
        ephemeralKey: configuration.customer?.ephemeralKeySecret,
        customerID: configuration.customer?.id
          ) { result in
        switch result {
        case .success((let intent, let paymentMethods)):
            // Set the PaymentSheetViewController as the content of our bottom sheet
            let isApplePayEnabled = StripeAPI.deviceSupportsApplePay() && self.configuration.applePay != nil
            let paymentSheetVC = PaymentSheetViewController(
                intent: intent,
                savedPaymentMethods: paymentMethods,
                configuration: self.configuration,
                isApplePayEnabled: isApplePayEnabled,
                delegate: self
            )
            // Workaround to silence a warning in the Catalyst target
            #if targetEnvironment(macCatalyst)
            self.configuration.style.configure(paymentSheetVC)
            #else
            if #available(iOS 12.0, *) {
                self.configuration.style.configure(paymentSheetVC)
            }
            #endif
            self.bottomSheetViewController.contentStack = [paymentSheetVC]
        case .failure(let error):
            completion(.failed(error: error))
            }
         }

    presentingViewController.presentPanModal(bottomSheetViewController)// **Error - Value of type 'UIViewController' has no member 'presentPanModal'**
     }

    // MARK: - Internal Properties
   /// An unordered list of paymentMethod types that can be used with PaymentSheet
      static let supportedPaymentMethods: [STPPaymentMethodType] = [.card, .iDEAL]// Error - Cannot find type 'STPPaymentMethodType' in scope

      let intentClientSecret: IntentClientSecret//. **Error -  Cannot find type 'IntentClientSecret' in scope**

      var completion: ((PaymentSheetResult) -> ())?/**/  Error - Cannot find type 'PaymentSheetResult' in scope**  
     lazy var bottomSheetViewController: BottomSheetViewController = {
    let vc = BottomSheetViewController(
        contentViewController: LoadingViewController(delegate: self)
    )
    if #available(iOS 12.0, *) {
        configuration.style.configure(vc)
    }
    return vc
      }()

   }

请帮帮我。谢谢

【问题讨论】:

  • @JoakimDanielson - 好的,我添加了“import Firebase”和“import Stripe”(见编辑)。我还应该导入什么?
  • 它在一行中显示 - “- 参数配置:PaymentSheet 的配置。例如,您的公司名称、客户详细信息等”。那么,如何设计该配置?

标签: ios swift firebase stripe-payments


【解决方案1】:

您分享的第二个链接是 SDK 本身的内部代码,您在使用 SDK 时不会以这种方式实现。

您共享的示例在此处有一个付款单示例: https://github.com/stripe-samples/firebase-mobile-payments/blob/main/ios-swiftui/Firestripe/ContentView.swift https://github.com/stripe-samples/firebase-mobile-payments/blob/main/ios-swiftui/Firestripe/PaymentStore.swift

【讨论】:

  • 我粘贴了你的代码,还是一样的错误。
【解决方案2】:

对我有用的是将配置类型从 Configuration 更改为 ButtonStyleConfiguration

【讨论】:

  • 对我不起作用
猜你喜欢
  • 2021-09-24
  • 2021-09-21
  • 2021-08-01
  • 2022-01-16
  • 2021-08-03
  • 2021-11-29
  • 2021-09-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多