You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.0 KiB
Dart
60 lines
2.0 KiB
Dart
import 'package:sentry_flutter/sentry_flutter.dart';
|
|
|
|
import 'package:fluffychat/pangea/controllers/subscription_controller.dart';
|
|
import 'package:fluffychat/pangea/models/base_subscription_info.dart';
|
|
import 'package:fluffychat/pangea/repo/subscription_repo.dart';
|
|
|
|
class WebSubscriptionInfo extends SubscriptionInfo {
|
|
WebSubscriptionInfo({required super.pangeaController}) : super();
|
|
|
|
@override
|
|
Future<void> configure() async {
|
|
await setAppIds();
|
|
await setAllProducts();
|
|
await setCustomerInfo();
|
|
availableSubscriptions = allProducts!
|
|
.where((product) => product.appId == appIds!.currentAppId)
|
|
.toList();
|
|
availableSubscriptions.sort((a, b) => a.price.compareTo(b.price));
|
|
//@Gabby - temporary solution to add trial to list
|
|
if (currentSubscriptionId == null && !hasSubscribed) {
|
|
final id = availableSubscriptions[0].id;
|
|
final package = availableSubscriptions[0].package;
|
|
final duration = availableSubscriptions[0].duration;
|
|
availableSubscriptions.insert(
|
|
0,
|
|
SubscriptionDetails(
|
|
price: 0,
|
|
id: id,
|
|
duration: duration,
|
|
package: package,
|
|
periodType: 'trial',
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> setCustomerInfo() async {
|
|
if (currentSubscriptionId != null && currentSubscription != null) {
|
|
return;
|
|
}
|
|
final RCSubscriptionResponseModel currentSubscriptionInfo =
|
|
await SubscriptionRepo.getCurrentSubscriptionInfo(
|
|
pangeaController.matrixState.client.userID,
|
|
allProducts,
|
|
);
|
|
|
|
currentSubscriptionId = currentSubscriptionInfo.currentSubscriptionId;
|
|
currentSubscription = currentSubscriptionInfo.currentSubscription;
|
|
allEntitlements = currentSubscriptionInfo.allEntitlements ?? [];
|
|
expirationDate = currentSubscriptionInfo.expirationDate;
|
|
|
|
if (currentSubscriptionId != null && currentSubscription == null) {
|
|
Sentry.addBreadcrumb(
|
|
Breadcrumb(message: "mismatch of productIds and currentSubscriptionID"),
|
|
);
|
|
}
|
|
}
|
|
}
|