hyperlink infosystem
Get A Free Quote

How to Integrate Brain tree Payment Gateway API in Swift

App Development

Mar 2016
2549 Views 5 Minute Read
how to integrate brain tree payment gateway api

Nowadays , In the world encircling with mobility and Smartphones all around us Performing transactions are the standard and the significant aspects any websites or the mobile application could think off. Probably almost each and every websites are affiliated with one or the other payment options in order to make feel to the customer rich user Experience.

online pay

As We can see the 80% Online trend is being channelized with E-commerce Websites and mobile apps and the more is gonna get explored in the upcoming few years . As per the statistics around 65-70% of Population highly depends on the online E-commerce platforms like those of E-bay , Amazon , Flip Kart and many other big-head companies for their style trends and shopping of their need as the current schedule has coupled them so tightly that they prefer online trading as the best option to be opted rather then personally visiting to the stores.

visiting to the stores

Looking at the above scenario Payment Gateway is the most inevitable option to be integrated in any of the Website developed . So , the let's have a deeper look inside Brain tree and know how it integrates with the Website.

Know What is Brain tree and its Working


It's an Full-fledged Platform that accepts payments from your application and websites and now with the coupling of mobile SDK it has become much more easier.

Consist of :

1) Client SDK : enables you to gather Payment Details from Paypal, credit card etc.

2) Server SDK : It maintains all the request to Brain tree Gateway.



1) An Request of client token is being send from your server side for client token.

2) Then, Server after generating client token sends back to the client along with server SDK.

3) Once Client SDK is created and all payment info of customer is submitted , communication takes place between SDK and Brain tree that returns payment method.

4) Then a payment nonce is being send to Server and once payment nonce is being received by server then it uses server SDK to create transaction and other Brain tree functions.

Now, let's start with Client Setup


client setup

There are number of ways client SDK can be setup

i) Using Drop-in UI

ii) Add buttons for Apple Pay , Paypal, Venmo , Android Pay.

iii) Credit Card Tokenization.

Instructions for setup :

Step 1:
Engage Braintree to your podfile :

pod 'Braintree'

Then, run -> pod install .

Bridge Header For Swift

If your podfile does not include any kind of pods that needs framework , then your current versions of CocoaPods do not use framework till the time you make clear specification to use frameworks in your profile

If your app is being coded using Swift and that to does not contain any kind of frameworks , then use following steps to import header files of BrainTree.

1) Create bridge header file as : File -> new -> Header file and then Next . Create file using file name as of : MyAbc-Bridge-Header.h and make sure you add header to your application and check the appropriate box.

2) go to settings - > objective-C Bridging Header . Now set this path for the Bridging header. Eg. MyAbc / MyAbc-Bridge-Header.h . Also add all the other Braintree header files like eg. #import “BrainUI.h”.

Initializing Braintree

Just Declare the below property wherever you handle your order and payment details

var braintreeClient: BTAPIClient?

Get Client token

As we know Client tokens are not mandatory means if you are making use of tokenization key then you do not need to consider this section.

Your server is the one responsible to generate Client token that holds all your permission and configurations details that is needed by the client to generate client SDK.

Client Token is being requested by your app from your Server. Following Example demonstrates you the sample Server integration and if you want to adapt it then, you need to make use of your back end API.

get client token

Present Drop-in UI

It is the best way to collect payment details from your customer. You can also pick up the option for creating customized UI and then tokenize payment straightaway.

Initialize the Class BTDropInViewControllerDelegate to retrieve user's method of payment.

present drop in ui

Now , to initialize Brain tree SDK create BTDropInViewController.

create btdropInviewcontroller

Now implement BTDropInViewControllerDelegate to receive the payment method nonce on victory, and reject the Drop In UI in any of the case:


Sending Payment method Nonce to Server

Now again Send the resulting Payment nonce to server back

payment nonce to server back


Step 1:
Create Your Sandbox Account.

Step 2: Now once, you have created your sandbox account login into that to acquire your Sandbox API details and for that you will need below mentioned concerns:

i) Sandbox Merchant ID

ii) Public Key

iii) Private Key

Install & configure

Include brain tree gem in your project's Gem-file as below :


gem "braintree"

and , to install run bundle install .

In your code, Set the environment and API credentials:

api credentials

Generate Client token

Your server is answerable for creating a client token, which holds all permissions and configuration credentials that your client wants to commence the client SDK to commutate with Brain tree. That also includes a customer Id when creating the client token that returns customers selected from previously used payment method choices, that leads betterment in user experience over multiple payment checkouts.

Send a client token to your client

Here is an demonstration of how server would expose client token to you

Receive a payment method nonce from your client

Your server execution is then liable for receiving the payment_method_once and using it appropriately.


post "/checkout" do

nonce = params[:payment_method_nonce]

# Use payment method nonce here...


Creating transaction

Now you can create transactions with the help of payment_method_nonce and amount:


result = Braintree::Transaction.sale(

:amount => "100.00",

:payment_method_nonce => nonce_from_the_client,

:options => {

:submit_for_settlement => true



Testing & Go live

Now the testing phase is conducted where with the help of different test values you can go with testing and then can go live.

So , hope now you are clear with Payment API integration and how the payment process is been scheduled. If still you are confused then no need to stress your mind just hire Android app developer from one of the  top app development companies i.e Hyperlink Infosystem and get your API integrated . Contact us now for further discussions.

Hire the top 3% of best-in-class developers!

Harnil Oza is the CEO & Founder of Hyperlink InfoSystem. With a passion for technology and an immaculate drive for entrepreneurship, Harnil has propelled Hyperlink InfoSystem to become a global pioneer in the world of innovative IT solutions. His exceptional leadership has inspired a multiverse of tech enthusiasts and also enabled thriving business expansion. His vision has helped the company achieve widespread respect for its remarkable track record of delivering beautifully constructed mobile apps, websites, and other products using every emerging technology. Outside his duties at Hyperlink InfoSystem, Harnil has earned a reputation for his conceptual leadership and initiatives in the tech industry. He is driven to impart expertise and insights to the forthcoming cohort of tech innovators. Harnil continues to champion growth, quality, and client satisfaction by fostering innovation and collaboration.

Our Latest Podcast

Listen to the latest tech news and trends we have discovered.

Listen Podcasts
blockchain tech

Is BlockChain Technology Worth The H ...

Unfolds The Revolutionary & Versatility Of Blockchain Technology ...

iot technology - a future in making or speculating

IoT Technology - A Future In Making ...

Everything You Need To Know About IoT Technology ...


Feel Free to Contact Us!

We would be happy to hear from you, please fill in the form below or mail us your requirements on info@hyperlinkinfosystem.com

full name
e mail
*We sign NDA for all our projects.

Hyperlink InfoSystem Bring Transformation For Global Businesses

Starting from listening to your business problems to delivering accurate solutions; we make sure to follow industry-specific standards and combine them with our technical knowledge, development expertise, and extensive research.

apps developed


Apps Developed




website designed


Websites Designed

games developed


Games Developed

ai and iot solutions


AI & IoT Solutions

happy clients


Happy Clients

salesforce solutions


Salesforce Solutions

data science


Data Science