Pyae Phyoe Shein
Pyae Phyoe Shein

Reputation: 13827

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

Upvotes: 2

Views: 1703

Answers (2)

Prakash salawria
Prakash salawria

Reputation: 111

You can get Payment nonce in drop in method by using let nonce = result.paymentMethod!.nonce

Example :-

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?.isCancelled == true) {
            print("CANCELLED")
        } else if let result = result {

            let nonce = result.paymentMethod!.nonce

            print( nonce)

        }
        controller.dismiss(animated: true, completion: nil)
    }
    self.present(dropIn!, animated: true, completion: nil)
}

Upvotes: 3

Raymond Berg
Raymond Berg

Reputation: 870

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.

Upvotes: 1

Related Questions