Skip to content

Instantly share code, notes, and snippets.

@LethalMaus
Created March 11, 2024 21:42
Show Gist options
  • Select an option

  • Save LethalMaus/ac577bacd3421eac82177f4dc6b83ec7 to your computer and use it in GitHub Desktop.

Select an option

Save LethalMaus/ac577bacd3421eac82177f4dc6b83ec7 to your computer and use it in GitHub Desktop.
monetization.kt
// An activity reference from which the billing flow will be launched.
val activity : Activity = ...;
val productDetailsParamsList = listOf(
BillingFlowParams.ProductDetailsParams.newBuilder()
// retrieve a value for "productDetails" by calling queryProductDetailsAsync()
.setProductDetails(productDetails)
// For One-time product, "setOfferToken" method shouldn't be called.
// For subscriptions, to get an offer token, call ProductDetails.subscriptionOfferDetails()
// for a list of offers that are available to the user
.setOfferToken(selectedOfferToken)
.build()
)
val billingFlowParams = BillingFlowParams.newBuilder()
.setProductDetailsParamsList(productDetailsParamsList)
.build()
// Launch the billing flow
val billingResult = billingClient.launchBillingFlow(activity, billingFlowParams)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment