【问题标题】:How to add a new card / source to stripe customer account?如何添加新卡/来源以条带化客户帐户?
【发布时间】:2020-01-08 10:26:35
【问题描述】:

我正在使用stpaddcardviewcontroller UI 元素要求客户输入新卡信息

let addCardViewController = STPAddCardViewController()
addCardViewController.delegate = self
present(navigationController, animated: true)

上面的代码将显示UI,但在点击完成按钮后,我需要获取令牌(从添加的卡信息生成)以向现有客户添加新卡/来源。

我正在使用以下委托方法从stpaddcardviewcontroller UI 获取令牌

extension viewController : STPAddCardViewControllerDelegate {

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


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

如何在委托方法中接收卡令牌?这样我就可以传递给Add Card API ?

【问题讨论】:

    标签: ios swift stripe-payments


    【解决方案1】:

    您在 didCreatePaymentMethod 委托中获得 PaymentMethod 令牌。

    Stripe-iOS(使用您的可发布密钥)无法自行更新客户。这里有两个选项:

    1) 将令牌发布到后端服务器端点,您将在其中使用 Stripe API 库(使用您的 Stripe 密钥)并将 PaymentMethod 附加到 Stripe 客户:https://stripe.com/docs/api/payment_methods/attach

    2) 如果您在 iOS 应用上使用临时密钥,您可以将 PaymentMethod 附加到 Stripe 客户。 SDK 会为您处理。 Stripe-iOS 实际上也提供了预构建的 UI 来处理这个问题,例如 STPPaymentOptionsViewController。您需要参考此处使用 STPCustomerContext 的“标准集成”指南:https://stripe.com/docs/mobile/ios/standard

    【讨论】:

    • 感谢您的回答,但我什么参数会给我支付令牌?我试过paymentMethod.card.,新API中没有像令牌这样的参数。是 paymentMethod.stripeId 吗?
    • 正确,paymentMethod.stripeID 将返回您将附加给客户的 PaymentMethod 的 ID,例如“pm_123”。 STPPaymentMethod 的文档:stripe.dev/stripe-ios/docs/Classes/STPPaymentMethod.html
    猜你喜欢
    • 2016-11-02
    • 2016-10-02
    • 1970-01-01
    • 2019-12-22
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    相关资源
    最近更新 更多