This is a complete guide for all those koders who want to integrate In-App billing in their project
Note : I used billing extension made by @Taifun
STEP 1 : Prepare everything
A. All you need is a Google Play Console, with your merchant account activated !!
B. Select the app in which you want to integrate in-app billing.
C. Choose In-app products under Monetise section
D. Click on Create Product
E. Enter name of your product, for an example - product1, product2, etc
F. Enter Product Details
G. Set the price you want or you can choose the price from your pricing templates
Now save and activate your product and copy the product id, we will use it later in our project
STEP 2 : Itâs time for koding
A. Components that i used
B. Blocks
C. Explanation
- Use start connection block when screen1 is initialized, it will trigger
SetupFinished
event.
- As per googleâs new policy, you have to consume or acknowledge the purchase in 3 days may be otherwise your payment will be refunded automatically. so, i suggest you to set the AutoAcknowledge to true and call
a. Product Details - it will trigger Got Product Details
b. Purchased Products - it will trigger GotPurchasedProducts
- You can show your price in a label by this block
- You can check if the user had purchased the product in the past or not by checking whether the acknowledged list is empty or not.
If the list is not empty it means user had made the purchase in past and if it is empty then user has not purchased it yet
I used the global variable - FIRST_TIME to check whether the user is new or old. if the user is new and just purchased the product then it it will show - Purchase Successful otherwise Purchase Restored if the user is old and reinstalled the application.
Note - Status.text is nothing but just to show that the product is purchased or not, you can replace it by any premium function you want like removing ads from your app.
- The button is used to make the purchase. first it checks whether the product is purchased or not . if the product is purchased then it will show an error. so it is better to prevent it by using if and else block.
Now as we have set the autoacknowledge to true, so if the purchase is successful then it will trigger the event - Acknowledged
and if the purchase is not successful then it will trigger the event - Error Occurred
- Now as the user is new so iâve to set FIRST_TIME to YES. check the fourth point to know why i used it.
- Our final block, i donât think there is any need to explain it
SCREENSHOTS
Thatâs all,
For more information visit this site - App Inventor Extensions: Billing | Pura Vida Apps
FAQ
- Iâm unable to find my product id !!
- look, if youâve not uploaded your apk then please upload it first in order to create product id. What you need to do is to create your apk integrated with InApp Billing any use any random product id, for ex - âproduct01â. now after uploading this, use the same product id while creating it in your console. Done
- Why do i need to buy this extension, canât i use kodular InApp Billing component?
- my simple answer is⊠you can but i donât suggest you to do so because the library kodular InApp Billing is using isnât latest and you canât use it after November 2021 as per googleâs policy. Also if youâre thinking to use it before November then please donât, you will lose your earning as some payments are getting back to the user automatically. Iâm telling you this by my experience.
If you have any question, feel free to ask
To test your app, change your product id to android.test.purchased
Note- i didnât find any way of cancelling the purchase after it is refunded. So⊠thatâs all. iâll add subscription method as well but later.
Thanks to @Taifun for this amazing extension and for this amazing platform.
Thank you