Android Kotlin: Adding subscription nightmare (+ Billing library 3.0)

I am being heavily ignored in the last days on this forum… but I will give it another try πŸ™‚

Ok.. I have downloaded Google’s Trivial Drive app which should be kinda demo app for learning how to add billing library into your app… But… They made it soooo much (in my opinion) unnecessary complex and complicated…

They focused so much on some layouts and made dozens of micro procedures which makes it very hard to get everything connected in your head… Even just checking if fuel is empty of full tank got sooo much complex…

​

And the irony of the life is that in few places they wrote: “To keep simple things simple”

​

​

Can someone help me with the most simple code for buying 1 month subscription and buying 1 product?

​

Please… Just the absolute bare minimum of code in one file… Without using my own server support for tracking sales… and if possible… to be compatible with Billing library 3.0 :)))

​

In short.. I would like this code to do:

—————————————————————————————————————————–

You click button [Subscribe] and get a Google Play dialog menu to pay for sub

You click button [Buy fuel] and get a Google Play dialog menu to pay for product

You click button [Action button] and code checks the status of subscription (Active, Expired, Canceled, In grace period, On hold, Paused)

 // Is there a status ---> NEVER BOUGHT SUBSCRIPTION... or something like that?) 

And there should be some event… Some trigger where you will get status what happened with requested purchase of product…

override fun OnSomeActivityDontKnowWhichOne(action: Action, string: String)

—————————————————————————————————————————–

​

Ok.. Soo… Visually …something like this:

​

package example.asdf.com.billy import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Toast var CarFuel = 0 class MainActivity : AppCompatActivity() { override fun OnSomeActivityDontKnowWhichOne(action: Action, product: String) { if (action == PURCHASE_PRODUCT_OK) { if (product == "car_fuel") { CarFuel++ Toast.makeText(applicationContext, "Thank you for your purchase. You have now " + CarFuel.toString() + " unit(s) of fuel", Toast.LENGTH_SHORT).show() } } if (action == PURCHASE_PRODUCT_NOT_OK { Toast.makeText(applicationContext,"Purchase failed...", Toast.LENGTH_SHORT).show() } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Text on button: [Subscribe] val BuySub = findViewById<Button>(R.id.buttonBuyOneMonthSub) BuySub.setOnClickListener(View.OnClickListener { // When you click button [Subscribe] it should appear // Google Play dialog for paying for 1 month subscription RequestBuySubscription() }) // Text on button: [Buy fuel] val BuyProduct = findViewById<Button>(R.id.buttonBuyMyCoolProduct) BuyProduct.setOnClickListener(View.OnClickListener { // When you click button [Buy fuel] it should appear // Google Play dialog for buying a product RequestPurchaseProduct(ProductId) }) // Text on button: [Action button] val MyCoolAction = findViewById<Button>(R.id.buttonActionButton) MyCoolAction.setOnClickListener(View.OnClickListener { // check if subscription is active... // like... val Status = GetSubscriptionStatus() // Status can be Active, Expired, Canceled, In grace period, On hold, Paused // Is there a status ---> NEVER BOUGHT SUBSCRIPTION... or something like that? if (Status == EXPIRED) { Toast.makeText(applicationContext, "Subscription expired. Please click [Subscribe]", Toast.LENGTH_SHORT).show() return@OnClickListener } if (Status == ACTIVE) { Toast.makeText(applicationContext, "Thank you for being our vip user :)", Toast.LENGTH_SHORT).show() FetchSubStartTime() FetchSubExpirationTime() // It would be good to fetch date of Subscription start and subscription end // Preferably if possible to get unix times :) } }) } } 

submitted by /u/KotlinNoob
[link] [comments]