ios - 一旦我在STPAddCardViewController()上选择完成,应用程序就会加载并且不会停止加载

标签 ios swift xcode stripe-payments payment

我使用本教程将付款集成到我的应用中:

https://www.raywenderlich.com/182-accepting-credit-cards-in-your-ios-app-using-stripe#

但是,当我在STPAddCardViewController()上选择完成时,应用程序将加载并且不会停止加载。我将打印语句添加到本教程中显示的扩展中,希望它可以向我显示代码停滞的位置,但未显示任何打印语句。如下所示:

extension OrderDetialsViewController: STPAddCardViewControllerDelegate {

    func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
        print("addCard")
        navigationController?.popViewController(animated: true)
    }

    private func addCardViewController(_ addCardViewController: STPAddCardViewController,
                             didCreateToken token: STPToken,
                             completion: @escaping STPErrorBlock) {
        print("addCard Created Token")
        var totalCost = 0
        for i in 0...localData.shoppingCart.itemSizeArray.count-1{
            if localData.shoppingCart.itemSizeArray[i] == "hd"{
                totalCost = totalCost+2000
            }
            else if localData.shoppingCart.itemSizeArray[i] == "d"{
                totalCost = totalCost+4000
            }
            else if localData.shoppingCart.itemSizeArray[i] == "free"{
                totalCost = totalCost + 0
            }
            else if localData.shoppingCart.itemSizeArray[i] == "home" {
                totalCost = totalCost + 500
            }
        }
        StripeClient.shared.completeCharge(with: token, amount: totalCost) { result in
            print("StripeClient")
          switch result {
          case .success:
            completion(nil)
            let alertController = UIAlertController(title: "Congrats on your order",
                                  message: "Your payment was successful! Check email for confirmation!",
                                  preferredStyle: .alert)
            let alertAction = UIAlertAction(title: "OK", style: .default, handler: { _ in
              self.navigationController?.popViewController(animated: true)
            })
            alertController.addAction(alertAction)
            self.present(alertController, animated: true)
            self.createOrderEmailBody()
            self.createCustomerOrderBody()
            self.changeUserRewardsScore()
          case .failure(let error):
            print(error)
            completion(error)
          }
        }
  }
}

最佳答案

您正在使用哪个版本的iOS SDK?

如果它是v16.0.0之后的版本,则需要实现didCreatePaymentMethod函数以取回PaymentMethod对象,不建议使用didCreateToken方法。

您还必须实现PaymentIntents,因为PaymentMethods仅可与PaymentIntents一起使用,这是推荐的集成方式。

以下是有关如何在iOS应用中开始使用PaymentMethods和PaymentIntents的教程:https://youtu.be/s5Ml41bZidw?t=57

关于ios - 一旦我在STPAddCardViewController()上选择完成,应用程序就会加载并且不会停止加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61003642/

相关文章:

ios - 类型 'PHPhotoLibrary' 的值没有成员 'presentLimitedLibraryPicker' - Xcode 11.3.1

ios - Swift 中的自动完成搜索列表问题

ios - 如何从 UITableViewController 到多个 View Controller

ios - 检测双击 UITabbarController 项目以向上滚动表格 View

ios - XCode 4.6 管理器不表示我的应用程序崩溃堆栈跟踪

xcode - 更新框架按钮在 Xcode 8.1 中消失

ios - 获取从 UIImagePickerController 中选择的 UIImage 的 URL

ios - 从 NSErrorPointer 获取可读信息

ios - UIGraphicsGetImageFromCurrentImageContext() 不包括 CAAnimations

ios - MacCatalyst 的条件 Pod 链接