Add kotlin snippets for User Billing #975
Conversation
|
Here is the summary of changes. You are about to add 15 region tags.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request updates the playbilling dependency to version 9.1.0 and introduces a new Integration class to handle various Google Play Billing Choice integration scenarios. The review feedback highlights a critical issue where the class-level billingClient property is shadowed locally within connection methods instead of being reassigned, which requires changing the property to a var. Additionally, several redundant self-assignments and an unused import should be cleaned up to improve code quality.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| private val activity: Activity, | ||
| private val billingClient: BillingClient, | ||
| private val developerProvidedBillingListener: DeveloperProvidedBillingListener, | ||
| private val purchasesUpdatedListener: PurchasesUpdatedListener |
There was a problem hiding this comment.
The billingClient property is declared as a read-only val. However, inside startConnectionGoogleRenderedInApp and startConnectionDeveloperRenderedInApp, a new BillingClient instance is built locally and shadows this property. This local instance is discarded after the connection method finishes, meaning other methods in this class will continue to use the original, unconfigured billingClient passed to the constructor.\n\nTo fix this, change private val billingClient to private var billingClient so that the newly configured instance can be reassigned to the class property.
| private val purchasesUpdatedListener: PurchasesUpdatedListener | |
| private var billingClient: BillingClient, |
| // pending purchases support, and the billing choice params. | ||
| val billingClient = BillingClient.newBuilder(context) | ||
| .setListener(purchasesUpdatedListener) | ||
| .enablePendingPurchases(pendingPurchasesParams) |
There was a problem hiding this comment.
| val billingClient = BillingClient.newBuilder(context) | ||
| .setListener(purchasesUpdatedListener) | ||
| .enablePendingPurchases(pendingPurchasesParams) | ||
| .enableBillingProgram(params) |
| import com.android.billingclient.api.BillingProgramAvailabilityDetails.BillingChoiceAvailabilityDetails.ChoiceScreenType | ||
| import com.android.billingclient.api.BillingProgramReportingDetailsParams | ||
| import com.android.billingclient.api.BillingProgramReportingDetailsParams.DeveloperBillingType | ||
| import com.android.billingclient.api.BillingResult |
| val activity: Activity = activity | ||
|
|
||
| val params = LaunchExternalLinkParams.newBuilder() | ||
| .setBillingProgram(BillingClient.BillingProgram.BILLING_CHOICE) |
| val externalTransactionId = externalTransactionId | ||
|
|
||
| val developerBillingOptionParams = DeveloperBillingOptionParams.newBuilder() | ||
| .setBillingProgram(BillingClient.BillingProgram.BILLING_CHOICE) |
| val externalTransactionId = externalTransactionId | ||
|
|
||
| // 1. Construct DeveloperBillingOptionParams indicating the billing program | ||
| val developerBillingOptionParams = DeveloperBillingOptionParams.newBuilder() |
Add Kotlin code snippets for Play Billing Choice integration
Description
This PR adds the Kotlin code snippets for the Billing Choice integration guidance to the
playbillingmodule.The snippets have been implemented in a new file:
playbilling/src/main/java/com/example/pbl/kotlin/billingchoice/Integration.kt.To support the new Billing Choice APIs, the Play Billing Library dependency has been upgraded to
9.1.0.Changes in addition to the snippet
suspendCancellableCoroutinecould attempt to resume a continuation multiple times if the billing service disconnected after a successful connection. Addedcontinuation.isActivechecks to safeguard this.createBillingProgramReportingDetailsAsyncto use a lambda instead of an anonymousBillingProgramReportingDetailsListenerobject.