GodotPaymentV3 IAP purchase callbacks not triggered (Godot 3.0.2)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By aomimezura

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")
		#payment.setPurchaseCallbackId(get_instance_ID())
		payment.setPurchaseCallbackId(null)
	else:
		DebugScreen.d("payments not supported")
	# Called every time the node is added to the scene.
	# Initialization here
	pass

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")
	else:
		DebugScreen.d("iap unavailable")

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

func purchase_fail():
	DebugScreen.d("purchase_fail")
	#emit_signal("purchase_fail")

func purchase_cancel():
	DebugScreen.d("purchase_cancel")
	#emit_signal("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
:bust_in_silhouette: Reply From: aomimezura

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.

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

volzhs | 2018-07-19 06:27