2

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)


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 :)
   }


 })


   }
}
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
KotlinNoob
  • 55
  • 5
  • while I understand your frustration, let's not focus on what the google example does (or doesn't do) which frustrates you, let's rather focus on asking a question with a goal in mind :) – a_local_nobody Nov 04 '20 at 19:57
  • Yes you are right :) I am kinda frustrated because of their example haha... but... really... if just someone could help, that would be sooo awesome :) – KotlinNoob Nov 04 '20 at 20:12
  • Well.. It is not that I am just sitting and waiting for someone to solve my problem instead of me. :) I am still reading and reading... everywhere :) Just the problem is that I am mainly finding outdated codes...and java codes :) ...and some snippets of codes which i dont have a clue how to implement :))) – KotlinNoob Nov 04 '20 at 20:55

0 Answers0