Core Methods
Core methods available on both iOS and Android platforms. All methods use typed parameters and return typed objects.
Setup
Add GodotIapWrapper as a child node in your scene, then reference it in your script:
extends Node
# Load OpenIAP types
const Types = preload("res://addons/godot-iap/types.gd")
# Reference to GodotIapWrapper node
@onready var iap = $GodotIapWrapper
# Throughout this documentation, we use `iap` to reference the wrapper.
# You can also use any variable name you prefer.
In the examples below, GodotIapPlugin refers to your reference to the GodotIapWrapper node.
Replace it with your own variable name (e.g., iap, $GodotIapWrapper, or IapManager if using an autoload).
Connection Methods
init_connection
Initialize the billing connection. Must be called before any other IAP operations.
func init_connection() -> bool
Returns: bool - true if connection successful
Example:
func _ready():
GodotIapPlugin.purchase_updated.connect(_on_purchase_updated)
GodotIapPlugin.purchase_error.connect(_on_purchase_error)
if GodotIapPlugin.init_connection():
print("IAP connection initialized")
_fetch_products()
end_connection
End the billing connection. Call when your app no longer needs IAP functionality.
func end_connection() -> Types.VoidResult
Returns: Types.VoidResult with success boolean
Example:
func _exit_tree():
var result = GodotIapPlugin.end_connection()
if result.success:
print("Connection ended")
Product Methods
fetch_products
Fetch product details from the store. Returns an array of typed product objects.
func fetch_products(request: Types.ProductRequest) -> Array
Parameters:
| Parameter | Type | Description |
|---|---|---|
request | Types.ProductRequest | Product request with SKUs and type |
Returns: Array of Types.ProductAndroid (Android) or Types.ProductIOS (iOS)
GDScript doesn't support Union types. The returned array contains either ProductAndroid or ProductIOS objects depending on the platform. Both share common properties like id, title, and display_price.
Example:
func _fetch_products():
var request = Types.ProductRequest.new()
request.skus = ["coins_100", "coins_500", "remove_ads"]
request.type = Types.ProductQueryType.ALL
var products = GodotIapPlugin.fetch_products(request)
for product in products:
# Access typed properties directly
print("Product: %s - %s" % [product.id, product.display_price])
print(" Title: %s" % product.title)
print(" Description: %s" % product.description)
Purchase Methods
request_purchase
Request a purchase for a product.
func request_purchase(props: Types.RequestPurchaseProps) -> Variant
Parameters:
| Parameter | Type | Description |
|---|---|---|
props | Types.RequestPurchaseProps | Purchase request with platform-specific options |
Returns: Variant - Types.PurchaseAndroid, Types.PurchaseIOS, or null
Example:
func purchase_product(product_id: String):
var props = Types.RequestPurchaseProps.new()
props.request = Types.RequestPurchasePropsByPlatforms.new()
# Android configuration
props.request.google = Types.RequestPurchaseAndroidProps.new()
props.request.google.skus = [product_id]
# iOS configuration
props.request.apple = Types.RequestPurchaseIosProps.new()
props.request.apple.sku = product_id
props.type = Types.ProductQueryType.IN_APP
var purchase = GodotIapPlugin.request_purchase(props)
if purchase:
print("Purchase initiated: ", purchase.product_id)
finish_transaction
Finish a transaction after processing. Must be called for every successful purchase.
func finish_transaction(purchase: Types.PurchaseInput, is_consumable: bool) -> Types.VoidResult
Parameters:
| Parameter | Type | Description |
|---|---|---|
purchase | Types.PurchaseInput | Purchase to finish |
is_consumable | bool | Whether the product is consumable |
Returns: Types.VoidResult
Example:
func _on_purchase_updated(purchase: Dictionary):
if purchase.get("purchaseState") == "Purchased":
# Verify on server first (recommended)
var verified = await verify_on_server(purchase)
if verified:
var purchase_input = Types.PurchaseInput.from_dict(purchase)
var is_consumable = _is_consumable_product(purchase.get("productId", ""))
var result = GodotIapPlugin.finish_transaction(purchase_input, is_consumable)
if result.success:
print("Transaction finished")
