Advertisement
Guest User

premiumpass.gd

a guest
Aug 7th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Node2D
  2.  
  3. var payment
  4.  
  5. func _ready():
  6.     $Camera2D.zoom = Vector2(0.91, 0.91)
  7.  
  8.     if DataManager.premiumPass == true:
  9.         enable_premium()
  10.     else:
  11.         $Purchase/AnimationPlayer.play("idle")
  12.        
  13.     if Engine.has_singleton("InAppStore"):  #This part works and prints "success"
  14.         payment = Engine.get_singleton("InAppStore")
  15.         var result = payment.request_product_info({ "product_ids": ["com.justjustin.galaxius.premiumpass"] })
  16.         if result == OK:
  17.             print_to_label("success")
  18.  
  19. func _on_Purchase_pressed():
  20.     purchase("purchase")
  21.  
  22. func _on_Restore_pressed():
  23.     purchase("restore")
  24.  
  25. func purchase(item): #This function fails and prints '31'
  26.     if item == "purchase":
  27.         var result = payment.purchase({ 'product_id': "com.justjustin.galaxius.premiumpass" })
  28.         if result == OK:
  29.             print_to_label("Purchasing")
  30.             return true
  31.         else:
  32.             print_to_label(result)
  33.        
  34. func _on_Timer_timeout():
  35.     check_events()
  36.  
  37. func check_events():
  38.     while payment.get_pending_event_count() > 0:
  39.         var event = payment.pop_pending_event()
  40.         if event.type == "purchase":
  41.             if event.result == OK:
  42.                 show_success(event.product_id)
  43.                 $Timer.stop()
  44.             else:
  45.                 print_to_label("error")
  46.  
  47. func show_success(product_id):
  48.     print_to_label(product_id)
  49.     enable_premium()
  50.  
  51. func enable_premium():
  52.     DataManager.premiumPass = true
  53.     $Purchase.disabled = true
  54.     $Button.disabled = false
  55.     $Purchase.text = "Thanks!"
  56.     $Purchase/AnimationPlayer.play("RESET")
  57.     print_to_label("premium activated")
  58.  
  59. func _on_Button_pressed():
  60.     SceneChanger.change_scene("res://Scenes/Main Menu.tscn", "fade")
  61.  
  62. func print_to_label(text):
  63.     $MessageLabel.text = text
  64.     print(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement