godot-sdk-integrations / godot-google-play-billing

Godot Android plugin for the Google Play Billing library
MIT License
147 stars 46 forks source link

querySkuDetails with product type inapp return no data (null) #42

Closed JUNZ1 closed 1 year ago

JUNZ1 commented 1 year ago

Hello I am currently trying to use plugin with godot 3.5.1, and see that there is no return for the items queried which are already defined in play console. My codes for the practising is below.

extends Node2D

var payment
var itemToken
func _ready():
    if Engine.has_singleton("GodotGooglePlayBilling"):
        print("Engine has Singleton")
        payment = Engine.get_singleton("GodotGooglePlayBilling")
        # These are all signals supported by the API
        # You can drop some of these based on your needs
        payment.connect("connected", self, "_on_connected") # No params
        payment.connect("disconnected", self, "_on_disconnected") # No params
        payment.connect("connect_error", self, "_on_connect_error") # Response ID (int), Debug message (string)
        payment.connect("purchases_updated", self, "_on_purchases_updated") # Purchases (Dictionary[])
        payment.connect("purchase_error", self, "_on_purchase_error") # Response ID (int), Debug message (string)
        payment.connect("product_details_query_completed", self, "_on_product_details_query_completed") # SKUs (Dictionary[])
        payment.connect("product_details_query_error", self, "_on_product_details_query_error") # Response ID (int), Debug message (string), Queried SKUs (string[])
        payment.connect("purchase_acknowledged", self, "_on_purchase_acknowledged") # Purchase token (string)
        payment.connect("purchase_acknowledgement_error", self, "_on_purchase_acknowledgement_error") # Response ID (int), Debug message (string), Purchase token (string)
        payment.connect("purchase_consumed", self, "_on_purchase_consumed") # Purchase token (string)
        payment.connect("purchase_consumption_error", self, "_on_purchase_consumption_error") # Response ID (int), Debug message (string), Purchase token (string)
        payment.startConnection()
    else:
        print("Android IAP support is not enabled. Make sure you have enabled 'Custom Build' and the GodotGooglePlayBilling plugin in your Android export settings! IAP will not work.")

func _on_PurchaseDemoItem_pressed():
    var response = payment.purchase("testsku")
    print("Purchase has been attempted, result is: " + response.debug_message)
    if response.status !=1:
        print("Error purchasing Item")

func _on_UseDemoItem_pressed():
    if itemToken == null: 
        print("You need to buy this item")
    else:
        print("Consuming item")
        payment.consumePurchase(itemToken)

func _on_connected():
    print("Connection is done")

func _on_disconnected():
    pass

func _on_connect_error(responseID, debugMsg):
    print("_on_connect_error" + str(responseID) + debugMsg)

func _on_purchases_updated(items):
    for item in items:
        if !item.is_acknowledged:
            print("acknowledge purchases: " + item.purchase_token)
            payment.acknowledgePurchase(item.purchase_token)
    if items.size() > 0:
        itemToken = items[items.size()-1].purchase_token

func _on_purchase_acknowledged(token):
    print("purchase was acknowledged: " + token)

func _on_purchase_consumed(token):
    print("purchase was consumed: " + token)

func _on_purchase_error(responseID, debugMsg):
    print("_on_purchase_error" + str(responseID) + debugMsg)

func _on_product_details_query_completed(details):
    print("query completed")
    print(details)

func _on_product_details_query_error(id, message, queriedSKU):
    print("query error")
    print(message)

func _on_purchase_acknowledgement_error(id, message, purchasedtoken):
    print("_on_purchase_acknowledgement_error")

func _on_purchase_consumption_error(id, message, token):
    print("_on_purchase_consumption_error")

func _on_QueryItemButton_pressed():
    var result = payment.querySkuDetails(["testsku"], "inapp") # "subs" for subscriptions
    print(result)
JUNZ1 commented 1 year ago

Problem no more occure, looks like time is needed

KoBeWi commented 1 year ago

I'm using version 2.0.0-rc.1 and I have the same problem. It's not fixed by time. I looked into the plugin code and found out the problem are ArrayLists. E.g. here: https://github.com/godotengine/godot-google-play-billing/blob/eeaf30911348fa0a1cb542c2b9490f93a71f3375/godot-google-play-billing/src/main/java/org/godotengine/godot/plugin/googleplaybilling/utils/GooglePlayBillingUtils.java#L105 You need to convert it to Object[] before putting to Dictionary.

Seems like it's fixed on master though.

NianoTT commented 1 year ago

Seems like it's fixed on master though.

master is still the old v1 from 2021, way behind the new 2.0.0 branch from #36 tho, unless I missed something?

The issue with subscriptions returning an empty dictonary on querySkuDetails() has been confirmed several times on Godot discord btw.

al-bezd commented 12 months ago

Я использую версию 2.0.0-rc.1, и у меня та же проблема. Это не исправлено временем. Я просмотрел код плагина и обнаружил, что проблема в ArrayLists. Например здесь:

https://github.com/godotengine/godot-google-play-billing/blob/eeaf30911348fa0a1cb542c2b9490f93a71f3375/godot-google-play-billing/src/main/java/org/godotengine/godot/plugin/googleplaybilling/utils/GooglePlayBillingUtils.java#L105

Вам необходимо преобразовать его в Object[] перед помещением в словарь. Хотя, похоже, это исправлено на мастере.

i have same problem

NianoTT commented 12 months ago

The current maintained version is by finepointcgi, you can get the release here: https://github.com/finepointcgi/godot-google-play-billing/releases/tag/1.1.2

It uses the same API as the legacy version thats documented in the Godot docs. I'd suggest using that version instead of 2.0.0-rc1, as it has this issue also solved.