Search code examples
iosbraintreebraintree-sandbox

Unable to present dropIn UI using braintree iOS


I am creating a payment app and using braintree for that. I want to use braintree dropIn UI. Installed BraintreeDropIn through pod. Using the following code to present dropIn UI.

func showDropIn(clientTokenOrTokenizationKey: String) {
    let request =  BTDropInRequest()
    let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
    { (controller, result, error) in
        if (error != nil) {
            print("ERROR")
        } else if (result?.cancelled == true) {
            print("CANCELLED")
        } else if result != nil {
            // Use the BTDropInResult properties to update your UI
            // result.paymentOptionType
            // result.paymentMethod
            // result.paymentIcon
            // result.paymentDescription
        }
        controller.dismissViewControllerAnimated(true, completion: nil)
    }
    self.presentViewController(dropIn!, animated: true, completion: nil)
}

I got tokenization key from sandbox control panel under Tokenization Keys and I am passing it to showDropIn function. Still its not showing anything, not going inside this function

(BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
{ (controller, result, error))

Solution

  • Try using this:

        func showDropIn(clientTokenOrTokenizationKey: String) {
    
            let request =  BTDropInRequest()
            let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
            { (controller, result, error) in
                if (error != nil) {
                    print("ERROR")
                } else if (result?.cancelled == true) {
                    print("CANCELLED")
                } else if result != nil {
                    // Use the BTDropInResult properties to update your UI
                    // result.paymentOptionType
                    // result.paymentMethod
                    // result.paymentIcon
                    // result.paymentDescription
                }
             dispatch_async(dispatch_get_main_queue(), ^{
                 controller.dismissViewControllerAnimated(true,   completion: nil)
         });
            }
              dispatch_async(dispatch_get_main_queue(), ^{
                 self.presentViewController(dropIn!, animated: true, completion: nil)
         });
        }
    

    Hope this will work...!!