【问题标题】:How to get the card number from braintree payments?如何从braintree支付中获取卡号?
【发布时间】:2018-07-11 14:06:27
【问题描述】:

我正在为我的项目使用braintree pod,它在获得nonce 后运行良好。但我想检索卡图标和卡号的数字。

如何同时获取 imageView 中的卡片图标和 UILabel 中的卡号?

我使用了两个 pod 文件。

pod 'BraintreeDropIn'
pod 'BraintreeDropIn/UIKit'

我正在使用 Braintree 文档中提供的此功能。

func showDropIn(clientTokenOrTokenizationKey: String) {
        let request =  BTDropInRequest()

        //BTUIKAppearance.darkTheme()
        //BTUIKAppearance.sharedInstance().primaryTextColor = UIColor.green

        let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
        { (controller, result, error) in
            if (error != nil) {
                print("ERROR : \(error.debugDescription)")
            } else if (result?.isCancelled == true) {
                print("CANCELLED")
            } else if let result = result {
                // Use the BTDropInResult properties to update your UI
                //result.paymentOptionType
                //result.paymentMethod
                //result.paymentIcon
                //result.paymentDescription

                if let outPut = result.paymentMethod {
                    print("\nNonce : \(outPut.nonce)")

                    self.paymentNonce = outPut.nonce
                    self.paymentCardType = result.paymentDescription.description

                }
            }
            controller.dismiss(animated: true, completion: nil)
        }
        self.present(dropIn!, animated: true, completion: nil)
    }

【问题讨论】:

    标签: ios swift4 braintree braintree-sandbox


    【解决方案1】:

    全面披露:我在 Braintree 工作。如果您还有任何问题,请随时联系support

    目前,Braintree 的 iOS SDK 不会在结果中返回卡片品牌图标。但是,图像 URL 在 transaction response object 中返回,其中包含 imageUrl 属性中的卡片品牌图标。您可以查看this gist,了解如何在 Swift 中显示图像 URL。或者,当返回 nonce 时,type 在客户端可用。

    出于 PCI 合规性的原因,如果您使用 Drop-in UI,则不会向商家公开完整的卡号。相反,如果您将付款方式转换为BTCardNonce,iOS SDK 将提供lastTwo 数字。 Swift's documentation 有很多关于选角的好信息。虽然是 Objective-C,但一个例子是:

    BTCardNonce *cardNonce = (BTCardNonce*)result.paymentMethod;
    

    或者,您可以从事务响应对象中获取maskedNumber,类似于图像 URL。

    已编辑:将图片 URL 添加到 Swift 4 的更新链接

    【讨论】:

    • 如何在swift4中获取(在事务响应对象中返回图片URL)?
    • 如果您将结果转换为 BTCardNonce,iOS SDK 将提供最后两位数字 - 但如何?你能给我确切的文档或代码sn-ps吗?
    • 抱歉:我的意思是将付款方式转换为BTCardNonce。我已经更新了我的答案和一个在 Swift 中使用图像 URL 的链接。该链接会将您带到 Swift 3 文档,所以如果有人找到 Swift 4,那就太好了!
    • 这里是关于如何在 Swift 4 中从远程 URL 加载图像的要点。gist.github.com/popmedic/e79760aa65504085ede282cf868bfc82
    • 否- 如答案所述,iOS SDK 不返回卡片品牌图标。只有事务响应对象。我认为对于其中一些与代码无关的问题,您应该联系 Braintree 的技术支持braintreepayments.com/contact
    猜你喜欢
    • 2019-03-26
    • 2016-06-18
    • 1970-01-01
    • 2013-05-12
    • 2017-02-07
    • 2021-08-26
    • 2018-10-26
    • 2020-12-16
    • 2016-02-22
    相关资源
    最近更新 更多