Good afternoon, Guys, please help me, I need an example code in Kotlin. I have the simplest option: no authorization, no subscriptions, no Compose. Only three products (Consumables), my own layout with three buttons (for each product).
How can I get the price of a product and setOnClickListener so that the process of purchasing this product begins?
val tv_Crystals_100: TextView = findViewById(R.id.tv_Crystals_100) val tv_Crystals_200: TextView = findViewById(R.id.tv_Crystals_200) val tv_Crystals_500: TextView = findViewById(R.id.tv_Crystals_500)
val tv_Crystals_100: TextView = findViewById(R.id.tv_btn_Buy_01) val tv_Crystals_200: TextView = findViewById(R.id.tv_btn_Buy_02) val tv_Crystals_500: TextView = findViewById(R.id.tv_btn_Buy_03)
tv_Crystals_100.text = "___" tv_Crystals_100.setOnClickListener { purchaseProduct(<put your product ID here>) }
tv_Crystals_200.text = "___" tv_Crystals_200.setOnClickListener { purchaseProduct(<put your product ID here>) }
tv_Crystals_500.text = "___" tv_Crystals_500.setOnClickListener { purchaseProduct(<put your product ID here>) }
override fun onError(error: PurchasesError, userCancelled: Boolean) { // Handle purchase error if (userCancelled) { // The user cancelled the purchase } else { // The purchase experienced an error, handle it } } }) }
val tv_Crystals_100: TextView = findViewById(R.id.tv_btn_Buy_01) val tv_Crystals_200: TextView = findViewById(R.id.tv_btn_Buy_02) val tv_Crystals_500: TextView = findViewById(R.id.tv_btn_Buy_03)
tv_Crystals_100.text = "___" tv_Crystals_100.setOnClickListener { purchaseProduct(<put your product ID here>) }
tv_Crystals_200.text = "___" tv_Crystals_200.setOnClickListener { purchaseProduct(<put your product ID here>) }
tv_Crystals_500.text = "___" tv_Crystals_500.setOnClickListener { purchaseProduct(<put your product ID here>) }
override fun onError(error: PurchasesError, userCancelled: Boolean) { // Handle purchase error if (userCancelled) { // The user cancelled the purchase } else { // The purchase experienced an error, handle it } } }) }
Thanks for confirming you got it working! If you are able, please share what changes you had to make so that I can fix my original answer. If you are not able then no problem, I’m glad it’s working now.
Yes, of course, here is an example of code that works for me. Let me remind you that I have the simplest option. Three buttons, three products (Consumables), and my own layout.
1 Kotlin
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.xxxxxxxxxxxxx)
val tv_btn_Buy_01: TextView = findViewById(R.id.tv_btn_Buy_01) val tv_btn_Buy_02: TextView = findViewById(R.id.tv_btn_Buy_02) val tv_btn_Buy_03: TextView = findViewById(R.id.tv_btn_Buy_03)
If I have a mistake or something that can be improved, please write.
Now I'm sorting out errors when making a purchase. And I don’t quite understand what and how errors need to be handled. For example this: PurchasesErrorCode.OperationAlreadyInProgressError.
This parameter Purchases.logLevel = LogLevel.DEBUG is needed for debugging. What should this parameter be for shopping to work as usual?