KhanShaheb
KhanShaheb

Reputation: 714

How to get the card number from braintree payments?

I am using braintree pod for my project and it is working nicely after getting nonce. But I want to retrieve the card icon and digits of the card number.

How can I get both card icon in an imageView and card number in UILabel?

I used two pod files.

pod 'BraintreeDropIn'
pod 'BraintreeDropIn/UIKit'

and I am using this function provided from braintree documentation.

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)
    }

Upvotes: 1

Views: 1092

Answers (1)

David
David

Reputation: 701

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.

Right now, Braintree's iOS SDK does not return the card brand icon in the result. However, an image URL is returned in a transaction response object that contains the card brand icon within the imageUrl attribute. You can check out this gist on how to display image URLs in Swift. Alternatively, the type is available on the client when the nonce is returned.

For PCI compliance reasons, the full card number is not ever exposed to a merchant if you are using the Drop-in UI. Instead, the iOS SDK will provide the lastTwo digits if you cast the payment method to BTCardNonce. Swift's documentation has a lot of good info on casting. Though Objective-C, an example would be:

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

Alternatively, you can get a maskedNumber from the transaction response object, similarly to the image URL.

Edited: updated link for adding image URL to Swift 4

Upvotes: 1

Related Questions