如何从Braintree付款中获得卡号?

时间:2018-07-11 14:06:27

标签: ios swift4 braintree braintree-sandbox

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

1 个答案:

答案 0 :(得分:1)

全部披露:我在Braintree工作。如果您还有其他疑问,请随时与support联系。

现在,Braintree的iOS SDK不会在结果中返回卡片品牌图标。但是,图像URL将在transaction response object属性内的imageUrl中返回,其中包含卡牌图标。您可以查看this gist有关如何在Swift中显示图像URL的信息。或者,当随机数返回时,type在客户端上可用。

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

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

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

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