Android Question sku details price and price currency code

DonManfred

Expert
Licensed User
Longtime User
somethink like

B4X:
Dim jo As JavaObject = PurchaseItem
Dim raw As String = jo.RunMethod("getOriginalJson", null)
Dim parser As JSONParser
parser.Initialize(raw)
Dim root As Map = parser.NextObject
Dim productId As String = root.Get("productId")
Dim price As String = root.Get("price")
Dim description As String = root.Get("description")
Dim title As String = root.Get("title")
Dim mtype As String = root.Get("type")
Dim price_amount_micros As Int = root.Get("price_amount_micros")
Dim price_currency_code As String = root.Get("price_currency_code")
 
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
somethink like

B4X:
Dim jo As JavaObject = PurchaseItem
Dim raw As String = jo.RunMethod("getOriginalJson", null)
Dim parser As JSONParser
parser.Initialize(raw)
Dim root As Map = parser.NextObject
Dim productId As String = root.Get("productId")
Dim price As String = root.Get("price")
Dim description As String = root.Get("description")
Dim title As String = root.Get("title")
Dim mtype As String = root.Get("type")
Dim price_amount_micros As Int = root.Get("price_amount_micros")
Dim price_currency_code As String = root.Get("price_currency_code")

Hi DonMafred,

Thank you for your reply. unfortunately there is no price and price_currency_code in the json obtained by the purchase item. You get the price in the internal logs when the product information is obtained but not in the purchase item.

Best,
SK
 
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
Hi Erel,

Since the sku full details that includes price and currency is posted in the internal logs, is there any way the method can be exposed to access all the details. OriginalJson method only retrieves partial data. It would be great to access the price and price types since there are multiple currency transactions and getting the details means one can upload such information to the server immediately when the transaction happens and not wait for google play records to refresh.

Sometimes google play takes days to update the revenue count that's is the reason I am asking.

Best,
SK
 
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
Hi Erel,

below are the logs.

B4X:
Sku is owned: test_monthly
Continuation token: null
Querying SKU details.
Got sku details: SkuDetails:{"productId":"test_monthly","type":"subs","price":"$2.99","price_amount_micros":2990000,"price_currency_code":"USD","title":"test monthly","description":"test monthly"}
Ending async operation: refresh inventory

Best,
SK
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've sent you an email with an updated version (v1.15).
Please try it with code similar to:
B4X:
Sub BillingManager_OwnedProducts (Success As Boolean, Purchases As Map)
   If Success Then
     Dim skus As JavaObject = billingManager 
     Dim items As List = skus.GetField("SkuDetails")
     For Each sku As JavaObject In items
       Log(sku.RunMethod("getSku", Null))
       Log(sku.RunMethod("getPrice", Null))
       Log(sku.RunMethod("getTitle", Null))
       Log(sku.RunMethod("getDescription", Null))
     Next
   End If
End Sub
 
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
Hi Erel,

Getting the below error. I tried to use map or object but it didnt work.

B4X:
Dim items As List = skus.GetField("SkuDetails")
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.List cannot be cast to java.util.List

Best,
SK
 
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
Hi Erel,

It is working :) but how do you get price_currency_code and price_amount_micros. the get method is not working

Best,
SK
 
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
Hi Erel,

Yes, it is printed.

B4X:
sku SkuDetails:{"productId":"test_monthly","type":"subs","price":"$2.99","price_amount_micros":2990000,"price_currency_code":"USD","title":"test monthly (test)","description":"test monthly"}

Best,
SK
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
does NOT work for you?
It will not work as there are no such methods in the library.

You will need to remove the prefix and parse it with a json parser.

B4X:
Dim s As String = sku
Dim i As Int = s.IndexOf(":")
s = s.Substring(i + 1)
You can use this tool to help you with the parsing code: https://b4x.com:51041/json/index.html
 
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
Hi Erel,

The new Inapp billing jar you sent, the purchase_completed sub is not called after purchasing a product. Also when I call manager.getownedproducts the second time I am getting the below error.

B4X:
starter_request_owned_products (B4A line: 579)
manager.GetOwnedProducts
java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4a.objects.IbHelper.queryInventoryAsync(anywheresoftware.b4a.objects.IbHelper$QueryInventoryFinishedListener)' on a null object reference
    at anywheresoftware.b4a.inappbilling3.BillingManager3.GetOwnedProducts(BillingManager3.java:89)
    at starter._request_owned_products(starter.java:975)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:897)
    at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:831)
    at main._sercheck_user_bytestoobject(main.java:5310)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA$2.run(BA.java:328)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7229)
    at java.lang.reflect.Method.invoke(Native Method)

Best,
SK
 
Last edited:
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
Hi Erel,

The issue was I was calling the manager in starter service. Once i moved it to the main activity everything worked fine. Since manager_OwnedProducts was called inthe service I thought the purchase would also be called but It did not.

Best,
SK
 
Upvote 0
Top