Paypal Checkout Integration in Android

Ajay
Tilicho Labs
Published in
3 min readMar 16, 2021

Integrating Paypal in Android is quite complex because of the lack of proper documentation and also limited community support.

Recently when my team and I were trying to integrate the Paypal payment method in one of our projects we were following this documentation. In our use-case, the order will be created from the backend and the order_id is shared with the mobile client. Using this order_id, we need to checkout via Paypal and make the payment.

If you don’t have a backend for creating order_id you can go with Paypal SDK or try with Braintree Paypal SDK.

We had followed all the steps mentioned in the documentation. We were using the native implementation with isWebView set to true

We added a redirect URI scheme as mentioned in the documentation that would be used while redirecting back to our app after the payment is completed or canceled.

The scheme should be like this:

Make sure that your activity launchMode should be singleTop.
You need to define the merchant redirect URL as checkoutConfig.merchantRedirectUrl = “yourappnamepaypal://paypalxo”

Now, Paypal payment will redirect to your app after the payment is successful or canceled.

After we are redirected to our app we would receive an intent which would be like so :
yourappnamepaypal://paypalxo?token=9WH********61B&PayerID=VJW*******5EC&intent=sale&opType=payment&return_uri=

You will get this intent in OnNewIntent(intent: Intent). You need to capture this intent from the above function.

Here comes the real nightmare which we faced while capturing the payment from the frontend. We have tried using the callback listeners which actually didn’t work for payment successful or canceled.

So, We tried capturing the payments from the backend using the order_id. Paypal provides v2 API’s for capturing and authorizing the payments.

Here is the link for the Paypal v2 API’s documentation for capturing and authorizing the payments.

https://developer.paypal.com/docs/api/orders/v2/

Note: Make sure that you integrate these Order Capturing API’s in backend only. We should not keep the Paypal token in the frontend as the token may be misused.

After capturing the payment from the backend, the response should be propagated to the mobile client informing if the order was captured successfully or not and then on the mobile client we have to update the UI based on this response.

That’s it, Paypal Checkout integration in Android is completed.

Follow our Blog, Like us on Facebook

--

--