Skip to content

Commit c7cb5e2

Browse files
Chris YangEgor
Chris Yang
authored and
Egor
committed
[in_app_purchase] update docs to warn about completePurchase (flutter#2739)
1 parent 07adeca commit c7cb5e2

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

packages/in_app_purchase/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.3+1
2+
3+
* Update documentations for `InAppPurchase.completePurchase` and update README.
4+
15
## 0.3.3
26

37
* Introduce `SKPaymentQueueWrapper.transactions`.

packages/in_app_purchase/README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ once they're marked as consumed and fails to return them here. For restoring
120120
these across devices you'll need to persist them on your own server and query
121121
that as well.
122122

123+
### Listening to purchase updates
124+
125+
You should always start listening to purchase update as early as possible to be able
126+
to catch all purchase updates, including the ones from the previous app session.
127+
To listen to the update:
128+
129+
```dart
130+
Stream purchaseUpdated =
131+
InAppPurchaseConnection.instance.purchaseUpdatedStream;
132+
_subscription = purchaseUpdated.listen((purchaseDetailsList) {
133+
_listenToPurchaseUpdated(purchaseDetailsList);
134+
}, onDone: () {
135+
_subscription.cancel();
136+
}, onError: (error) {
137+
// handle error here.
138+
});
139+
```
140+
123141
### Making a purchase
124142

125143
Both storefronts handle consumable and non-consumable products differently. If
@@ -134,11 +152,19 @@ if (_isConsumable(productDetails)) {
134152
} else {
135153
InAppPurchaseConnection.instance.buyNonConsumable(purchaseParam: purchaseParam);
136154
}
137-
138155
// From here the purchase flow will be handled by the underlying storefront.
139156
// Updates will be delivered to the `InAppPurchaseConnection.instance.purchaseUpdatedStream`.
140157
```
141158

159+
### Complete a purchase
160+
161+
The `InAppPurchaseConnection.purchaseUpdatedStream` will send purchase updates after
162+
you initiate the purchase flow using `InAppPurchaseConnection.buyConsumable` or `InAppPurchaseConnection.buyNonConsumable`.
163+
After delivering the content to the user, you need to call `InAppPurchaseConnection.completePurchase` to tell the `GooglePlay`
164+
and `AppStore` that the purchase has been finished.
165+
166+
WARNING! Failure to call `InAppPurchaseConnection.completePurchase` and get a successful response within 3 days of the purchase will result a refund.
167+
142168
## Development
143169

144170
This plugin uses

packages/in_app_purchase/lib/src/in_app_purchase/in_app_purchase_connection.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ abstract class InAppPurchaseConnection {
109109
/// [PurchaseDetails.status] and update your UI accordingly. When the
110110
/// [PurchaseDetails.status] is [PurchaseStatus.purchased] or
111111
/// [PurchaseStatus.error], you should deliver the content or handle the
112-
/// error. On iOS, you also need to call [completePurchase] to finish the
113-
/// purchasing process.
112+
/// error, then call [completePurchase] to finish the purchasing process.
114113
///
115114
/// This method does return whether or not the purchase request was initially
116115
/// sent successfully.

packages/in_app_purchase/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: in_app_purchase
22
description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase
4-
version: 0.3.3
4+
version: 0.3.3+1
55

66
dependencies:
77
async: ^2.0.8

0 commit comments

Comments
 (0)