Android Question GooglePlayBilling - Get Price Currency

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I was using the old Google Play Billing in the past (InAppBilling3) and was working fine and now Google requires me to upgrade to v4 or above.

I managed to get the new version to work with my app using GooglePlayBilling (v5.00) using the code below.

B4X:
Sub Initialize_Inapp_billing
    billing.Initialize("billing")
    Get_SKU_Item_Details
End Sub

Sub Get_SKU_Item_Details
    
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
    
    If Result.IsSuccess Then
        
        Dim sf As Object = billing.QuerySkuDetails("inapp", Array("sku1", "sku2", "sku3"))
        Wait For (sf) Billing_SkuQueryCompleted (Result As BillingResult, SkuDetails As List)
        
        For Each sk As SkuDetails In SkuDetails
            Log(sk.Title)
            Log(sk.Price)
            Log(sk.Sku)
            Log(sk.Description)
        Next
        
    End If
End Sub

However, how can I get the currency using the new GooglePlayBilling (v5.00) ?
 

hatzisn

Expert
Licensed User
Longtime User
The currency is on the sk.price in conjuction with the numerical value. For subscriptions see bellow.

Have a look at this thread (@Erel's Launchbilling sub for subscriptions) and also my solution in second URL:


 
Last edited:
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I am using in-app purchases and not subscriptions.

I did see those posts before I posted this thread, but couldn't get them to work and didn't think it would return the currency.

The currency is on the sk.price in conjuction with the numerical value.

When I log sk.price it just logs the price but doesn't tell you what currency it is.

In the past with GooglePlayBilling v3 I used to be able to get it like:
B4X:
Dim value As String = sk.toString
    value = value.SubString(11)
            
Dim parser As JSONParser
    parser.Initialize(value)
Dim root As Map = parser.NextObject
Dim price_currency_code As String = root.Get("price_currency_code")
But sk.toString doesn't exist anymore.

I can't seem to work it out.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
I am using in-app purchases and not subscriptions.

I did see those posts before I posted this thread, but couldn't get them to work and didn't think it would return the currency.



When I log sk.price it just logs the price but doesn't tell you what currency it is.

In the past with GooglePlayBilling v3 I used to be able to get it like:
B4X:
Dim value As String = sk.toString
    value = value.SubString(11)
          
Dim parser As JSONParser
    parser.Initialize(value)
Dim root As Map = parser.NextObject
Dim price_currency_code As String = root.Get("price_currency_code")
But sk.toString doesn't exist anymore.

I can't seem to work it out.

have you tried the following?

B4X:
Dim value As String = sk.As(String)
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
It shows a warning that the object converted to string.

1665189575509.png


I went along with it anyway and used the following code and it seem to work fine.

B4X:
Dim value As String = sk.As(String)
    value = value.SubString(44)
           
Dim parser As JSONParser
    parser.Initialize(value)
Dim jRoot As Map = parser.NextObject
Dim localizedIn As List = jRoot.Get("localizedIn")
    For Each collocalizedIn As String In localizedIn
    Next
Dim productId As String = jRoot.Get("productId")
Dim skuDetailsToken As String = jRoot.Get("skuDetailsToken")
Dim name As String = jRoot.Get("name")
Dim description As String = jRoot.Get("description")
Dim Type As String = jRoot.Get("type")
Dim title As String = jRoot.Get("title")
Dim oneTimePurchaseOfferDetails As Map = jRoot.Get("oneTimePurchaseOfferDetails")
Dim formattedPrice As String = oneTimePurchaseOfferDetails.Get("formattedPrice")
Dim priceAmountMicros As Int = oneTimePurchaseOfferDetails.Get("priceAmountMicros")
Dim priceCurrencyCode As String = oneTimePurchaseOfferDetails.Get("priceCurrencyCode")
           
Log(priceCurrencyCode)
 
Upvote 0
Top