Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node2D
- var payment
- func _ready():
- $Camera2D.zoom = Vector2(0.91, 0.91)
- if DataManager.premiumPass == true:
- enable_premium()
- else:
- $Purchase/AnimationPlayer.play("idle")
- if Engine.has_singleton("InAppStore"): #This part works and prints "success"
- payment = Engine.get_singleton("InAppStore")
- var result = payment.request_product_info({ "product_ids": ["com.justjustin.galaxius.premiumpass"] })
- if result == OK:
- print_to_label("success")
- func _on_Purchase_pressed():
- purchase("purchase")
- func _on_Restore_pressed():
- purchase("restore")
- func purchase(item): #This function fails and prints '31'
- if item == "purchase":
- var result = payment.purchase({ 'product_id': "com.justjustin.galaxius.premiumpass" })
- if result == OK:
- print_to_label("Purchasing")
- return true
- else:
- print_to_label(result)
- func _on_Timer_timeout():
- check_events()
- func check_events():
- while payment.get_pending_event_count() > 0:
- var event = payment.pop_pending_event()
- if event.type == "purchase":
- if event.result == OK:
- show_success(event.product_id)
- $Timer.stop()
- else:
- print_to_label("error")
- func show_success(product_id):
- print_to_label(product_id)
- enable_premium()
- func enable_premium():
- DataManager.premiumPass = true
- $Purchase.disabled = true
- $Button.disabled = false
- $Purchase.text = "Thanks!"
- $Purchase/AnimationPlayer.play("RESET")
- print_to_label("premium activated")
- func _on_Button_pressed():
- SceneChanger.change_scene("res://Scenes/Main Menu.tscn", "fade")
- func print_to_label(text):
- $MessageLabel.text = text
- print(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement