Skip to content

Methods🔗

This page documents all available methods of the BillingClient class.


acknowledge_purchase🔗

func acknowledge_purchase(purchase_token: String)

Acknowledges in-app purchases.

All purchases require acknowledgement. Failure to acknowledge a purchase will result in that purchase being refunded.

Consumable purchases do not need to be acknowledged manually because calling consume_purchase(...) already acknowledges them.

Parameter Description
purchase_token Token identifying the purchase to acknowledge. This value is provided in purchase data returned by on_purchase_updated or query_purchases_response.

Emits the acknowledge_purchase_response signal.


consume_purchase🔗

func consume_purchase(purchase_token: String)

Consumes a given in-app product.

Consumable products can be purchased multiple times. Consuming the purchase removes it from the user's owned purchases so it can be bought again.

Calling this method automatically acknowledges the purchase.

Parameter Description
purchase_token Token identifying the purchase to consume. This token is included in purchase data received from on_purchase_updated or query_purchases_response.

Emits the consume_purchase_response signal.


end_connection🔗

func end_connection() -> void

Ends the connection to the Google Play Billing service.

Once closed, the client should not be used again.

Emits the disconnected signal.


get_connection_state🔗

func get_connection_state() -> int

Returns the current connection state of the billing client.

Returns an int representing a value from ConnectionState.

Example

var state = billing_client.get_connection_state()

if state == BillingClient.ConnectionState.CONNECTED:
    print("Billing ready")

is_ready🔗

func is_ready() -> bool

Returns true if the billing client is connected and ready for use.


open_subscriptions_page🔗

func open_subscriptions_page(product_id: String = "")

Opens the Google Play subscription management page.

Parameter Description
product_id Optional subscription product ID. If provided, Google Play will open the management page for that specific subscription.

Example

billing_client.open_subscriptions_page("my_subscription_product_id")

purchase🔗

func purchase(product_id: String, purchase_option_id: String = "", offer_id: String = "", is_offer_personalized: bool = false) -> Dictionary

Starts the purchase flow for an in-app product.

Note

The product must first be fetched using query_product_details(...) before attempting to purchase.

Parameter Description
product_id Identifier of the in-app product configured in the Google Play Console.
purchase_option_id Optional purchase option identifier returned from query_product_details_response. Used when the product have multiple purchase options, created in Google Play Console.
offer_id Optional offer identifier associated with the selected purchase option.
is_offer_personalized Indicates whether the price is personalized for the user.

Returns a Dictionary describing whether the billing flow launched successfully.

Final purchase results are delivered through the on_purchase_updated signal.

Example

billing_client.purchase("coins_100", premium_purchase_id, new_login_offer_id)

# billing_client.purchase("coins_100")

purchase_subscription🔗

func purchase_subscription(product_id: String, base_plan_id: String, offer_id: String = "", is_offer_personalized: bool = false) -> Dictionary

Starts the purchase flow for a subscription product.

Note

The product must first be fetched using query_product_details(...) before attempting to purchase.

Subscriptions require both a product ID and a base plan ID configured in the Play Console.

Parameter Description
product_id Subscription product identifier defined in Google Play Console.
base_plan_id Base plan ID configured for the subscription.
offer_id Optional offer ID defined under the base plan.
is_offer_personalized Indicates whether the price is personalized for the user.

Returns a Dictionary describing whether the billing flow launched successfully.

Final purchase results are delivered through the on_purchase_updated signal.


query_product_details🔗

func query_product_details(product_list: PackedStringArray, product_type: ProductType)

Queries product information.

This must be called before attempting to purchase products.

Parameter Description
product_list List of product IDs configured in Google Play Console.
product_type ProductType enum value indicating the product type being queried.

Emits the query_product_details_response signal.

Example

var product_ids = ["coins_100", "premium_potion"]
billing_client.query_product_details(products_ids, BillingClient.ProductType.INAPP)

query_purchases🔗

func query_purchases(product_type: ProductType, include_suspended_subs: bool = false)

Queries the user's currently owned purchases.

By default, this returns active subscriptions and unconsumed in-app purchases.

Parameter Description
product_type ProductType enum value indicating the product type being queried.
include_suspended_subs If true, suspended subscriptions will also be included in the results.

Info

Suspended subscriptions are still associated with the user but are not active. This can happen if the user paused the subscription or if the renewal payment method was declined.

The Purchase dictionary will contain is_suspended = true for suspended subscriptions.

When a subscription is suspended, you should not grant access to the subscription benefits. Instead, guide the user to the subscription management page using open_subscriptions_page() so they can update their payment method or resume the subscription.

Emits the query_purchases_response signal.

Example

billing_client.query_purchases(BillingClient.ProductType.INAPP)

billing_client.query_purchases(BillingClient.ProductType.SUBS, true)

set_obfuscated_account_id🔗

func set_obfuscated_account_id(account_id: String)

Sets an obfuscated account identifier for the current user.

Helps Google Play detect fraud and associate purchases with the correct user account.

Parameter Description
account_id Obfuscated identifier representing the user's account in your system.

Info

See the official Google Play Billing API reference: setObfuscatedAccountId.


set_obfuscated_profile_id🔗

func set_obfuscated_profile_id(profile_id: String)

Sets an obfuscated profile identifier.

Useful if your application supports multiple profiles under one account.

Parameter Description
profile_id Obfuscated identifier representing the user's profile.

Info

See the official Google Play Billing API reference: setObfuscatedProfileId.


start_connection🔗

func start_connection() -> void

Starts the connection to the Google Play Billing service.

The client must be connected before using any billing features.

Connection results are delivered through:


update_subscription🔗

func update_subscription(old_product_id: String, old_purchase_token: String, replacement_mode: ReplacementMode, new_product_id: String, base_plan_id: String, offer_id: String = "", is_offer_personalized: bool = false) -> Dictionary

Updates an existing subscription to a new subscription product or plan.

Parameter Description
old_purchase_token Purchase token of the currently active subscription. This token is returned in purchase data from query_purchases_response.
replacement_mode ReplacementMode enum value to define how the subscription replacement should behave.
new_product_id Product ID of the subscription to switch to.
base_plan_id Base plan ID of the new subscription.
offer_id Optional offer ID configured under the base plan.
is_offer_personalized Indicates whether the price is personalized for the user.

Returns a Dictionary describing whether the update flow launched successfully.

Emits the on_purchase_updated signal.

Example

billing_client.update_subscription("monthly_adfree_sub", old_purchase_token, BillingClient.ReplacementMode.CHARGE_PRORATED_PRICE, "premium_sub", "monthly")