MALE SPEAKER: Hey, Jarek.
What's happening?
JAREK WILKIEWICZ: I'm coding this--
MALE SPEAKER: Oh, that's great.
Say listen, I've been talking to folks upstairs,
and we think we need to make our apps a little more freemium.
Do you think you can do that for us?
Maybe add a little freemiumification to our apps?
JAREK WILKIEWICZ: Do you even know what freemium means?
MALE SPEAKER: Jarek, look.
I'm more of what you might want to call a big picture
kind of guy.
I don't like to get bogged down in details
like, what is freemium, and what does that even mean.
I like to leave that people like you.
So what do you say?
Can you get this done for me?
JAREK WILKIEWICZ: Well, we could reshuffle the schedule and--
MALE SPEAKER: That's great.
Hey, listen.
I kind of told the folks in upper management
we'd have something for them on Mondays.
So I'm going to have to ask you to come in over the weekend
and get this done for me, OK?
Thanks a lot, Jarek.
You're a team player.
JAREK WILKIEWICZ: It's Jarek.
MALE SPEAKER: Keep up the good work.
JAREK WILKIEWICZ: Hi, I'm Jarek Wilkiewicz.
In this series, I'm covering things
every developer needs to understand
to be successful-- user acquisition, engagement,
and earning money.
In this video, we'll focus on the money part and freemium.
Freemium is a product pricing strategy
where, instead of charging the user for app download,
you make money on in-app purchases,
or even up sell the user to a subscription.
In-app purchases and subscriptions
have already proven very lucrative for games.
And according to App Annie, they're
growing fast for non-games as well.
To illustrate how this works, let's look at a small example
called Trivial Drive, which you can clone from GitHub.
The sample app is a driving simulator,
except that you can't actually do the driving.
But anyway, Trivial Drive implements three types
of in-app purchases.
You can buy more gas, upgrade your car,
and subscribe to the unlimited gas service.
After your first free tank of gas,
you have to purchase more by hitting the Buy Gas button.
A nice dialogue pops up which guides the user
through a frictionless purchase flow.
The gas is what's called a consumable item.
The car consumes the fuel, and the user needs to buy more.
You can upgrade the car to a fancier red one.
This is an example of purchasing a non-consumable item.
The car upgrade is a one-time purchase.
Let's now look at how that's implemented.
Before you can sell something, you need to have inventory.
The in-app digital products offered by your app
are configured in the Google Play Developer Console.
As you can see, I have set up gas as a Stock
Keeping Unit, or a SKU, with a price of $1
and the ID of a value of gas.
The ID is what the mobile app uses to look up the product
and initiate the purchase flow.
To initiate gas purchase, Trivial Drive
constructs a byte pendingIntent, starts it, and then
processes the response in the handle activity result method.
As you can see, Google Play handles the purchasing flow.
At this point, the user is in the possession of extra gas,
so the app updates the fuel gauge display.
Because gas is a consumable product, following
the successful gas purchase flow,
Trivial Drive also calls the consumePurchase method.
ConsumePurchase tells the Google Play back end
that the user took inventory of the product.
The call to consume purchase is necessary
because the Google Play back end does not
make a distinction between a consumable item,
such as gas, or a non-consumable item,
for example, an item representing
an upgrade to a fancy red car.
While Google Play tracks the purchases,
so you don't have to, managing the user's inventory
is your job.
All right.
So far I've showed you how to handle in-app product
purchases-- for example, getting more gas, or a premium car
upgrade.
Now let's talk about subscriptions.
Let's suppose I want my car to go on forever,
without having to worry about fuel.
For a small fee, Trivial Drive lets
me purchase recurring subscription
so that my tank is always full.
To implement subscriptions, you need
to first configure a new product in the Google Play Developer
Console.
Configure the name and the ID, the price, billing period,
and even offer a free trial.
Then, in the app, you kick off the purchase flow
like in the gas example.
This time, the SKU ID is infinite gas.
Trivial Drive constructs a byte pendingIntent,
starts it, and then processes the response
in the handle activity result method.
And voila, we done with subscriptions.
Finally, I wanted to cover one more aspect of using
the in-app billing API.
What if the app is restarted, or uninstalled, and installed
again?
Or what happens if the phone runs out of battery right
after the user completes the purchase?
The Google Play in-app billing API keeps track of purchases
so you don't have to.
Your app can retrieve products owned by the user at any time.
It is a good practice to always do that
upon application start-up.
This way, you don't have to maintain purchases in the app.
And since the API utilizes a persistent cache,
the response time is good.
Restoring purchases upon start-up
also conveniently handles the corner case
when the app crashes right after the user completes a purchase.
There's a lot more to the purchase flow
that we did not cover-- for example,
handling refunds and managing your digital products
programmatically using the Google Play Developer API.
What's even more important is securing transactions.
You can use several techniques enabled by the Google Play
in-app billing API to prevent bad actors
from spoofing in-app purchases.
Check out this Google I/O talk by Bruno Oliveira.
To learn more about Google Play in-app billing API,
visit our documentation, or better yet, run the sample
Trivial Drive application, which comes with several convenience
classes you can reuse in your own app.
Note that you need to publish the app to the alpha channel
before you can try it out.
Last, but not least, remember that the Google Play in-app
billing API is designed for digital products only.
If you would like to sell physical products in your app,
check out our Android Pay API.
On behalf of your boss and the in-app billing API,
I would like to say, thank you for watching.