@@ -72,15 +72,15 @@ class KotlinSampleActivity : AppCompatActivity() {
7272 subscriptionIds.add(" subscription_id_3" )
7373
7474 billingConnector = BillingConnector (
75- this ,
76- " license_key" ) // "license_key" - public developer key from Play Console
77- .setConsumableIds(consumableIds) // to set consumable ids - call only for consumable products
78- .setNonConsumableIds(nonConsumableIds) // to set non-consumable ids - call only for non-consumable products
79- .setSubscriptionIds(subscriptionIds) // to set subscription ids - call only for subscription products
80- .autoAcknowledge() // legacy option - better call this. Alternatively purchases can be acknowledge via public method "acknowledgePurchase(PurchaseInfo purchaseInfo)"
81- .autoConsume() // legacy option - better call this. Alternatively purchases can be consumed via public method consumePurchase(PurchaseInfo purchaseInfo)"
82- .enableLogging() // to enable logging for debugging throughout the library - this can be skipped
83- .connect() // to connect billing client with Play Console
75+ this ,
76+ " license_key" ) // "license_key" - public developer key from Play Console
77+ .setConsumableIds(consumableIds) // to set consumable ids - call only for consumable products
78+ .setNonConsumableIds(nonConsumableIds) // to set non-consumable ids - call only for non-consumable products
79+ .setSubscriptionIds(subscriptionIds) // to set subscription ids - call only for subscription products
80+ .autoAcknowledge() // legacy option - better call this. Alternatively purchases can be acknowledge via public method "acknowledgePurchase(PurchaseInfo purchaseInfo)"
81+ .autoConsume() // legacy option - better call this. Alternatively purchases can be consumed via public method consumePurchase(PurchaseInfo purchaseInfo)"
82+ .enableLogging() // to enable logging for debugging throughout the library - this can be skipped
83+ .connect() // to connect billing client with Play Console
8484
8585 billingConnector.setBillingEventListener(object : BillingEventListener {
8686 override fun onProductsFetched (productDetails : MutableList <ProductInfo >) {
@@ -89,23 +89,23 @@ class KotlinSampleActivity : AppCompatActivity() {
8989
9090 for (productInfo in productDetails) {
9191 product = productInfo.product
92- price = productInfo.oneTimePurchaseOfferPrice
92+ price = productInfo.oneTimePurchaseOfferFormattedPrice
9393
9494 if (product.equals(" consumable_id_1" , ignoreCase = true )) {
9595 // TODO - do something
9696 Log .d(" BillingConnector" , " Product fetched: $product " )
9797 Toast .makeText(
98- this @KotlinSampleActivity,
99- " Product fetched: $product " ,
100- Toast .LENGTH_SHORT
98+ this @KotlinSampleActivity,
99+ " Product fetched: $product " ,
100+ Toast .LENGTH_SHORT
101101 ).show()
102102
103103 // TODO - do something
104104 Log .d(" BillingConnector" , " Product price: $price " )
105105 Toast .makeText(
106- this @KotlinSampleActivity,
107- " Product price: $price " ,
108- Toast .LENGTH_SHORT
106+ this @KotlinSampleActivity,
107+ " Product price: $price " ,
108+ Toast .LENGTH_SHORT
109109 ).show()
110110 }
111111
@@ -116,8 +116,8 @@ class KotlinSampleActivity : AppCompatActivity() {
116116 }
117117
118118 override fun onPurchasedProductsFetched (
119- productType : ProductType ,
120- purchases : MutableList <PurchaseInfo >
119+ productType : ProductType ,
120+ purchases : MutableList <PurchaseInfo >
121121 ) {
122122 /*
123123 * This will be called even when no purchased products are returned by the API
@@ -127,14 +127,17 @@ class KotlinSampleActivity : AppCompatActivity() {
127127 ProductType .INAPP -> {
128128 // TODO - non-consumable/consumable products
129129 }
130+
130131 ProductType .SUBS -> {
131132 // TODO - subscription products
132133 }
134+
133135 ProductType .COMBINED -> {
134136 // this will be triggered on activity start
135137 // the other two (INAPP and SUBS) will be triggered when the user actually buys a product
136138 // TODO - restore purchases
137139 }
140+
138141 else -> {
139142 Log .d(" BillingConnector" , " None of the above ProductType match" )
140143 }
@@ -146,9 +149,9 @@ class KotlinSampleActivity : AppCompatActivity() {
146149 // TODO - do something
147150 Log .d(" BillingConnector" , " Purchased product fetched: $it " )
148151 Toast .makeText(
149- this @KotlinSampleActivity,
150- " Purchased product fetched: $it " ,
151- Toast .LENGTH_SHORT
152+ this @KotlinSampleActivity,
153+ " Purchased product fetched: $it " ,
154+ Toast .LENGTH_SHORT
152155 ).show()
153156 }
154157
@@ -169,17 +172,17 @@ class KotlinSampleActivity : AppCompatActivity() {
169172 // TODO - do something
170173 Log .d(" BillingConnector" , " Product purchased: $product " )
171174 Toast .makeText(
172- this @KotlinSampleActivity,
173- " Product purchased: $product " ,
174- Toast .LENGTH_SHORT
175+ this @KotlinSampleActivity,
176+ " Product purchased: $product " ,
177+ Toast .LENGTH_SHORT
175178 ).show()
176179
177180 // TODO - do something
178181 Log .d(" BillingConnector" , " Purchase token: $purchaseToken " )
179182 Toast .makeText(
180- this @KotlinSampleActivity,
181- " Purchase token: $purchaseToken " ,
182- Toast .LENGTH_SHORT
183+ this @KotlinSampleActivity,
184+ " Purchase token: $purchaseToken " ,
185+ Toast .LENGTH_SHORT
183186 ).show()
184187 }
185188
@@ -207,9 +210,9 @@ class KotlinSampleActivity : AppCompatActivity() {
207210 // TODO - do something
208211 Log .d(" BillingConnector" , " Acknowledged: ${purchase.product} " )
209212 Toast .makeText(
210- this @KotlinSampleActivity,
211- " Acknowledged: ${purchase.product} " ,
212- Toast .LENGTH_SHORT
213+ this @KotlinSampleActivity,
214+ " Acknowledged: ${purchase.product} " ,
215+ Toast .LENGTH_SHORT
213216 ).show()
214217 }
215218
@@ -231,9 +234,9 @@ class KotlinSampleActivity : AppCompatActivity() {
231234 // TODO - do something
232235 Log .d(" BillingConnector" , " Consumed: ${purchase.product} " )
233236 Toast .makeText(
234- this @KotlinSampleActivity,
235- " Consumed: ${purchase.product} " ,
236- Toast .LENGTH_SHORT
237+ this @KotlinSampleActivity,
238+ " Consumed: ${purchase.product} " ,
239+ Toast .LENGTH_SHORT
237240 ).show()
238241 }
239242
@@ -242,22 +245,26 @@ class KotlinSampleActivity : AppCompatActivity() {
242245 }
243246
244247 override fun onBillingError (
245- billingConnector : BillingConnector ,
246- response : BillingResponse
248+ billingConnector : BillingConnector ,
249+ response : BillingResponse
247250 ) {
248251 when (response.errorType) {
249252 ErrorType .CLIENT_NOT_READY -> {
250253 // TODO - client is not ready yet
251254 }
255+
252256 ErrorType .CLIENT_DISCONNECTED -> {
253257 // TODO - client has disconnected
254258 }
259+
255260 ErrorType .PRODUCT_NOT_EXIST -> {
256261 // TODO - product does not exist
257262 }
263+
258264 ErrorType .CONSUME_ERROR -> {
259265 // TODO - error during consumption
260266 }
267+
261268 ErrorType .CONSUME_WARNING -> {
262269 /*
263270 * This will be triggered when a consumable purchase has a PENDING state
@@ -270,9 +277,11 @@ class KotlinSampleActivity : AppCompatActivity() {
270277 * */
271278 // TODO - warning during consumption
272279 }
280+
273281 ErrorType .ACKNOWLEDGE_ERROR -> {
274282 // TODO - error during acknowledgment
275283 }
284+
276285 ErrorType .ACKNOWLEDGE_WARNING -> {
277286 /*
278287 * This will be triggered when a purchase can not be acknowledged because the state is PENDING
@@ -285,51 +294,62 @@ class KotlinSampleActivity : AppCompatActivity() {
285294 * */
286295 // TODO - warning during acknowledgment
287296 }
297+
288298 ErrorType .FETCH_PURCHASED_PRODUCTS_ERROR -> {
289299 // TODO - error occurred while querying purchased products
290300 }
301+
291302 ErrorType .BILLING_ERROR -> {
292303 // TODO - error occurred during initialization / querying product details
293304 }
305+
294306 ErrorType .USER_CANCELED -> {
295307 // TODO - user pressed back or canceled a dialog
296308 }
309+
297310 ErrorType .SERVICE_UNAVAILABLE -> {
298311 // TODO - network connection is down
299312 }
313+
300314 ErrorType .BILLING_UNAVAILABLE -> {
301315 // TODO - billing API version is not supported for the type requested
302316 }
317+
303318 ErrorType .ITEM_UNAVAILABLE -> {
304319 // TODO - requested product is not available for purchase
305320 }
321+
306322 ErrorType .DEVELOPER_ERROR -> {
307323 // TODO - invalid arguments provided to the API
308324 }
325+
309326 ErrorType .ERROR -> {
310327 // TODO - fatal error during the API action
311328 }
329+
312330 ErrorType .ITEM_ALREADY_OWNED -> {
313331 // TODO - item is already owned
314332 }
333+
315334 ErrorType .ITEM_NOT_OWNED -> {
316335 // TODO - failure to consume since item is not owned
317336 }
337+
318338 else -> {
319339 Log .d(" BillingConnector" , " None of the above ErrorType match" )
320340 }
321341 }
322342
323343 Log .d(
324- " BillingConnector" , " Error type: ${response.errorType} " +
325- " Response code: ${response.responseCode} " + " Message: ${response.debugMessage} "
344+ " BillingConnector" , " Error type: ${response.errorType} " +
345+ " Response code: ${response.responseCode} " + " Message: ${response.debugMessage} "
326346 )
327347
328348 Toast .makeText(
329- this @KotlinSampleActivity,
330- " Error type: ${response.errorType} " + " Response code: ${response.responseCode} "
331- + " Message: ${response.debugMessage} " ,
332- Toast .LENGTH_SHORT
349+ this @KotlinSampleActivity,
350+ " Error type: ${response.errorType} " + " Response code: ${response.responseCode} "
351+ + " Message: ${response.debugMessage} " ,
352+ Toast .LENGTH_SHORT
333353 ).show()
334354 }
335355 })
@@ -417,14 +437,17 @@ class KotlinSampleActivity : AppCompatActivity() {
417437 // TODO - do something
418438 Log .d(" BillingConnector" , " Device subscription support: SUPPORTED" )
419439 }
440+
420441 SupportState .NOT_SUPPORTED -> {
421442 // TODO - do something
422443 Log .d(" BillingConnector" , " Device subscription support: NOT_SUPPORTED" )
423444 }
445+
424446 SupportState .DISCONNECTED -> {
425447 // TODO - do something
426448 Log .d(" BillingConnector" , " Device subscription support: client DISCONNECTED" )
427449 }
450+
428451 else -> {
429452 Log .d(" BillingConnector" , " None of the above SupportState match" )
430453 }
@@ -441,27 +464,31 @@ class KotlinSampleActivity : AppCompatActivity() {
441464 // TODO - do something
442465 Log .d(" BillingConnector" , " The product: ${productInfo.product} is purchased" )
443466 }
467+
444468 PurchasedResult .NO -> {
445469 // TODO - do something
446470 Log .d(
447- " BillingConnector" ,
448- " The product: ${productInfo.product} is not purchased"
471+ " BillingConnector" ,
472+ " The product: ${productInfo.product} is not purchased"
449473 )
450474 }
475+
451476 PurchasedResult .CLIENT_NOT_READY -> {
452477 // TODO - do something
453478 Log .d(
454- " BillingConnector" ,
455- " Cannot check: ${productInfo.product} because client is not ready"
479+ " BillingConnector" ,
480+ " Cannot check: ${productInfo.product} because client is not ready"
456481 )
457482 }
483+
458484 PurchasedResult .PURCHASED_PRODUCTS_NOT_FETCHED_YET -> {
459485 // TODO - do something
460486 Log .d(
461- " BillingConnector" ,
462- " Cannot check: ${productInfo.product} because purchased products are not fetched yet"
487+ " BillingConnector" ,
488+ " Cannot check: ${productInfo.product} because purchased products are not fetched yet"
463489 )
464490 }
491+
465492 else -> {
466493 Log .d(" BillingConnector" , " None of the above PurchasedResult match" )
467494 }
0 commit comments