See the App Inventor Extensions document about how to use an App Inventor Extension.
For questions about this extension or bug reports please start a new thread in the
App Inventor community. Thank you.
For feature requests please contact me by email.
To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. Thank you.
Aug 15th, 2016: Version 1: initial version of the Billing Extension released
Aug 14th, 2019: Version 2: in app billing library updated to V 1.1.
Aug 29th, 2019: Version 2a: in app billing library updated to V 1.1 and Google Billing API V2.0.3 added.
Google deprecates the Google Play Billing with AIDL end of December 2019.
This version fixes this. Both example apps, the Airline example as well as the
Subscription example have been tested successfully together with version 2a on a Google Pixel device running Android 9.
This extension enables you to use Google In-App Billing in your App Inventor app for Products (both non-consumable and consumable) and Subscriptions.
Required permission: com.android.vending.BILLING
This extension uses the Android In-App Billing v3 library V 1.1. Thank you Anj Lab!
Thank you Johannes for being the sponsor of this extension.
Returns whether In-app billing service is ready to purchase.
Initialize the In-App Billing service using your licency key and merchant id.
How to get this information, see chapter Preparation for your own app.
Note: The GotOwnItems event will be fired automatially after using that method.
Load Own Items.
Purchase Product.
Note: The purchase process takes a few seconds. You have to trigger the method LoadOwnItems to refresh the purchased items.
You only can purchase a product once. Then you first have to consume it before being able to purchase it again.
Consume product.
Note: The GotOwnItems event will be fired automatially after using that method.
Subscribe.
Note: The purchase process takes a few seconds. You have to trigger the method LoadOwnItems to refresh the subscribed items.
You only can subscribe an item once.
Get Product Details.
Get Subscription Details.
Event indicating that own items have been loaded.
A list of own products and own subscriptions will be returned.
Event indicating that product details have been received.
Event indicating that subscription details have been received.
Event indicating that an error occurred.
Let's assume, you like to offer a free version of your app and a premium version. After paying a small amount, the user can upgrade to the premium version
to get additional features. So there is only one product to buy. After successful purchase, store the status (premium) in TinyDB,
so you also can get the correct status of the app (free or premium) also if there is no internet connection.
You can test the example using the test product android.test.purchased also in the companion app.
If you want to test again, first consume the product and clear the tag premium in TinyDB.
Initialize
Product Details
Purchase
Note: I'm located in Costa Rica, therefore I get the local currency CRC (Costa Rican Colones) displayed...
Further blocks used
Yes, it's really simple...
Setup
protip: use simple subscription ids, in the example I used sub01
Screenshots
Note: I'm located in Costa Rica, therefore I get the local currency CRC (Costa Rican Colones) displayed...
Blocks
After subscribing, Google will send an email to confirm the subscription.
Q1: I get the error message "Authentication is required"?
A: See this stackoverflow answer:
Make sure your app is PUBLISHED to any version (alpha, beta or production). Also you must test using your apk file.
Exception: you can purchase the test product android.test.purchased also using the companion app.
Q2: I get the error message "The Item you requested is not available for purchase"?
A: See this stackoverflow answer for some things to check.
Q3: How can I test the subscriptions?
A: See this stackoverflow answer.
Q4: I would like to remove ads after purchase. Should I publish 2 apps to Alpha (with ads and without ads) OR publish 1 app and code this:
"After purchase, remove all ads (permanently, e.g. TinyDB)"?
A: I would publish one app only.
Q5: It would be nice to see publishing process step by step on forum or video.
A: There is loads of information online concerning Google In App Billing, just look around a little bit, see for example this
Google Search result
or this Youtube Search result
and choose a step by step guide of your choice.
Q6: I did not understand the additional Security Recommendation? What does it mean "Retrieve it from an encrypted store"?
A: To keep it as simple as possible for you, just copy the licence key and your merchant id as they are into the corresponding variables.
To have additional security, in App Inventor you 1) could write your own procedure to construct your license key string during runtime from substrings.
2) Also instead of storing the licence key itself, you could store the encrypted licence key using the
AES extension inside your app.
You would have to store additionally a password to be able to decrypt the license key again before using it.
Q7: How can I give the users instant access to the new features in my app right after they buy an item?
What happens right after they purchase an item? Is there an event triggered?
A: There is no AfterPurchase event available. Therefore the suggestion is to follow "Example 1, as simple as possible",
which uses a button "Continue" to call procedure "LoadOwnItems".
Q8:When I try to make a purchase, the android purchase popup will appear briefly, load for a moment, and then the app will crash.
What can I do?
A: There is an issue with Play Store version 7.9.80.Q-all and test products, see also
this stackoverflow question.
For this Google Play version you might want to test using real product ids instead until Google fixed that issue.
Q9: What will happen if someone deletes the app then wants to reinstall it - what blocks do I need for a "Restore" button?
A: Google of course still knows, that the user bought the product, which means in the OwnItemsLoaded event
(which fires after calling the Initialize method or also the LoadOwnPurchases method) you will receive the list of purchased products
also if a user reinstalls the app and also if the user installs the app on another device using the same Google login.
Q10: How to prevent In App purchase bypass?
A: I recommend to follow additionally the recommendations by Cian as well as
to use the HackProtect Extension by cian to prevent In App Purchase bypass. Thank you Cian!
Q11: How to implement the Account Hold and Restore feature?
A: Just implement deep links, see here. With that you meet the requirements of Google Play.
Google wants users to know that they can manage their subscriptions.
Q12: We are a self-service laundry and would like to to implement your solution to charge people by mobile phone for our services.
A: Are you aware, that Google charges a service fee of 30% of the price? You only will receive 70% of the payment,
see also here.
If the payment is primarily for physical goods or services as in your case, then let me suggest you to NOT use the in app billing extension, but another solution.
See also the Google Policy.
For questions concerning other payment options please do a search in the App Inventor community or ask there. Thank you.
Q13: We have detected that this app uses an old version of Google Play Billing. By November 1, 2021, all app updates will need to use version 3 or later
of the Play Billing library. Upgrade to version 3 before that date. Learn more about the Google Play Billing 3 library.
A: This is a new warning you get in the Google Play console after using the billing extension. Which means, there is time until November 2021 to switch to the new version 3.
Meanwhile take the warning as what it is: a warning and ignore it.
I'm currently in the process of developing a new version of the billing extension based on the Google Play Billing 3 library.
The new version will have new methods and events and therefore an update from the old to the new version will not be available.
The new version will be available end of April/beginning of May 2021. Everyone who bought the billing extension in 2020 or 2021 will be able to download the new version for free.
Everyone who bought the billing extension earlier will be able to buy the new version for a reduced price.
The test app is available in Google Play. You can test the example following these steps
The test app is available in Google Play. You can test the example following these steps
You can buy this extension (aix file).
With your payment you accept the
terms and conditions below.
Payment options
1.
Please transfer 12 USD via Paypal
to Pura Vida Apps
2.
After having received your payment I will be happy to send the download link to you. Please let me know your Google account!
I usually will send the download link not later than 24 hours after having received your payment.
Thank you! Taifun