code-with-max / godot-google-play-iapp

AndroidIAPP is a plugin for the Godot 4.2+ game engine. It provides an interface to work with Google Play Billing Library version 7. The plugin supports all public functions of the library, passes all error codes, and can work with different subscription plans.
MIT License
45 stars 5 forks source link

How to Retrieve the Quantity of a Purchase #7

Open Shay-M opened 3 months ago

Shay-M commented 3 months ago

Hello, first of all, thank you very much for the plugin! I wanted to ask how I can get the amount of the purchase made? I tried purchase["quantity"] According to the example: https://github.com/code-with-max/godot-google-play-iapp/blob/master/examples/purchase_updated_inapp.json

but nothing is received

code-with-max commented 3 months ago

@Shay-M Hi! First you must turn on option "multi-quantity purchases" for product in Play Console settings. After users will have ability to buy more than one instance, uses standard purchase interface. On processing this purchase in parameter "quantity" you receive actual data.

Shay-M commented 3 months ago

@code-with-max Hii, Yes, I marked it and it still doesn't show image

Maybe I'm doing something wrong?


func process_purchase(purchase):
    for product in purchase["products"]:
        if (product in ITEM_ACKNOWLEDGED) or (product in SUBSCRIPTIONS):
            # Acknowledge the purchase
            if not purchase["is_acknowledged"]:
                print("Acknowledging: " + purchase["purchase_token"])
                billing.acknowledgePurchase(purchase["purchase_token"])

                # Here, process the use of the product in your game.

            else:
                print("Already acknowledged")
                # if not SceneManager.user_preferences.is_removing_ads: successful()

        elif product in ITEM_CONSUMATED:
            # Consume the purchase
            print("Consuming: " + purchase["purchase_token"])
            billing.consumePurchase(purchase["purchase_token"])

            GPrint.text("purchase: " + purchase["quantity"])  <<<<<<----
            successful()
            #
            # Here, process the use of the product in your game.
            #
        else:
            print("Product not found: " + str(product))
            purchase_error.emit("Product not found: " + str(product))
code-with-max commented 3 months ago

@Shay-M I'm sorry that I didn't answer for a long time. At first glance, everything looks fine, you don't need to change anything in the code, just billing will return you a quantity of more than one. Are there any errors in the logcat output?

Shay-M commented 3 months ago

@code-with-max Thank you for getting back to me.

Regarding the issue, there are no errors in the logcat output; however, there is no printout for the quantity.

for this :

Gprint.text("purchase: " + purchase["purchase_token"])
Gprint.text("purchase: " + purchase["quantity"])

I’m only receiving the purchase_token, but the line for purchase["quantity"] does not produce any output.

code-with-max commented 2 months ago

@Shay-M In the next version, I will try to implement a method that returns data received from Google directly without converting it. This will help you understand if there is information about the quantity in the original response from the server.

Shay-M commented 2 months ago

@code-with-max Okay, thanks!