Integrate Braintree Payment Gateway in iOS Swift 4

Posted By : Vasu Saini | 24-Nov-2017

Braintree is a very useful payment gateway especially for USA base web and mobile applications, Braintree is provided by PayPal, let us know to integrate how to use it in your application.

Step 1. Most of the work of brain tree payment gateway is to be setup from your backed developer, braintree is to be deployed from both ends as well as from backend and front end.

Step 2. Create a new project in which braintree has to be setup.

Step 3. Install following  pod if your apps deployment target is above 9.0
            pod 'BraintreeDropIn'

         If its below 9.0 install following one
          pod 'Braintree', '~> 3.9'

Let us consider is above 9.0

Step 4. Import following 2 modules class in which braintree have to integrate.

import BraintreeDropIn

import Braintree

Step 5.After Setup braintree from backend ask your backend developer for the url to get the token for the transaction.

Step 6. Hit the URL and get and save the token

Step 7. After Getting token Call Braintree Method by passing token provided by your backend as shown below 

 

 

    //Brain Tree Method

    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 {

              //Save Nounce and call api provide by your backend passing amount and nounce string (nounce strin can be get from result.paymentMethod?.nounce) 

            }

            controller.dismiss(animated: true, completion: nil)

        }

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

    }

Step 8. Here an options is asked for payment method , select any payment method and fill details which is to asked for ex. card details, cvv, expiry date etc.

Step 9. After calling this method you will get result dictionary from which you can get a string named as nounce which is used for further transaction process

Step 9. Ask backed for web service url to do transaction with nounce string, hit the url with 2 parameters
 1.Amount to be deduct
 2. Nounce string

Step 10. This API will give u status of transaction in response whether is it successful or not

All done with braintree

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

 

 

 

 

 

About Author

Author Image
Vasu Saini

Vasu Saini is Passionate to deploy ideas into real world, Have zeal to learn new technologies. working as iOS Developer in Oodles Technologies. Sports Freak, Calisthenics ,Parkour, Love to play football, swimmer, athletics etc

Request for Proposal

Name is required

Comment is required

Sending message..