无法加载Stripe的pushPaymentOptionsViewController

时间:2019-07-05 16:20:27

标签: swift google-cloud-functions stripe-payments

我正在尝试在iOS应用中实现Stripe付款,但是由于某种原因,默认的Stripe的pushPaymentOptionsVewController允许用户选择其付款方式,但已推送但仍保持加载状态,并且不会显示。但是,pushShippingViewController可以正常工作。

我正在将Google Cloud函数用于我的createStripeCustomer和createEphemeralKey函数。我在StripeApi.swift中设置了createCustomerKey函数。我无法找到解决此问题的方法,因为它不会触发任何错误,并且代码是根据Stripe文档编写的。

//StripeApi

let StripeApi = _StripeApi()

class _StripeApi: NSObject, STPCustomerEphemeralKeyProvider {

    func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {

        let data = [
            "stripe_version": apiVersion,
            "customer_id" : UserService.user.stripeId
        ]

        Functions.functions().httpsCallable("createEphemeralKey").call(data) { (result, error) in

            if let error = error {
                debugPrint(error.localizedDescription)
                completion(nil, error)
                return
            }

            guard let key = result?.data as? [String: Any] else {
                completion(nil, nil)
                return
            }

            completion(key, nil)
        }
    }
}




//CheckOutVC

func setupStripeConfig() {
        let config = STPPaymentConfiguration.shared()
        config.createCardSources = true
        config.requiredBillingAddressFields = .none
        config.requiredShippingAddressFields = [.postalAddress]

        let customerContext = STPCustomerContext(keyProvider: StripeApi)
        paymentContext = STPPaymentContext(customerContext: customerContext, configuration: config, theme: .default())

        paymentContext.paymentAmount = StripeCart.total
        paymentContext.delegate = self
        paymentContext.hostViewController = self
    }


    @IBAction func payementMethodClicked(_ sender: Any) {
        // vc is pushed but won't stop loading
        paymentContext.pushPaymentOptionsViewController()
    }


    @IBAction func shippingMethodClicked(_ sender: Any) {
        // this is working and showing up nicely
        paymentContext.pushShippingViewController()
    }

我显然希望pushPaymentOptionsViewController完成加载并显示出来。但是viewController只会显示一个蓝色的旋转指示器和一个取消按钮。

编辑:任何人都知道这是否是Stripe最新版本中的错误吗?

1 个答案:

答案 0 :(得分:0)

您的快速代码看起来不错-我建议您查看一下您创建的临时密钥云函数,因为它们彼此通信。在运行快速代码之前,请确保已保存并部署了此代码。

让我知道怎么回事。