Braintree payment gateway is basically a paypal service, so we would require braintree sdks to be integrated in our android code. We can then link our paypal credentials with braintree dashboard.





First of all go here https://www.paypal.com/in/webapps/mpp/merchant and create a paypal merchant account. You may choose to create shoppers account or business account or freelancers account based on your needs. As soon as the above step is complete, head over to the paypal developer website here https://developer.paypal.com/ and login with the above generated credentials. Once you are logged in click on your username at the top right corner and then click on dashboard. Now click on "create app" option in your dashboard. Now fill in the app name for your sandbox environment and complete the app creation. As soon as the app is created, you can see that the client id, client secret has beem generated has been generated. Now go here and create braintree sandbox account >> https://sandbox.braintreegateway.com/ . Once the account is created, goto Settings >> processing >> paypal. Now toggle paypal to turn it on. Now click on "options" next to the paypal field. Now enter the paypal email, client id, secret id generated in step 2 and click update to save. Now we have successfully linked paypal with braintree. Once you are logged in with the braintree sandbox account, you can goto Account >> Merchant Account Info and then click "new sandbox merchant account" to create a braintree merchant account for testing purposes. The braintree merchant account is not like a bank account, basically this account directs funds from your customers to your business bank account. You may create any number of braintree merchant account like shown above. While creating the braintree merchant account, it can be set as the default merchant account so that the transactions will be using it as the default one.





Follow the below steps for integration :



The first step is the generation of client token at the server side using your server side braintree library. We will be following .NET library for server side integrations. Check here for other formats available Following library supports both .NET Framework 4.5.2+, .NET Core 1.0+ and higher.

Download the .NET library for braintree here

Version: 4.8.0

SHA256: a700b98818c1f4266701160a1059d75f1cb17aa8d8ae12696c6812264781d932 2. Once the braintree library is setup login to your braintree sandbox account here >> As of now the initial dashboard setup is now complete.Follow the below steps for integration :Following library supports both .NET Framework 4.5.2+, .NET Core 1.0+ and higher.2. Once the braintree library is setup login to your braintree sandbox account here >> https://sandbox.braintreegateway.com/ and goto settings >> API Keys. Now click on

"Generate new API key". Now you will get a public key, private key and merchant id if you click the "view" option in the generated API Key. Now add the above generated values as shown below

payment_method_nonce

payment_method_nonce

payment_method_nonce

amount

payment_method_nonce

implementation 'com.braintreepayments.api:drop-in:3.7.0'

implementation 'com.squareup.retrofit2:retrofit:2.0.0-beta4'

implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

onBraintreeSubmit(response.body().toString());

onActivityResult

String payment_method_nonce=result.getPaymentMethodNonce().getNonce();

We will see how to integrate braintree sdk in android and perform paypal transactions3. Now that you have setup the braintree sandbox, the next step is the generation of client token, which will be required at the client side to initialise the client side braintree sdk(in our case >> android braintree sdk). Inorder to allow return customers to choose previously chosen payment method options, you can make use of a customerid like shown belowNow generate the client token and expose it to the clients like shown below4. Now, the client(android app) requests the client token and intialieses the client side sdk using this client token. Once the sdk is initialised, the client generates avalue and sends it to the server, the server should accept thevalue like shown below5. You have now successfully accepted thevalue from the client which depicts client side authorisation to create transaction. So create a transaction like shown below, using anand theyou received from clientNow let us see some client side code using androidAdd the following dependency in your app level build.gradleIn our server side implementation, we have already created an api to expose client token(check step 3 in server side integration). We will need to get this client token to initialise our braintree payment gateway sdk in our app side. So write a network call to fetch client token like shown below(here we are using retrofit library for network calls)and create RequestInterface.java like this Please note that you have to set the base url and endpoint according to the one that you have created in step 3 in server side integrationAs you can see above we need to pass the client token like thisto the braintree sdk from the onResponse method of our retrofit instance. So we need to write the code for this method like shown belowNow we will need to overrideas shown below, so that we can get the results from the braintree sdkAs shown above, we have successfully obtained the nonce value from the braintree sdk like this. Now we will need to send this nonce value along with an amount to our server side implementation to perform the transaction at the server side. So create submitNonce() method like shown below :now update your RequestInterface.java like shown below