mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2025-12-16 13:30:07 +01:00
Update Android IAP demo for v1.1 of PBL plugin
Minor update to reflect an API change in v1.1 of the Google Play Billing Library plugin. The queryPurchases function changed to be asyncronous, added a query_purchases_response callback to process the results. This change is dependent on the contents of: https://github.com/godotengine/godot-google-play-billing/pull/25
This commit is contained in:
@@ -35,6 +35,8 @@ func _ready():
|
||||
payment.connect("purchase_consumed", self, "_on_purchase_consumed")
|
||||
# Response ID (int), Debug message (string), Purchase token (string).
|
||||
payment.connect("purchase_consumption_error", self, "_on_purchase_consumption_error")
|
||||
# Purchases (Dictionary[])
|
||||
payment.connect("query_purchases_response", self, "_on_query_purchases_response")
|
||||
payment.startConnection()
|
||||
else:
|
||||
show_alert("Android IAP support is not enabled. Make sure you have enabled 'Custom Build' and installed and enabled the GodotGooglePlayBilling plugin in your Android export settings! This application will not work.")
|
||||
@@ -47,17 +49,21 @@ func show_alert(text):
|
||||
|
||||
func _on_connected():
|
||||
print("PurchaseManager connected")
|
||||
payment.queryPurchases("inapp") # Use "subs" for subscriptions.
|
||||
|
||||
# We must acknowledge all puchases.
|
||||
# See https://developer.android.com/google/play/billing/integrate#process for more information
|
||||
var query = payment.queryPurchases("inapp") # Use "subs" for subscriptions.
|
||||
if query.status == OK:
|
||||
for purchase in query.purchases:
|
||||
|
||||
func _on_query_purchases_response(query_result):
|
||||
if query_result.status == OK:
|
||||
for purchase in query_result.purchases:
|
||||
# We must acknowledge all puchases.
|
||||
# See https://developer.android.com/google/play/billing/integrate#process for more information
|
||||
if not purchase.is_acknowledged:
|
||||
print("Purchase " + str(purchase.sku) + " has not been acknowledged. Acknowledging...")
|
||||
payment.acknowledgePurchase(purchase.purchase_token)
|
||||
else:
|
||||
print("Purchase query failed: %d" % query.status)
|
||||
print("queryPurchases failed, response code: ",
|
||||
query_result.response_code,
|
||||
" debug message: ", query_result.debug_message)
|
||||
|
||||
|
||||
func _on_sku_details_query_completed(sku_details):
|
||||
|
||||
Reference in New Issue
Block a user