Skip to content

Instantly share code, notes, and snippets.

@PriyaSindkar
Created December 23, 2022 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PriyaSindkar/5f5586be8bdac64193e2a76cdeb3bf5d to your computer and use it in GitHub Desktop.
Save PriyaSindkar/5f5586be8bdac64193e2a76cdeb3bf5d to your computer and use it in GitHub Desktop.
// Migrating queries to fetch all products (From skus to products)
// v4.0 - deprecated
val skuList = ArrayList<String>()
skuList.add("up_basic_sub")
val params = SkuDetailsParams.newBuilder()
params.setSkusList(skuList).setType(BillingClient.SkuType.SUBS)
billingClient.querySkuDetailsAsync(params.build()) {
billingResult, skuDetailsList ->
// Process the result
}
// v5.0 - new
val productList =
listOf(QueryProductDetailsParams.Product.newBuilder()
.setProductId("up_basic_sub")
.setProductType( BillingClient.ProductType.SUBS).build())
val params = QueryProductDetailsParams.newBuilder()
.setProductList(productList)
billingClient.queryProductDetailsAsync(params.build()) {
billingResult, productDetailsList ->
// Process the result
}
// ============================================================
// Migrating queries to launch the purchase flow
// v4.0 - deprecated
val activity : Activity = ...;
val billingFlowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails)
.build()
val billingResult = billingClient.launchBillingFlow(activity, billingFlowParams)
// v5.0 - new
val offerToken = productDetails.subscriptionOfferDetails?.get(selectedOfferIndex)?.offerToken
val productDetailsParamsList = listOf(BillingFlowParams.ProductDetailsParams
.newBuilder()
.setProductDetails(productDetails)
.setOfferToken(offerToken)
.build())
val billingFlowParams = BillingFlowParams.newBuilder().setProductDetailsParamsList(productDetailsParamsList).build()
val billingResult = billingClient.launchBillingFlow(activity, billingFlowParams)
// =====================================================
// Migrating queries to fetch the purchases
// v4.0 - deprecated
billingClient.queryPurchasesAsync(BillingClient.SkuType.SUBS) { billingResult, purchaseList -> {
// Process the result
}
}
// v5.0 - new
billingClient.queryPurchasesAsync(QueryPurchasesParams.newBuilder()
.setProductType(BillingClient.ProductType.SUBS)
.build()) { billingResult, purchaseList ->
// Process the result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment