Using Braintree SDK on Android for Paypal and Credit Card Payments

Leave a comment

Previously it was just using Paypal SDK to accept Paypal payments but now it requires you to use Braintree SDK to accept Paypal, Credit card or other types of payments. Accepting a payment through Braintree SDK is a multistep process.

1. Braintree live account (you need to apply for it, they will review and approve)
2. Braintree Sandbox account for testing
3. Paypal Business Account
4. Your own server to host server side code (can use localhost and Sandbox for testing though)
5. Linking Paypal with Braintree

These two tutorials shows you how to do using localhost for Android, Braintree SDK and PHP:

1. Braintree Android Integration Tutorial
2. Using Braintree Payment in Android

While these tutorials will give you a head start, none of them fully work. I came across some issues, here’s how I have solved them. Also, not only sandbox , I have tested for production environment as well.

1. After adding Braintree SDK as Module dependency in your Android project there might be mismatch due to SDK version differences

It is annoying specially because you have no idea which library versions are used internally by another library.

The best way to solve the problem is implement all ‘…’ suggested by android studio
(doesn’t matter which support versions you are using — 27.1.1, 28.0.0 etc..)

place the cursor to the error line e.g:
implementation ‘’
android studio will suggest you which ‘…’ is different version than ‘’


All libraries must use the exact same version specification (mixing versions can lead to runtime crashes).
Found versions 28.0.0, 27.1.0, 27.0.2. Examples include and

so add 

now sync gradle file.

one by one try to implement all the suggested ‘…’ till there is no error in this line implementation ‘’

In my case, my dependencies were like this:

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('', {
exclude group: '', module: 'support-annotations'
compile ''
compile ''
compile ''
compile ''
compile ''
compile 'com.braintreepayments.api:drop-in:3.+'
compile 'com.braintreepayments.api:braintree:2.+'
compile ''
compile ''
testCompile 'junit:junit:4.12'

2. Don’t forget to declare Activity for Paypal payments in the Android Manifest for BrowserSwitchActivity, otherwise it will do nothing on Paypal option selection in the Braintree Drop-In and you will have no idea why it’s doing nothing!

<activity android:name="com.braintreepayments.api.BraintreeBrowserSwitchActivity"
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="${applicationId}.braintree" />

3. Volley RequestQueue failed to do HTTP POST for some reason and AsyncHttpClient worked for me

4. Going from Sandbox to Production Environment
After testing in Sandbox Environment to go in Production Environment you just need to update the Merchand Id, Private Key and Public Key in server side PHP.
Still don’t forget to enable Paypal Processing option in Braintree Control Panel, otherwise Paypal option just won’t show up in the Android app UI!

5. Use to access your local machine from Android emulator when running local server like XAMPP/WAMPP
Use to access your actual machine. As I’ve learned, when you use the emulator, localhost ( ) refers to the device’s own loopback service, not the one on your machine as you may expect. You can use to access your actual machine, it is an alias set up to help in development.

6. Sending a mail from PHP after successful transaction
[PHP Warning: mail(): “ sendmail_from” not set in php.ini or custom “From:” header missing

if you’re using you own PC/localhost/ as server you can’t connect to SMTP server. You can only send mail from live server.
Also check with headers in PHP

$headers =  'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name &lt;;' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

mail($to, $subject, $body, $headers);

Leave a Reply