+1 vote

I can successfully show the Google payment prompt and make a payment, but none of the purchase_success, purchase_fail, or purchase_cancel functions are called. What am I doing wrong?

extends Node

# class member variables go here, for example:
# var a = 2
# var b = "textvar"

var payment = null

func is_available():
    return payment!=null

func _ready():
    if Engine.has_singleton("GodotPayments"):
        payment = Engine.get_singleton("GodotPayments")
    if payment:
        DebugScreen.d("payments supported")
        DebugScreen.d("payments not supported")
    # Called every time the node is added to the scene.
    # Initialization here

func purchase(item_name):
    if payment:
        DebugScreen.d("purchase " + item_name)
        # transaction_id could be any string that used for validation internally in java
        payment.purchase(item_name, "transaction_id")
        DebugScreen.d("iap unavailable")

#func purchase_success(receipt, signature, sku):
#   DebugScreen.d("purchase_success : " + str(sku))
#   emit_signal("purchase_success", sku)

func purchase_fail():

func purchase_cancel():

func purchase_owned(sku):
    DebugScreen.d("purchase_owned : " + str( sku))
    #emit_signal("purchase_owned", sku)

#func _process(delta):
#   # Called every frame. Delta is time since last frame.
#   # Update game logic here.
#   pass
asked Apr 20, 2018 in Engine by aomimezura (20 points)

1 Answer

0 votes
Best answer

I finally figured it out. First of all, in _ready() I was calling payment.setPurchaseCallbackId(null). I replaced it with the line above it instead, payment.setPurchaseCallbackId(get_instance_ID()). Then I find out that is also wrong. The tutorial I read calls get_instance_ID() with CAPITAL letters for ID. It should be get_instance_id(), all lowercase. I found this out when I realized on Android, many errors are just simply ignored without crashing (somehow). With remote debugging on, it told me that the function did not exist. Now the payment callbacks are working properly.

answered Apr 25, 2018 by aomimezura (20 points)

it took very long days..., but the demo project for android iap is fixed now.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.