Search code examples
iospaypalbraintreepaypal-rest-sdk

How to get nonce from Braintree iOs SDK


I'm trying to get nonce from Braintree. I have not found any documentation Braintree provided that how to get nonce from Braintree SDK in following documentation.

https://developers.braintreepayments.com/start/hello-client/ios/v4

Please let me know how to get nonce from Braintree iOs SDK


Solution

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

    Getting the nonce is documented in the Presenting Drop-in UI section of the page you linked. Once you have the Drop-in active, you need to implement a delegate so the Drop-in can find where to send the nonce it produces. Without a delegate like the one specified you won't receive the nonce from the Drop-in: ​

    Then implement BTDropInViewControllerDelegate to obtain the payment method nonce on success, and dismiss the Drop In UI in either case:

    - (void)dropInViewController:(BTDropInViewController *)viewController   
      didSucceedWithTokenization:(BTPaymentMethodNonce *)paymentMethodNonce {
        // Send payment method nonce to your server for processing
        [self postNonceToServer:paymentMethodNonce.nonce];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    
     - (void)dropInViewControllerDidCancel:(__unused BTDropInViewController *)viewController {
         [self dismissViewControllerAnimated:YES completion:nil];
    }
    

    ​ If you look at the first function you can see that a variable paymentMethodNonce (type: BTPaymentMethodNonce) is passed into your app. This sample code expects that you have another function (postNonceToServer) to actually handle the nonce once you get it.