首页 > 解决方案 > 在“Stripe”集成时,类型“FundsVC”不符合 Swift 中的协议“STPAddCardViewControllerDelegate”

问题描述

"Stripe"在我的应用程序中使用支付网关..为此我已经在 Stripe 帐户中注册并获得了测试和密钥

我的代码是:

 import Stripe

 class FundsVC: UIViewController, STPAddCardViewControllerDelegate //here getting an error {

 @IBAction func stripePaymentBtn(_ sender: Any) {

    let config = STPPaymentConfiguration.shared()//here getting second error
    config.requiredBillingAddressFields = .full
    let viewController = STPAddCardViewController(configuration: config, theme: STPTheme.default())
    viewController.delegate = self
    let navigationController = UINavigationController(rootViewController: viewController)
    present(navigationController, animated: true, completion: nil)
    
}


//MARK:- STPAdd Card Controller Delegate
func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
    dismiss(animated: true, completion: nil)
}

func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: @escaping STPErrorBlock) {
    
    dismiss(animated: true, completion: nil)

}
}

请帮忙

错误

“WithdrawFundsVC”不符合协议“STPAddCardViewControllerDelegate”

无法调用非函数类型“STPPaymentConfiguration”的值

编辑

我已经更新了这样的代码:

func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
    dismiss(animated: true, completion: nil)
 }

@objc
func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreatePaymentMethod paymentMethod: STPPaymentMethod, completion: @escaping STPErrorBlock) {
    dismiss(animated: true, completion: nil)
}

o/p 这里的完成按钮没有启用为什么?

在此处输入图像描述

标签: iosswiftstripe-payments

解决方案


您正在关注与 stripe old pod 兼容的 stripe 实现的旧教程,但您使用的是最新的 stripe 版本。根据最新的 STPAddCardViewControllerDelegate文档,您应该需要这两种方法来确保其一致性

addCardViewControllerDidCancel(_:)
addCardViewController(_:didCreatePaymentMethod:completion:)

但你正在实施方法

addCardViewController(_:didCreateToken:completion:)

在最新版本中已弃用。您需要根据新版本更改您的实现。如果您仍想使用旧实现,请在您的 pod 文件中将 pod 版本修复为15.0.0。如果您遇到任何错误,请将 pod 版本更改为15.0.1


推荐阅读