首页 > 解决方案 > 如何从braintree支付中获取卡号?

问题描述

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

如何获取 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)
    }

标签: iosswift4braintreebraintree-sandbox

解决方案


全面披露:我在布伦特里工作。如果您还有其他问题,请随时联系支持人员

目前,Braintree 的 iOS SDK 不会在结果中返回卡片品牌图标。但是,在属性中包含卡品牌图标的交易响应对象中会返回图像 URL imageUrl。你可以查看这篇关于如何在 Swift 中显示图片 URL 的要点。或者,type当返回 nonce 时,客户端上可用。

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

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

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

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


推荐阅读