Posted on

Android In App Payments


android-app-payments

Sooner or later you need to figure out how to monetize your app. In app purchases (freemium) is way more appealing than ugly bunners. Although Backdrops apps have an amazing ads in the flow example

If what you’re selling is in app product (not a food, furniture, clothing) then you have to use Google Play in-app Billing API.

Setting Up

Google has a good sample called Trivial Drive. Of course you’ll have to change package name first. And now you need to have a Google developer account already. Don’t remember if you get an access to play.google.com/apps/publish/ without one, I think no.

So that’s the place where you create products that you can sell.

 

I don’t know why, but you need to upload release apk before you can start adding products. So just build any first.

Adding Product

There’s two types of them: managed and subscription. First is the one that you buy one/use once. Then you assign ID yourself, pricing, local pricing. Min price is currency equivalent of $1, about that. Don’t forget to activate that product

android app purchases

If you’re using Trivial Drive, which I highly suggest to just strip off code from there, replace base64EncodedPublicKey with yours from Play Console/Serivces & API’s of your app

android in-app purchases

Purchasing

There’s 3 product placeholders in sample. Let’s use buy gas. There’s a method called onBuyGasButtonClicked in MainActivity.java. Replace line in try block with this

second argument is product ID which you created yourself and listener to handle success/failure. Then to get the list of purchased items you use this method

And there’s a method for consuming products, because you can’t have multiple products of same ids at the same time.

android in-app purchases   android in-app purchases

Since those aren’t physical goods, knowing what current user purchases you give him extra features, boost etc.

Testing

Of course you’d want to test it first without buying anything. Imagine debugging when for each flaw you pay actual money. That’s why there’s a number of test id’s that you should start with

And when you’re going for a real testing you’ll need to build release apk again and publish it in Alpha/Beta channel. Beware that it matters which Google account you used to install it. It’s not allowed to make purchases with dev account. Even though I added my dev email to Settings/Licence Testing it didn’t work.

If you have multiple accounts on your device then make sure you install it with a different acc.

Getting Payed

And here’s how you get money transferred to your bank account

 

Here’s Trivial Drive repo again, thanks for reading, don’t forget to subscribe, follow me on Facebook, Twitter, G+ and share with friends if you think they will benefit from it


  • Andres Garcia

    Thanks mate !!!
    But what about when it’s not in-App Billing?
    Like selling a Service.
    Then I guess we need to use an SDK to handle the Card Payment