PayPal Payment Method using BrainTree in swift 

Updated 16 September 2022


We can accept payments in your iOS app with the aid of the Braintree iOS SDK. To accept and process cards, PayPal, and also wallets like Apple Pay and Google Pay, use Braintree Direct’s collection of tools. Additionally, it has everything you need to manage data security, improve processes, and stop fraudulent transactions.


We always recommend to utilize the most recent SDK versions. We must use the iOS SDK at least in version 4.10.0 in order to safely communicate with the Braintree gateway.

Installing BrainTree

We can include Braintree in our project in multiple ways. See this Installation section for more information.

Swift Package Manager:

To add the Braintree package to your Xcode project, follow and select File > Swift Packages > Add Package Dependency, and enter as the repository URL. Select the checkboxes for the specific Braintree libraries you wish to include.

In your app’s source code files, use the following import syntax to include Braintree’s libraries:


Note: A warning may appear if you are using the Braintree iOS SDK version 4.x.x in Xcode 12. The iOS Simulator deployment target is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.0.99. There is a known fix for this CocoaPods problem.

Setup for app context switching

You must register a URL type and set your app to handle return URLs in order to manage workflows including moving to another app or SFSafariViewController for authentication.

Register a URL type

  1. Select your project from the Project Navigator in Xcode, then select App Target > Info > URL Types.
  2. To add a new URL type, click [+].
  3. Enter your app switch return URL scheme under URL Schemes. This strategy must be focused on Braintree app switch returns and begin with the Bundle ID of your app. For instance, your URL scheme could be com.your-company.your-app.payments if the app bundle ID is com.your-company.your-app.

Important: If you have multiple targets, make sure to add the return URL type for all of the targets.

Get a Client token:

Client tokens are not compulsory to use; instead of using a client token, you can begin Braintree using a tokenization key. You can omit this line if you’re using a tokenization key and just use that instead for authorization.

A client token, created by your server, comprises the authorization and configuration information required by your client to launch the client SDK.

Your app from your server must request a client token. Please modify this example to use your own backend API if you wish to use our sample integration server instead.

Make an HTTP request:


Pay using PayPal UI through BrainTree:

Add PayPal UI:

Accordingly in Xcode, follow the guide to add package dependencies to your app and enter as the repository URL. Also, select the checkboxes for each specific PayPal library you wish to include in your project.

In your app’s source files, use the following import syntax to include PayPal’s libraries:

Include the PayPal pod in your Podfile.


Sample Code:

First, you should check if you have registered your URL type and updated your app delegate.

Use BTPayPalDriver and BTPayPalRequest to start the process. However, a transaction amount requires to invoke the one-time payment flow. Below is an example of integration:

Shipping Address:

The PayPal Checkout flow may or may not include the collection of shipping addresses. However, if you decide to compile your own list of shipping addresses, it includes in your server-side transaction.

Currency Presentment:

In the PayPal Checkout flow, the customer can see the transaction’s currency. Since it supports all currencies that PayPal’s REST APIs support.


In this blog, we learned about PayPal Payment Method using Braintree. When available, the Braintree iOS SDK uses device and browser location information for fraud detection. To know more about BrainTree, you can look here.

To read more of my blogs, please visit this link.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home