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

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

Query is returning null #2

Closed himaghnam closed 4 years ago

himaghnam commented 4 years ago

3.2.2 Godot windows10

payment.queryPurchases() is returning null. Although purchased_updated do return the info with token

timoschwarzer commented 4 years ago

Hi!

Can you post the code you're using to query purchases please?

himaghnam commented 4 years ago

IAP on purchase success it uses consume func

extends Node

var payment

signal query_completed
signal purchases_success
signal consume_success
signal buy_error

func _ready():
    if Engine.has_singleton("GodotGooglePlayBilling"):
        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("sku_details_query_completed", self, "_on_sku_details_query_completed") # SKUs (Dictionary[])
        payment.connect("sku_details_query_error", self, "_on_sku_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 purchase(item_name):
    if payment:
        # transaction_id could be any string that used for validation internally in java
        payment.purchase(item_name)
        print("purchased")

func _on_purchase_error():
    print("purchase error")
    emit_signal("buy_error")

func _on_purchases_updated(list):
    print(list)
    print("purchase updated")
    emit_signal("purchases_success")

func _on_consume_consumed():
    print("purchase consumed")
    emit_signal("consume_success")

func consume(item_name):
    var query = payment.queryPurchases()
    print(query)
    if query.status == OK:
        for purchase in query.purchases:
            if purchase.sku == String(item_name):
                if !purchase.is_acknowledged:
                    payment.consumePurchase(purchase.purchase_token)
# Check the _on_purchase_consumed callback and give the user what they bought

func _on_purchase_consumption_error():
    print("consume error")

var sku_details:Dictionary = {}

func _on_connected():
    payment.querySkuDetails(["2000", "5000","9000","15000"], "inapp") # "subs" for subscriptions

func _on_sku_details_query_completed(sku_details_result):
    emit_signal("query_completed")
    for i in sku_details_result.size():

        match sku_details_result[i].sku :
            "2000": sku_details["2000"] = sku_details_result[i]
            "5000":sku_details["5000"] = sku_details_result[i]
            "9000":sku_details["9000"] = sku_details_result[i]
            "15000":sku_details["15000"] = sku_details_result[i]
timoschwarzer commented 4 years ago

It appears that I made a mistake while writing the docs: queryPurchases also takes a parameter like querySkuDetails that has to be either "inapp" or "subs". Going to fix that...

timoschwarzer commented 4 years ago

Fixed with https://github.com/godotengine/godot-docs/pull/3738