Migrate to third party library for IAP
This commit is contained in:
parent
26a498883a
commit
f320d00ef8
6 changed files with 80 additions and 73 deletions
|
@ -15,6 +15,8 @@ PODS:
|
|||
- Flutter
|
||||
- Mantle
|
||||
- SDWebImageWebPCoder
|
||||
- flutter_inapp_purchase (0.0.1):
|
||||
- Flutter
|
||||
- flutter_inappwebview (0.0.1):
|
||||
- Flutter
|
||||
- flutter_keyboard_visibility (0.0.1):
|
||||
|
@ -83,6 +85,7 @@ DEPENDENCIES:
|
|||
- Flutter (from `Flutter`)
|
||||
- flutter_email_sender (from `.symlinks/plugins/flutter_email_sender/ios`)
|
||||
- flutter_image_compress (from `.symlinks/plugins/flutter_image_compress/ios`)
|
||||
- flutter_inapp_purchase (from `.symlinks/plugins/flutter_inapp_purchase/ios`)
|
||||
- flutter_inappwebview (from `.symlinks/plugins/flutter_inappwebview/ios`)
|
||||
- flutter_keyboard_visibility (from `.symlinks/plugins/flutter_keyboard_visibility/ios`)
|
||||
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
|
||||
|
@ -127,6 +130,8 @@ EXTERNAL SOURCES:
|
|||
:path: ".symlinks/plugins/flutter_email_sender/ios"
|
||||
flutter_image_compress:
|
||||
:path: ".symlinks/plugins/flutter_image_compress/ios"
|
||||
flutter_inapp_purchase:
|
||||
:path: ".symlinks/plugins/flutter_inapp_purchase/ios"
|
||||
flutter_inappwebview:
|
||||
:path: ".symlinks/plugins/flutter_inappwebview/ios"
|
||||
flutter_keyboard_visibility:
|
||||
|
@ -172,6 +177,7 @@ SPEC CHECKSUMS:
|
|||
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
|
||||
flutter_email_sender: f787522d0e82f50e5766c1213dbffff22fdcf009
|
||||
flutter_image_compress: 082f8daaf6c1b0c9fe798251c750ef0ecd98d7ae
|
||||
flutter_inapp_purchase: 5c6a1ac3f11b11d0c8c0321c0c41c1f05805e4c8
|
||||
flutter_inappwebview: 69dfbac46157b336ffbec19ca6dfd4638c7bf189
|
||||
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
|
||||
flutter_secure_storage: 7953c38a04c3fdbb00571bcd87d8e3b5ceb9daec
|
||||
|
|
|
@ -245,6 +245,7 @@
|
|||
"${BUILT_PRODUCTS_DIR}/device_info/device_info.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/flutter_email_sender/flutter_email_sender.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/flutter_image_compress/flutter_image_compress.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/flutter_inapp_purchase/flutter_inapp_purchase.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/flutter_inappwebview/flutter_inappwebview.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/flutter_keyboard_visibility/flutter_keyboard_visibility.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/flutter_secure_storage/flutter_secure_storage.framework",
|
||||
|
@ -280,6 +281,7 @@
|
|||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/device_info.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_email_sender.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_image_compress.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_inapp_purchase.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_inappwebview.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_keyboard_visibility.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_secure_storage.framework",
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:in_app_purchase/in_app_purchase.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/network.dart';
|
||||
|
@ -26,24 +27,21 @@ class BillingService {
|
|||
|
||||
Future<void> init() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
InAppPurchaseConnection.instance.purchaseUpdatedStream
|
||||
.listen((event) async {
|
||||
await FlutterInappPurchase.instance.initConnection;
|
||||
if (kDebugMode) {
|
||||
FlutterInappPurchase.instance.clearTransactionIOS();
|
||||
}
|
||||
FlutterInappPurchase.purchaseUpdated.listen((item) {
|
||||
if (_isOnSubscriptionPage) {
|
||||
return;
|
||||
}
|
||||
for (final e in event) {
|
||||
if (e.status == PurchaseStatus.purchased) {
|
||||
verifySubscription(
|
||||
e.productID, e.verificationData.serverVerificationData)
|
||||
.then((response) {
|
||||
if (response != null) {
|
||||
InAppPurchaseConnection.instance.completePurchase(e);
|
||||
}
|
||||
});
|
||||
} else if (Platform.isIOS && e.pendingCompletePurchase) {
|
||||
InAppPurchaseConnection.instance.completePurchase(e);
|
||||
verifySubscription(item.productId,
|
||||
Platform.isAndroid ? item.purchaseToken : item.transactionReceipt)
|
||||
.then((response) {
|
||||
if (response != null) {
|
||||
FlutterInappPurchase.instance.finishTransaction(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
if (_config.hasConfiguredAccount() && !hasActiveSubscription()) {
|
||||
fetchSubscription();
|
||||
|
|
|
@ -4,8 +4,8 @@ import 'dart:io';
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:in_app_purchase/in_app_purchase.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/events/user_authenticated_event.dart';
|
||||
|
@ -28,51 +28,45 @@ class _SubscriptionPageState extends State<SubscriptionPage> {
|
|||
@override
|
||||
void initState() {
|
||||
BillingService.instance.setIsOnSubscriptionPage(true);
|
||||
_purchaseUpdateSubscription = InAppPurchaseConnection
|
||||
.instance.purchaseUpdatedStream
|
||||
.listen((event) async {
|
||||
for (final e in event) {
|
||||
if (e.status == PurchaseStatus.purchased) {
|
||||
final dialog = createProgressDialog(context, "verifying purchase...");
|
||||
await dialog.show();
|
||||
try {
|
||||
await BillingService.instance.verifySubscription(
|
||||
e.productID, e.verificationData.serverVerificationData);
|
||||
} catch (e) {
|
||||
_logger.warning("Could not complete payment ", e);
|
||||
await dialog.hide();
|
||||
showErrorDialog(
|
||||
context,
|
||||
"payment failed",
|
||||
"please talk to " +
|
||||
(Platform.isAndroid ? "PlayStore" : "AppStore") +
|
||||
" support if you were charged");
|
||||
return;
|
||||
}
|
||||
await InAppPurchaseConnection.instance.completePurchase(e);
|
||||
Bus.instance.fire(UserAuthenticatedEvent());
|
||||
await dialog.hide();
|
||||
AlertDialog alert = AlertDialog(
|
||||
title: Text("thank you"),
|
||||
content: Text("your photos and videos will now be backed up"),
|
||||
actions: [
|
||||
FlatButton(
|
||||
child: Text("ok"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
} else if (Platform.isIOS && e.pendingCompletePurchase) {
|
||||
await InAppPurchaseConnection.instance.completePurchase(e);
|
||||
}
|
||||
|
||||
_purchaseUpdateSubscription =
|
||||
FlutterInappPurchase.purchaseUpdated.listen((item) async {
|
||||
final dialog = createProgressDialog(context, "verifying purchase...");
|
||||
await dialog.show();
|
||||
try {
|
||||
await BillingService.instance.verifySubscription(item.productId,
|
||||
Platform.isAndroid ? item.purchaseToken : item.transactionReceipt);
|
||||
await FlutterInappPurchase.instance.finishTransaction(item);
|
||||
await dialog.hide();
|
||||
Bus.instance.fire(UserAuthenticatedEvent());
|
||||
AlertDialog alert = AlertDialog(
|
||||
title: Text("thank you"),
|
||||
content: Text("your photos and videos will now be backed up"),
|
||||
actions: [
|
||||
FlatButton(
|
||||
child: Text("ok"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
_logger.warning("Could not complete payment ", e);
|
||||
await dialog.hide();
|
||||
showErrorDialog(
|
||||
context,
|
||||
"payment failed",
|
||||
"please talk to " +
|
||||
(Platform.isAndroid ? "PlayStore" : "AppStore") +
|
||||
" support if you were charged");
|
||||
return;
|
||||
}
|
||||
});
|
||||
super.initState();
|
||||
|
@ -121,23 +115,22 @@ class _SubscriptionPageState extends State<SubscriptionPage> {
|
|||
onTap: () async {
|
||||
final dialog = createProgressDialog(context, "please wait...");
|
||||
await dialog.show();
|
||||
// ignore: sdk_version_set_literal
|
||||
Set<String> _kIds = {
|
||||
List<String> _kIds = [
|
||||
Platform.isAndroid ? plan.androidID : plan.iosID
|
||||
};
|
||||
final ProductDetailsResponse response =
|
||||
await InAppPurchaseConnection.instance
|
||||
.queryProductDetails(_kIds);
|
||||
if (response.notFoundIDs.isNotEmpty) {
|
||||
];
|
||||
final items =
|
||||
await FlutterInappPurchase.instance.getProducts(_kIds);
|
||||
if (items.isEmpty) {
|
||||
await dialog.hide();
|
||||
showGenericErrorDialog(context);
|
||||
return;
|
||||
}
|
||||
List<ProductDetails> productDetails = response.productDetails;
|
||||
final PurchaseParam purchaseParam =
|
||||
PurchaseParam(productDetails: productDetails[0]);
|
||||
await InAppPurchaseConnection.instance
|
||||
.buyNonConsumable(purchaseParam: purchaseParam);
|
||||
FlutterInappPurchase.purchaseError.listen((event) async {
|
||||
_logger.info("Purchase error: " + event.toString());
|
||||
await dialog.hide();
|
||||
});
|
||||
await FlutterInappPurchase.instance
|
||||
.requestSubscription(items[0].productId);
|
||||
await dialog.hide();
|
||||
},
|
||||
child: SubscriptionPlanWidget(plan: plan),
|
||||
|
|
|
@ -251,6 +251,13 @@ packages:
|
|||
relative: true
|
||||
source: path
|
||||
version: "0.7.0"
|
||||
flutter_inapp_purchase:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_inapp_purchase
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
flutter_inappwebview:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
@ -72,6 +72,7 @@ dependencies:
|
|||
flutter_password_strength: ^0.1.4
|
||||
flutter_inappwebview: ^4.0.0+4
|
||||
background_fetch: ^0.5.1
|
||||
flutter_inapp_purchase: ^3.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Add table
Reference in a new issue