mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
IAP Verify Fail: Report it to Sentry
Not as analytics. This should typically never be happening.
This commit is contained in:
40
lib/iap.dart
40
lib/iap.dart
@ -3,8 +3,11 @@ import 'dart:io' show Platform;
|
|||||||
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:in_app_purchase/in_app_purchase.dart';
|
import 'package:in_app_purchase/in_app_purchase.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
|
import 'package:gitjournal/analytics.dart';
|
||||||
import 'package:gitjournal/app.dart';
|
import 'package:gitjournal/app.dart';
|
||||||
|
import 'package:gitjournal/error_reporting.dart';
|
||||||
import 'package:gitjournal/settings.dart';
|
import 'package:gitjournal/settings.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
|
|
||||||
@ -74,10 +77,16 @@ class InAppPurchases {
|
|||||||
|
|
||||||
var response = await iapConn.queryPastPurchases();
|
var response = await iapConn.queryPastPurchases();
|
||||||
for (var purchase in response.pastPurchases) {
|
for (var purchase in response.pastPurchases) {
|
||||||
var dt = await getExpiryDate(
|
DateTime dt;
|
||||||
|
try {
|
||||||
|
dt = await getExpiryDate(
|
||||||
purchase.verificationData.serverVerificationData,
|
purchase.verificationData.serverVerificationData,
|
||||||
purchase.productID,
|
purchase.productID,
|
||||||
_isPurchase(purchase));
|
_isPurchase(purchase));
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
|
||||||
if (dt == null || !dt.isAfter(dtNow)) {
|
if (dt == null || !dt.isAfter(dtNow)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -110,7 +119,13 @@ Future<DateTime> getExpiryDate(
|
|||||||
"code": response.statusCode,
|
"code": response.statusCode,
|
||||||
"body": response.body,
|
"body": response.body,
|
||||||
});
|
});
|
||||||
return null;
|
throw IAPVerifyException(
|
||||||
|
code: response.statusCode,
|
||||||
|
body: response.body,
|
||||||
|
receipt: receipt,
|
||||||
|
sku: sku,
|
||||||
|
isPurchase: isPurchase,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i("IAP Verify body: ${response.body}");
|
Log.i("IAP Verify body: ${response.body}");
|
||||||
@ -156,3 +171,24 @@ bool _isPurchase(PurchaseDetails purchase) {
|
|||||||
var sku = purchase.productID;
|
var sku = purchase.productID;
|
||||||
return !sku.contains('monthly') && !sku.contains('_sub_');
|
return !sku.contains('monthly') && !sku.contains('_sub_');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class IAPVerifyException implements Exception {
|
||||||
|
final int code;
|
||||||
|
final String body;
|
||||||
|
final String receipt;
|
||||||
|
final String sku;
|
||||||
|
final bool isPurchase;
|
||||||
|
|
||||||
|
IAPVerifyException({
|
||||||
|
@required this.code,
|
||||||
|
@required this.body,
|
||||||
|
@required this.receipt,
|
||||||
|
@required this.sku,
|
||||||
|
@required this.isPurchase,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return "IAPVerifyException{code: $code, body: $body, receipt: $receipt, $sku: sku, isPurchase: $isPurchase}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -162,6 +162,7 @@ class _PurchaseWidgetState extends State<PurchaseWidget> {
|
|||||||
return;
|
return;
|
||||||
} else if (purchaseDetails.status == PurchaseStatus.purchased) {
|
} else if (purchaseDetails.status == PurchaseStatus.purchased) {
|
||||||
Log.i("Verifying purchase sub");
|
Log.i("Verifying purchase sub");
|
||||||
|
try {
|
||||||
var subStatus = await verifyPurchase(purchaseDetails);
|
var subStatus = await verifyPurchase(purchaseDetails);
|
||||||
if (subStatus.isPro) {
|
if (subStatus.isPro) {
|
||||||
_deliverProduct(subStatus);
|
_deliverProduct(subStatus);
|
||||||
@ -169,6 +170,9 @@ class _PurchaseWidgetState extends State<PurchaseWidget> {
|
|||||||
_handleError("Failed to purchase product");
|
_handleError("Failed to purchase product");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
_handleError(err.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (purchaseDetails.pendingCompletePurchase) {
|
if (purchaseDetails.pendingCompletePurchase) {
|
||||||
Log.i("Pending Complete Purchase - ${purchaseDetails.productID}");
|
Log.i("Pending Complete Purchase - ${purchaseDetails.productID}");
|
||||||
|
Reference in New Issue
Block a user