Integrating Flutterwave into Android and Destructuring its Data Response in 3 Steps

Emmanuel Ututu
3 min readFeb 25, 2021

How did we get here?

Photo by Malin on Unsplash

So, despite the mixed feelings awash in the dev community about consuming flutterwave’s API (which I honestly do understand because I’m currently battling their bills API and their response in developer.flutterwave.com is annoying), it was love at first for me the first day we both met (Love at first sight…is that even a thing? Whatever…). Although I’d be insincere to claim I haven’t been hurt now again, like I am ATM, by trying to digest their voluminous and sometimes confusing documentation but what’s a relationship without one or two heartbreaks. I know you can relate.

I first interfaced with flutterwave’s payment gateway in January 2020 while working on an eCommerce web application and as I said earlier, it was love at first sight. Although I had worked with another payment gateway in 2019 (the year I started off my career as a developer) I felt more comfortable working with flutterwave, for now at least. And so when I jumped on the android development train by July 2020, I anticipated integrating an android app to a payment gateway. That opportunity came in November 2020 while working on ‘Avalanche Signature’ and yet again, flutterwave was my go-to API.

However, their documentation only explained how to create an object of the class and add the necessary dependency to Gradle, it didn’t say how to destructure the response that would return after a call is made. So, in 3 simple steps, I would explain how that can be achieved successfully. Alright, let’s dive in.

Steps to Integrating flutterwave and destructing its data response

  1. Create an account with Flutterwave.
    If you haven’t already, go onto flutterwave’s website and create an account. On the left pane of your dashboard, you’d find settings where you can access your API keys which are unique. There two kinds; live mode and test mode. You’d find a toggle button sitting above Settings, just immediately on top of Referrals. Use API keys in test mode when you’re still developing and testing. Please, remember to switch to live mode and update the keys in your codebase with those for live mode when you are ready to go live/deploy; otherwise, oyo o.
  2. Add Flutterwave dependency to your project and create an instance of RaveUiManager
    Ok, this step is all about adding flutterwave to your project, what permission to use in your manifest, creating an instance of RaveUiManager and handling response (we’d get to the destructuring in a bit). Uh, ok, so their documentation is quite explanatory on how to go about this. Although it is in java, trust me you’d be able to set it up in kotlin(my preferred native language BTW) easily too. But if it happens to knock you out with boredom, check out this youtube tutorial organized by Cousant Connect and taken by Hamza Fetuga( a flutterwave developer as at August 2019). If you still hit a wall after going through the above, omo…ok sha hit me up I wouldn’t mind helping to debug your code while I await my hammer.
  3. Destructure the data from the response
    After handling the response in onActivityResult and making your first call you need to restructure the returning data. Firstly, here’s a GitHub gist by Bolaji Kassim showing what a successful response looks like. And this shows a failed response. As you know already, the response contains the raw JSON response from the Rave API. It needs to be parsed to retrieve additional information needed. Below is a detailed GitHub gist I’ve created on how to go about this.

Final Notes

I hope this post helps you destructure the response you get from flutterwave. And I want to also remind you not to forget to change .onStagingEnv to false when in live mode to avoid stories that touch. It should be true if you are still testing.

.onStagingEnv(false)

--

--

Emmanuel Ututu

3yr Android developer & writer, adding creativity & imagination to projects. I love to dream of needs and their solutions.