Example you have 2 subscriptions (2 products) like this
[
ProductDetails{
parsedJson={
"productId": "...",
"subscriptionOfferDetails": [
{
"offerIdToken": "...token_1...",
"pricingPhases": [
{
"priceAmountMicros": 631000000000,
"priceCurrencyCode": "VND",
"formattedPrice": "₫631,000",
"billingPeriod": "P6M",
}
]
}
]
}
},
ProductDetails{
parsedJson={
"productId": "...",
"subscriptionOfferDetails": [
{
"offerIdToken": "...token_2...",
"pricingPhases": [
{
"priceAmountMicros": 0,
"priceCurrencyCode": "VND",
"formattedPrice": "Free",
"billingPeriod": "P1M",
"recurrenceMode": 2,
"billingCycleCount": 1
},
{
"priceAmountMicros": 112000000000,
"priceCurrencyCode": "VND",
"formattedPrice": "₫112,000",
"billingPeriod": "P6M",
}
],
{
"offerIdToken": "...token_3...",
"pricingPhases": [
{
"priceAmountMicros": 631000000000,
"priceCurrencyCode": "VND",
"formattedPrice": "₫631,000",
"billingPeriod": "P6M",
}
]
}
}
]
}
}
]
Example to buy the 1st plan (with 1 month free trial) on 2nd subscription (ProductDetails)
val productDetails2 = ...
val offerToken = "...token_2..."
// val offerToken = productDetails2.subscriptionOfferDetails.get(0).offerToken
// in json response, it name is offerIdToken but after parse it's offerToken
val productDetailsParamsList =
listOf(
BillingFlowParams.ProductDetailsParams.newBuilder()
.setProductDetails(productDetails2)
.setOfferToken(offerToken)
.build()
)
val billingFlowParams = BillingFlowParams.newBuilder()
.setProductDetailsParamsList(productDetailsParamsList)
.build()
billingClient.launchBillingFlow(this, billingFlowParams)
getSubscriptionOfferDetails()
returns a typeList<ProductDetails.SubscriptionOfferDetails>
, you need a singular object of typeProductDetails.SubscriptionOfferDetails
, so theselectedOfferIndex
is the index of the item that the user has selected from the list of offers available. More info on api docs: developer.android.com/reference/com/android/billingclient/api/… – Linearity