【问题标题】:Customizing Stripe UI integration to save and fetch user card information自定义 Stripe UI 集成以保存和获取用户卡信息
【发布时间】:2021-01-30 14:00:50
【问题描述】:

我正在使用条带允许用户相互发送付款。我遇到了一个错误,我很确定这是因为用户没有保存他们的付款类型。我想知道是否可以操纵条纹 STPPaymentOptionsViewController UI 来保存客户信息?或者如果我必须自定义我自己的控制器来执行此操作。

【问题讨论】:

  • 您需要哪些客户信息以便保存?帐单邮寄地址?
  • 没有他们的信用卡!

标签: ios node.js firebase stripe-payments


【解决方案1】:

可以存储用户的信用卡信息。

在您的服务器上,您需要调用stripe.paymentMethods.attach() 方法来保存付款方式(以stripeID 表示,我们稍后会谈到)。

例子:

app.post('/attach_card', (req, res) => {
    const customerID = req.body.customer_id;
    const cardStripeID = req.body.stripe_id;

    stripe.paymentMethods.attach(
        cardStripeID,
        { customer: customerID }
    ).then(value => {
        res.status(200).send(value);
    }).catch(err => {
        console.log(err);
        res.status(500).end()
    });
});

上面的代码需要两个参数customer_idstripe_id。假设你已经对customer_id很熟悉了,那么我们来谈谈如何收集用户的卡片信息并获取代表付款方式的stripe_id

  1. 初始化STPAddCardViewController(与STPPaymentOptionsViewController中的添加卡片屏幕相同的UI)
let config = STPPaymentConfiguration()
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)
  1. 使您的 ViewController 符合 STPAddCardViewControllerDelegate
func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
    // Handle cancel action if needed
}

func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreatePaymentMethod paymentMethod: STPPaymentMethod, completion: @escaping STPErrorBlock) {
    completion(nil)
    print("--- created payment method with stripe ID: \(paymentMethod.stripeId)")

    // Call the previous server code to store card info with Alamofire
    let url = YOUR_SERVER_BASE_URL.appendingPathComponent("attach_card")

    AF.request(url, method: .post, parameters: [ 
        "customer_id": YOUR_CUSTOMER_ID,
        "stripe_id": paymentMethod.stripeId
    ]) 

    // Dismiss the modally presented VC
    dismiss(animated: true, completion: nil)
}

现在卡片信息已保存,您可以在 Stripe 控制台中查看它:


条带化文档:

【讨论】:

  • 感谢您的回答,很抱歉迟到了!所以客户,我希望他们在设置视图控制器上更新他们的卡信息,而不是在用户结账时导航。我可以在那里操纵它吗?
  • 不用担心。是的,正如我在回答中提到的,您可以手动实例化STPAddCardViewController。 VC的实例化方法可以参考this tutorial的1st sectino。
  • 谢谢!我认为这不是我的问题。我仍然遇到错误。
  • 所以保存用户的卡信息没有帮助?
  • 是的!帮助我了解更多。但是,我仍然看到将我带到这里的相同问题错误。我可能不得不问另一个问题。不过你确实回答了我问的问题。
【解决方案2】:

我不认为这是 Stripe 可以支持的用例,因此您可能需要与他们联系以确认:https://support.stripe.com/contact/email

【讨论】:

  • 感谢您的回复。这是我已经联系到他们的 stripe 提供的服务,这里是描述能够收集付款并将其发送给用户的链接。 [stripe.com/en-br/connect/payouts] 但是,让我们暂时把它扔到一边。我的问题是我想知道是否可以操纵 UI 来保存信用卡信息,或者我是否必须创建自己的。
猜你喜欢
  • 2021-04-25
  • 2017-04-21
  • 2021-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-18
  • 2020-10-19
  • 2014-02-20
相关资源
最近更新 更多