AndroidIAPP is a plugin for the Godot game engine. It provides an interface to work with Google Play Billing Library version 7. The plugin supports all public functions of the library, passes all error codes, and can work with different subscription plans.
A simple game to demonstrate the work of purchases and subscriptions with different tariff plans: Circle Сatcher 2
Install the plugin using Godot Asset Library.
or
Download the plugin from GitHub.
And place the unpacked plugin folder in the res://addons/
directory of the project.
[!NOTE] Dont forget to enable the plugin in the project settings.
Google Play Billing uses these three types of purchases:
And their IDs should be passed to the function as a list of String elements. Even if there is only one ID, it still needs to be wrapped in a list.
All public methods and values returned by Google Play Billing are presented as a typed Godot dictionary. All dictionary keys represent the names of public methods written in snake_case style.
product_id
subscription_offer_details
See the variant of response here
The plugin also includes all standard BillingResponseCode messages as a key in the dictionary called response_code
. Additionally, it adds a debug_message
key if the code indicates an error.
Returns a String value.
helloResponse
: Emitted when a response to a hello message is received.
Does not return anything.
startConnection
: Emitted when the connection to Google Play Billing starts.
connected
: Emitted when successfully connected to Google Play Billing.
disconnected
: Emitted when disconnected from Google Play Billing.
Returns a Dictionary of Godot type.
query_purchases
: Emitted when a query for purchases is successful.
Returns a dictionary with purchases or subscriptions.
query_purchases_error
: Emitted when there is an error querying purchases.
Returns a dictionary with error codes and debug message.
query_product_details
: Emitted when a query for product details is successful.
Returns a dictionary with product or subscription details.
query_product_details_error
: Emitted when there is an error querying product details.
Returns a dictionary with error codes and debug message.
purchase_error
: Emitted when there is an error during the purchase process.
Returns a dictionary with error codes and debug message.
purchase_updated
: Emitted when the purchase information is updated.
Returns a dictionary with purchases or subscriptions.
purchase_cancelled
: Emitted when a purchase is cancelled.
Returns a dictionary with error codes and debug message.
purchase_update_error
: Emitted when there is an error updating the purchase information.
Returns a dictionary with error codes and debug message.
purchase_consumed
: Emitted when a purchase is successfully consumed.
Returns a dictionary with confirmation message.
purchase_consumed_error
: Emitted when there is an error consuming the purchase.
Returns a dictionary with error codes and debug message.
purchase_acknowledged
: Emitted when a purchase is successfully acknowledged.
Returns a dictionary with confirmation message.
purchase_acknowledged_error
: Emitted when there is an error acknowledging the purchase.
Returns a dictionary with error codes and debug message.
startConnection()
: Starts the connection to Google Play Billing, emit signals:
startConnection
signal when connection is started.connected
signal if connection is successful. isReady()
: Checks if the connection to Google Play Billing is ready and returns a boolean value.
sayHello()
: Sends a hello message from the plugin.
For testing purposes, not recommended in production.
helloResponse
signalqueryPurchases(productType: String)
productType: "inapp" for products or "subs" for subscriptions.
Handling purchases made outside your app.
[!NOTE] I recommend calling it every time you establish a connection with the billing service.
Emit signals:
query_purchases
: if a query for purchases is successful. query_purchases_error
: if there is an error querying purchases.queryProductDetails(productId: List<String>, productType: String)
: This function queries product of subscriptions details from Google Play Billing.
productId
: ID of the product or subscription wrapped in a list.
productType
: "inapp" for products or "subs" for subscriptions.
[!NOTE] You must pass the product type as a parameter. If you pass the wrong product type with the product IDs, like using subscription IDs with "inapp", it won't work and the function will return an error.
Emit signals:
query_product_details
: If a query for product details is successful. query_product_details_error
: If error :)See an example of product details answer or subscription.
[!NOTE] This is where the biggest difference from the official plugin begins. If you have never used the old plugin before, you don't need to worry. But if you are planning to switch to this version, you should know that I have implemented two separate functions for buying products and subscribing to plans.
purchase(product_id: List<String>, is_personalized: bool)
: purchase a product from Google Play Billing.
product_id
: ID of the product wrapped in a list. is_personalized
: This is to ensure compliance with the EU directive, you can clarify this here, but if you don't understand why, just set it to false
. Emit signals:
purchase_updated
: Emitted when the purchase information is updated. The purchase process was successful. Example of responsequery_product_details_error
: If an error occurred while receiving information about the product being purchased. purchase_error
: If there is an error during the purchase process. purchase_cancelled
: If a purchase is cancelled by the user. purchase_update_error
: If there is an error updating the purchase information. [!IMPORTANT] Do not forget consume or acknowledge the purchase.
subscribe(subscription_id: List<String>, base_plan_id: List<String>, is_personalized: bool)
: subscribe to a subscription plan from Google Play Billing.
subscription_id
: ID of the subscription wrapped in a list. base_plan_id
: ID of the base subscription plan wrapped in a list. is_personalized
: This is to ensure compliance with the EU directive, you can clarify this here, but if you don't understand why, just set it to false
. Emit signals:
purchase_updated
: Emitted when the purchase information is updated. The purchase process was successful. query_product_details_error
: If an error occurred while receiving information about the subscription being purchased. purchase_error
: If there is an error during the purchase process. purchase_cancelled
: If a purchase is cancelled by the user. purchase_update_error
: If there is an error updating the purchase information. [!IMPORTANT] Do not forget acknowledge the subscription.
consumePurchase(purchase["purchase_token"]
: consume a purchase from Google Play Billing.
purchase["purchase_token"]
: Purchase token from purchase updated response.
Emit signals:
purchase_consumed
: If a purchase is successfully consumed. purchase_consumed_error
: If there is an error consuming the purchase.acknowledgePurchase(purchase["purchase_token"])
: acknowledge a purchase from Google Play Billing.
purchase["purchase_token"]
: Purchase token from purchase updated response.
Emit signals:
purchase_acknowledged
: If a purchase is successfully acknowledged. purchase_acknowledged_error
: If there is an error acknowledging the purchase.