Skip to content

Commit 5207440

Browse files
authored
Merge pull request #11328 from syntaxerror247/update-billing-doc-2
Update android in app purchases doc
2 parents 8ba30f1 + 7168e25 commit 5207440

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

tutorials/platform/android/android_in_app_purchases.rst

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@ Initialize the plugin
2121

2222
To use the ``GodotGooglePlayBilling`` API:
2323

24-
1. Access the ``BillingClient`` autoload singleton, it's automatically added when the plugin is enabled.
24+
1. Access the ``BillingClient``.
2525
2. Connect to its signals to receive billing results.
2626
3. Call ``start_connection``.
2727

2828
Initialization example:
2929

3030
::
3131

32+
var billing_client: BillingClient
3233
func _ready():
33-
BillingClient.connected.connect(_on_connected) # No params
34-
BillingClient.disconnected.connect(_on_disconnected) # No params
35-
BillingClient.connect_error.connect(_on_connect_error) # response_code: int, debug_message: String
36-
BillingClient.query_product_details_response.connect(_on_query_product_details_response) # response: Dictionary
37-
BillingClient.query_purchases_response.connect(_on_query_purchases_response) # response: Dictionary
38-
BillingClient.on_purchase_updated.connect(_on_purchase_updated) # response: Dictionary
39-
BillingClient.consume_purchase_response.connect(_on_consume_purchase_response) # response: Dictionary
40-
BillingClient.acknowledge_purchase_response.connect(_on_acknowledge_purchase_response) # response: Dictionary
41-
42-
BillingClient.start_connection()
34+
billing_client = BillingClient.new()
35+
billing_client.connected.connect(_on_connected) # No params
36+
billing_client.disconnected.connect(_on_disconnected) # No params
37+
billing_client.connect_error.connect(_on_connect_error) # response_code: int, debug_message: String
38+
billing_client.query_product_details_response.connect(_on_query_product_details_response) # response: Dictionary
39+
billing_client.query_purchases_response.connect(_on_query_purchases_response) # response: Dictionary
40+
billing_client.on_purchase_updated.connect(_on_purchase_updated) # response: Dictionary
41+
billing_client.consume_purchase_response.connect(_on_consume_purchase_response) # response: Dictionary
42+
billing_client.acknowledge_purchase_response.connect(_on_acknowledge_purchase_response) # response: Dictionary
43+
44+
billing_client.start_connection()
4345

4446
The API must be in a connected state prior to use. The ``connected`` signal is sent
4547
when the connection process succeeds. You can also use ``is_ready()`` to determine if the plugin
@@ -76,12 +78,12 @@ Example use of ``query_product_details()``:
7678
::
7779

7880
func _on_connected():
79-
BillingClient.query_product_details(["my_iap_item"], BillingClient.ProductType.INAPP) # BillingClient.ProductType.SUBS for subscriptions.
81+
billing_client.query_product_details(["my_iap_item"], BillingClient.ProductType.INAPP) # BillingClient.ProductType.SUBS for subscriptions.
8082

8183
func _on_query_product_details_response(query_result: Dictionary):
8284
if query_result.response_code == BillingClient.BillingResponseCode.OK:
8385
print("Product details query success")
84-
for available_product in query_result.result_array:
86+
for available_product in query_result.product_details:
8587
print(available_product)
8688
else:
8789
print("Product details query failed")
@@ -105,12 +107,12 @@ Example use of ``query_purchases()``:
105107
::
106108

107109
func _query_purchases():
108-
BillingClient.query_purchases(BillingClient.ProductType.INAPP) # Or BillingClient.ProductType.SUBS for subscriptions.
110+
billing_client.query_purchases(BillingClient.ProductType.INAPP) # Or BillingClient.ProductType.SUBS for subscriptions.
109111

110112
func _on_query_purchases_response(query_result: Dictionary):
111113
if query_result.response_code == BillingClient.BillingResponseCode.OK:
112114
print("Purchase query success")
113-
for purchase in query_result.result_array:
115+
for purchase in query_result.purchases:
114116
_process_purchase(purchase)
115117
else:
116118
print("Purchase query failed")
@@ -120,9 +122,8 @@ Example use of ``query_purchases()``:
120122
Purchase an item
121123
~~~~~~~~~~~~~~~~
122124

123-
To launch the billing flow for an item:
124-
- Use ``purchase()`` for in-app products, passing the product ID string.
125-
- Use ``purchase_subscription()`` for subscriptions, passing the product ID and base plan ID. You may also optionally provide an offer ID.
125+
To launch the billing flow for an item: Use ``purchase()`` for in-app products, passing the product ID string.
126+
Use ``purchase_subscription()`` for subscriptions, passing the product ID and base plan ID. You may also optionally provide an offer ID.
126127

127128
For both ``purchase()`` and ``purchase_subscription()``, you can optionally pass a boolean to indicate whether
128129
offers are `personallised <https://developer.android.com/google/play/billing/integrate#personalized-price>`_
@@ -136,7 +137,7 @@ Example use of ``purchase()``:
136137

137138
::
138139

139-
var result = BillingClient.purchase("my_iap_item")
140+
var result = billing_client.purchase("my_iap_item")
140141
if result.response_code == BillingClient.BillingResponseCode.OK:
141142
print("Billing flow launch success")
142143
else:
@@ -151,7 +152,7 @@ The result of the purchase will be sent through the ``on_purchases_updated`` sig
151152
func _on_purchases_updated(result: Dictionary):
152153
if result.response_code == BillingClient.BillingResponseCode.OK:
153154
print("Purchase update received")
154-
for purchase in result.result_array:
155+
for purchase in result.purchases:
155156
_process_purchase(purchase)
156157
else:
157158
print("Purchase update error")
@@ -229,7 +230,7 @@ Example use of ``consume_purchase()``:
229230
if "my_consumable_iap_item" in purchase.product_ids and purchase.purchase_state == BillingClient.PurchaseState.PURCHASED:
230231
# Add code to store payment so we can reconcile the purchase token
231232
# in the completion callback against the original purchase
232-
BillingClient.consume_purchase(purchase.purchase_token)
233+
billing_client.consume_purchase(purchase.purchase_token)
233234

234235
func _on_consume_purchase_response(result: Dictionary):
235236
if result.response_code == BillingClient.BillingResponseCode.OK:
@@ -265,7 +266,7 @@ Example use of ``acknowledge_purchase()``:
265266
not purchase.is_acknowledged:
266267
# Add code to store payment so we can reconcile the purchase token
267268
# in the completion callback against the original purchase
268-
BillingClient.acknowledge_purchase(purchase.purchase_token)
269+
billing_client.acknowledge_purchase(purchase.purchase_token)
269270

270271
func _on_acknowledge_purchase_response(result: Dictionary):
271272
if result.response_code == BillingClient.BillingResponseCode.OK:
@@ -342,6 +343,6 @@ Example use of ``update_subscription``:
342343

343344
::
344345

345-
BillingClient.update_subscription(_active_subscription_purchase.purchase_token, \
346+
billing_client.update_subscription(_active_subscription_purchase.purchase_token, \
346347
BillingClient.ReplacementMode.WITH_TIME_PRORATION, "new_sub_product_id", "base_plan_id")
347348

0 commit comments

Comments
 (0)