ios - 如何从braintree payments中获取卡号?

标签 ios swift4 braintree braintree-sandbox

我正在为我的项目使用 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)
    }

最佳答案

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

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

出于 PCI 合规性原因,如果您使用 Drop-in UI,完整的卡号永远不会暴露给商家。相反,iOS SDK 将提供 lastTwo如果您将付款方式转换为 BTCardNonce,则为数字。 Swift's documentation有很多关于类型转换的好信息。通过 Objective-C,一个例子是:

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

或者,您可以获得 maskedNumber来自事务响应对象,类似于图像 URL。

已编辑:更新了用于将图像 URL 添加到 Swift 4 的链接

关于ios - 如何从braintree payments中获取卡号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51287618/

相关文章:

ios - 无法在 WKWebView Swift 4 中加载本地 html 文件

swift - 如何在没有 InfoView 的情况下在 GMSMarker 上添加点击事件

ios - 向具有多个自定义注释 View 的 map View 添加集群注释

ruby - 如何将 Brain Tree 事务详细信息存储到 Rails 4 中的数据库中

ios - Objective-C : Is there a way to call a completion block for a method in another method?

iphone - 如何确定应用程序是否显示 "App X would like to use your current location"警报?

ios - iPad 2 与 iPad 3 手动定位的项目有变化吗?

c++ - mach_header 64 位和 __PAGEZERO 段 64 位

paypal - 无法获得 PayPal/Braintree SDK 访问 token

javascript - 向客户端发送错误作为 HTTP 请求的回调