code-with-max / godot-google-play-iapp

AndroidIAPP is a plugin for the Godot 4.2+ 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.
MIT License
45 stars 5 forks source link
addon godot google-play-billing inapp

AndroidIAPP Godot Plugin

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

Features

Installation

[!NOTE] Dont forget to enable the plugin in the project settings.

Examples

Before start

Signals Descriptions (Event listeners)

Test signal

Returns a String value.

helloResponse: Emitted when a response to a hello message is received.

Information signals

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.

Billing signals

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.

Functions

startConnection(): Starts the connection to Google Play Billing, emit signals:


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.


queryPurchases(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:


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:

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.

Emit signals:

[!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.

Emit signals:

[!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:


acknowledgePurchase(purchase["purchase_token"]): acknowledge a purchase from Google Play Billing.
purchase["purchase_token"]: Purchase token from purchase updated response.

Emit signals:


Step-by-step set up guide

Connecting to the Google Play Billing Library

Requesting a list of products and subscriptions

Handling purchases and subscriptions

Confirming and consuming purchases

Handling errors and purchase states