Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions packages/in_app_purchase/in_app_purchase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,55 @@ InAppPurchase.instance
.buyNonConsumable(purchaseParam: purchaseParam);
```

### Confirming subscription price changes

When you change the price of a subscription the user will need to confirm the price change. If the user does not
confirm the price change the subscription will not be auto-renewed. On both iOS and Android the user will
automatically get a popup to confirm the price change, but you as a developer can show the popup on a moment that
suits you better. This works different on the Apple App Store and on the Google Play Store.

#### Google Play Store (Android)
When you raise the subscription price you will have 7 days to ask the user to approve the new price. The official
documentation can be found [here](https://support.google.com/googleplay/android-developer/answer/140504?hl=en#zippy=%2Cprice-changes).
When you lower the price the user will automatically receive the lower price and does not have to approve the price
change.

After 7 days the user will be notified through email and notifications on Google Play to agree with the new price,
so you have 7 days to explain the user in your app that the price is going to change and ask them to accept the
change. You will have to keep track of whether or not the price change is already accepted in your app or in the
backend. The [Google Play API](https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptions)
can be used to check whether or not the price change is accepted by the user by reading the priceChange property on
a subscription object.

The InAppPurchaseAndroidPlatformAddition can be used to show the price change confirmation flow. The additions
contain the function `launchPriceChangeConfirmationFlow` which needs the sku code of the subscription.

```dart
//import for InAppPurchaseAndroidPlatformAddition
import 'package:in_app_purchase_android/in_app_purchase_android.dart';
//import for BillingResponse
import 'package:in_app_purchase_android/billing_client_wrappers.dart';

if (Platform.isAndroid) {
final InAppPurchaseAndroidPlatformAddition androidAddition =
_inAppPurchase
.getPlatformAddition<InAppPurchaseAndroidPlatformAddition>();
var priceChangeConfirmationResult =
await androidAddition.launchPriceChangeConfirmationFlow(
sku: 'purchaseId',
);
if (priceChangeConfirmationResult.responseCode == BillingResponse.ok){
// TODO acknowledge price change
}else{
// TODO show error
}
}
```

#### Apple App Store (iOS)

//TODO

### Accessing platform specific product or purchase properties

The function `_inAppPurchase.queryProductDetails(productIds);` provides a `ProductDetailsResponse` with a
Expand Down
20 changes: 20 additions & 0 deletions packages/in_app_purchase/in_app_purchase/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,26 @@ class _MyAppState extends State<_MyApp> {
});
}

Future<void> confirmPriceChange() async {
if (Platform.isAndroid) {
final InAppPurchaseAndroidPlatformAddition androidAddition =
_inAppPurchase
.getPlatformAddition<InAppPurchaseAndroidPlatformAddition>();
var priceChangeConfirmationResult =
await androidAddition.launchPriceChangeConfirmationFlow(
sku: 'purchaseId',
);
if (priceChangeConfirmationResult.responseCode == BillingResponse.ok) {
// TODO acknowledge price change
} else {
// TODO show error
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvanbeusekom I'm not sure what to do here. Should I just add a print statement, leave these todo's or do you have an idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can simply show a snackbar message confirming the price change or showing the error?

}
if(Platform.isIOS){
//TODO setup flow
}
}

GooglePlayPurchaseDetails? _getOldSubscription(
ProductDetails productDetails, Map<String, PurchaseDetails> purchases) {
// This is just to demonstrate a subscription upgrade or downgrade.
Expand Down
2 changes: 1 addition & 1 deletion packages/in_app_purchase/in_app_purchase/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies:
flutter:
sdk: flutter
in_app_purchase_platform_interface: ^1.0.0
in_app_purchase_android: ^0.1.0
in_app_purchase_android: ^0.1.4
in_app_purchase_ios: ^0.1.0

dev_dependencies:
Expand Down