如何呈现Stripe Customer的卡片列表?

时间:2017-07-19 06:05:08

标签: ios swift stripe-payments

我只是想在iOS应用中显示用户的默认Stripe付款方式。

我正在尝试将STPPaymentMethodsViewController推送到viewController。 Stripe明确声明我必须创建STPCustomerContext。我是否还必须创建STPPaymentContext?我不想创建STPPaymentContext,因为它需要我在我的应用程序的这一部分中使用的4种方法......这是我拥有的,但没有骰子。

此外,Stripe的文档会指导您创建customerContext,但不要说明如何将其传递给STPPaymentMethodsViewController。我错过了什么?

https://stripe.com/docs/mobile/ios/custom

//AppDelegate.swift
var customerContext: STPCustomerContext?

func setupStripe() {
    self.customerContext = STPCustomerContext(keyProvider: MyAPIClient.sharedClient)
}

从用户的设置VC我尝试执行以下操作:

    func paymentMethodsButtonTapped() {
    let paymentMethodsViewController = STPPaymentMethodsViewController()
    paymentMethodsViewController.delegate = self // ERROR HERE: Cannot assign to property: 'delegate' is get only
    let navigationController = UINavigationController(rootViewController: paymentMethodsViewController)
    self.present(navigationController, animated: true, completion: nil)
}

2 个答案:

答案 0 :(得分:0)

确保您的班级确认STPPaymentMethodsViewControllerDelegate

答案 1 :(得分:0)

let customerContext = STPCustomerContext(keyProvider: StripeClient.shared)
let paymentMethodsViewController = STPPaymentMethodsViewController(configuration: STPPaymentConfiguration.shared(), theme: STPTheme.default(), customerContext: customerContext, delegate: self as STPPaymentMethodsViewControllerDelegate)
let navigationController = UINavigationController(rootViewController: paymentMethodsViewController)
present(navigationController, animated: true)