I have upgraded my Kotlin app to android-billing 5.0 from 4.0, and as such, SkuDetails is now deprecated so I am migrating to using ProductDetails using the migration instructions.
Previously I displayed the purchase price for in-app purchases to the user using SkuDetails.price, but I cannot find a similar method in ProductDetails.
In Google Play Billing Library 5.0, is there a non-deprecated way to retrieve the price for an in-app purchase or subscription?
Based on the documentation you can call getOneTimePurchaseOfferDetails()
on ProductDetails to return a ProductDetails.OneTimePurchaseOfferDetails
object, which has a getFormattedPrice()
method to return the price for in-app purchases.
For subscriptions you can call getSubscriptionOfferDetails()
which returns a list of ProductDetails.SubscriptionOfferDetails
objects, which have a getPricingPhases()
method to return different pricing phases. The pricing phase objects have a getFormattedPrice()
method to get the price from.
UPDATE
To better explain what this new approach allows, you can now create multiple "base plans" for a given subscription product. For example, you could create an "unlimited" product, then create an "unlimited-annual" plan for $50/year and an "unlimited-monthly" plan for $5/month.
The ProductDetails
returned for a configuration like that would look like this - where you have a single productId
with multiple payment rates/plans. If you add a promotion (e.g. discount for the first year) that shows up with a non-null offerId
under an existing base plan ID.
{
productId: "unlimited",
subscriptionOfferDetails:
[
{
basePlanId: "unlimited-monthly",
offerId: null,
pricingPhases:
[
{formattedPrice: "$5", billingPeriod: P1M, recurrence: 1}
]
},
{
basePlanId: "unlimited-annual",
offerId: null,
pricingPhases:
[
{formattedPrice: "$50", billingPeriod: P1Y, recurrence: 1}
]
},
{
basePlanId: "unlimited-annual",
offerId: "unlimited-annual-promotion",
pricingPhases:
[
{formattedPrice: "$30", billingPeriod: P1Y, recurrence: 2}
{formattedPrice: "$50", billingPeriod: P1Y, recurrence: 1}
]
}
],
oneTimePurchaseOfferDetails: null
}
There are also details from Google here about the new format.