Unable to present dropIn UI using braintree iOS

318 views Asked by At

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

There are 2 answers

3
Dheeraj D On BEST ANSWER

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...!!

0
ArielSD On

In Objective - C:

- (void)showDropIn:(NSString *)clientTokenOrTokenizationKey {
    BTDropInRequest *request = [[BTDropInRequest alloc] init];
    BTDropInController *dropIn = [[BTDropInController alloc] initWithAuthorization:clientTokenOrTokenizationKey request:request handler:^(BTDropInController * _Nonnull controller, BTDropInResult * _Nullable result, NSError * _Nullable error) {

        if (error != nil) {
            NSLog(@"ERROR");
        } else if (result.cancelled) {
            NSLog(@"CANCELLED");
        } else {
            // Use the BTDropInResult properties to update your UI
            // result.paymentOptionType
            // result.paymentMethod
            // result.paymentIcon
            // result.paymentDescription
        }

        dispatch_async(dispatch_get_main_queue(), ^{
            [controller dismissViewControllerAnimated:YES completion:nil];
        });
    }];

    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:dropIn animated:YES completion:nil];
    });
}