代码之家  ›  专栏  ›  技术社区  ›  KhanShaheb

如何从braintree payments获得卡号?

  •  1
  • KhanShaheb  · 技术社区  · 6 年前

    我在我的项目中使用了BrainTreePod,它在获得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)
        }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   David    6 年前

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

    现在,Braintree的iOS SDK不会在结果中返回卡片品牌图标。但是,在 transaction response object imageUrl 属性。你可以退房 this gist 关于如何在Swift中显示图像url。或者 type 在返回nonce时在客户端上可用。

    lastTwo BTCardNonce . Swift's documentation 有很多关于选角的好信息。尽管是目标C,例如:

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

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