3

I'm investigating using the new Play Billing Library, and one thing I'm concerned about is the products introductory prices.

I'm wondering if there is a way to retrieve the introductory prices with the new library. As far as I know it could be done with the Google Play In-app Billing APIs as described in this Stackoverflow question, but I can't find a similar approach using the new Billing library.

Has anyone come through this before?

goRGon
  • 4,402
  • 2
  • 43
  • 45
Mina Wissa
  • 10,923
  • 13
  • 90
  • 158

2 Answers2

2

Yes, there is. Kindly see this >> https://codelabs.developers.google.com/codelabs/play-billing-codelab/#1

val skuList = arrayListOf("sku_id_of_in_app_product","sku_id_of_in_app_product")
val itemType = SkuType.INAPP // or SkuType.SUBS that corresponds with the skuList
val skuDetailsParams = SkuDetailsParams.newBuilder().setSkusList(skuList).setType(itemType).build()

mBillingClient.querySkuDetailsAsync(skuDetailsParams, object : SkuDetailsResponseListener{
    override fun onSkuDetailsResponse(responseCode: Int, skuDetailsList: MutableList<SkuDetails>?) {
       responseListener.onSkuDetailsResponse(responseCode, skuDetailsList);
   }
})

Your Listener: You need to use a listener so that you will be able to get a response when the Asynchronous Query is done!

val responseListener = SkuDetailsResponseListener { responseCode, skuDetailsList ->
    if (responseCode == BillingClient.BillingResponse.OK && skuDetailsList != null) {
        val inList = ArrayList<SkuRowData>()
        for (details in skuDetailsList) {
            Log.i(TAG, "Found sku: $details")
            inList.add(SkuRowData(details.sku, details.title, details.price, details.introductoryPrice, details.description, details.type))
         }
     }
 }

SkuRowData is just a model class

class SkuRowData(sku: String?, title: String?, price: String?, introductory_price: String?, description: String?, type: String?)

Be aware that you can only get introductory Price for subscription in app product!

EdgeDev
  • 2,376
  • 2
  • 20
  • 37
  • Thanks, but I didn't find any properties that expose the SKU introductory price, there are the title, price, details, ... but not the introductory price – Mina Wissa Sep 27 '17 at 09:10
  • SKU introductory price is not the same as your SKU price returned by getPrice() method. So you should use getIntroductoryPrice() method instead. – goRGon Sep 29 '17 at 20:47
  • @goRGon oh, thanks i was using `getPrice()` Instead. – EdgeDev Sep 30 '17 at 19:51
  • 1
    @goRGon is the price returned by the getIntroductoryPrice() what that particular user will get charged? how about users that do not qualify for the introductory price because they already purchased that product (or another one) before? – XAnguera Feb 01 '18 at 19:13
  • @XAnguera did you find a way to know if the user is qualified for the introductory price or not? – Mina Wissa Apr 04 '18 at 13:25
  • @MinaSamy Unfortunately not. Right now I am making the hypothesis on server side that the user is qualified for the intro price if this is the first time he purchases a product with intro price enabled. This is not a failproof solution, but will do for us until Google adds this info in the receipt or makes an API for it. – XAnguera Apr 05 '18 at 15:00
  • @XAnguera Thanks, yes I was thinking about a similar solution, it seems like we'll have to wait for Google – Mina Wissa Apr 05 '18 at 19:41
  • @XAnguera any update on this perhaps? I'm experiencing the same issue and I was hoping there has been a way to determine if a user has received, or is eligible, for an introductory price? – saltandpepper Apr 16 '19 at 09:59
  • Introductory price is not showing, whenever we launch it is showing the regular price for every user. – KKSINGLA May 10 '21 at 15:04
1

You should just query SKU details and use getIntroductoryPrice() method for the items from the result list.

P.S. It was added recently into 1.0 release. So if you got the library within first days of the release, you should clear your gradle cache and /build folders to re-download an updated release.

goRGon
  • 4,402
  • 2
  • 43
  • 45