From e812729389066a273722c3fbcff5d0101cfb491e Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Sat, 28 Sep 2024 19:34:34 +0200 Subject: [PATCH 01/10] removed urls --- lib/pangea/network/urls.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/pangea/network/urls.dart b/lib/pangea/network/urls.dart index ff0404947..cc0e5dc41 100644 --- a/lib/pangea/network/urls.dart +++ b/lib/pangea/network/urls.dart @@ -15,10 +15,12 @@ class PApiUrls { static String getLanguages = "/languages"; /// ---------------------- Users -------------------------------------- - static String createUser = "/account/create"; + static String paymentLink = "/account/payment_link"; static String userDetails = "/account/get_user_access_token?pangea_user_id="; + + // USED ?? + static String createUser = "/account/create"; static String updateUserProfile = "/account/update"; - static String paymentLink = "/account/payment_link"; static String subscriptionExpiration = "/account/premium_expires_date"; /// ---------------------- Conversation Partner ------------------------- From 8c4619dfdcba22488bf208c0b55df16728172ca8 Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Tue, 3 Sep 2024 12:53:05 +0200 Subject: [PATCH 02/10] moved revenuecat --- lib/pangea/models/base_subscription_info.dart | 8 +-- lib/pangea/models/mobile_subscriptions.dart | 5 +- lib/pangea/models/web_subscriptions.dart | 5 +- lib/pangea/network/urls.dart | 14 ++-- lib/pangea/repo/subscription_repo.dart | 71 ++++++++++--------- lib/pangea/utils/subscription_app_id.dart | 23 ++---- 6 files changed, 58 insertions(+), 68 deletions(-) diff --git a/lib/pangea/models/base_subscription_info.dart b/lib/pangea/models/base_subscription_info.dart index 469ac5786..8792284e6 100644 --- a/lib/pangea/models/base_subscription_info.dart +++ b/lib/pangea/models/base_subscription_info.dart @@ -36,14 +36,14 @@ class SubscriptionInfo { Fetch App Ids for each RC app (iOS, Android, and Stripe). Used to determine which app a user with an active subscription purchased that subscription. */ - Future setAppIds() async { + Future setAppIds(String accessToken) async { if (appIds != null) return; - appIds = await SubscriptionRepo.getAppIds(); + appIds = await SubscriptionRepo.getAppIds(accessToken); } - Future setAllProducts() async { + Future setAllProducts(String accessToken) async { if (allProducts != null) return; - allProducts = await SubscriptionRepo.getAllProducts(); + allProducts = await SubscriptionRepo.getAllProducts(accessToken); } bool get isNewUserTrial => diff --git a/lib/pangea/models/mobile_subscriptions.dart b/lib/pangea/models/mobile_subscriptions.dart index 00fc6e3fd..d3c58ec82 100644 --- a/lib/pangea/models/mobile_subscriptions.dart +++ b/lib/pangea/models/mobile_subscriptions.dart @@ -31,8 +31,9 @@ class MobileSubscriptionInfo extends SubscriptionInfo { ); return; } - await setAppIds(); - await setAllProducts(); + const accessToken = ""; + await setAppIds(accessToken); + await setAllProducts(accessToken); await setCustomerInfo(); await setMobilePackages(); if (allProducts != null && appIds != null) { diff --git a/lib/pangea/models/web_subscriptions.dart b/lib/pangea/models/web_subscriptions.dart index 1a6cc722a..d70d08c7c 100644 --- a/lib/pangea/models/web_subscriptions.dart +++ b/lib/pangea/models/web_subscriptions.dart @@ -8,8 +8,9 @@ class WebSubscriptionInfo extends SubscriptionInfo { @override Future configure() async { - await setAppIds(); - await setAllProducts(); + const accessToken = ""; + await setAppIds(accessToken); + await setAllProducts(accessToken); await setCustomerInfo(); if (allProducts == null || appIds == null) { diff --git a/lib/pangea/network/urls.dart b/lib/pangea/network/urls.dart index 9a8421d83..41fae28cd 100644 --- a/lib/pangea/network/urls.dart +++ b/lib/pangea/network/urls.dart @@ -12,7 +12,7 @@ class PApiUrls { static String baseAPI = Environment.baseAPI; /// ---------------------- Languages -------------------------------------- - static String getLanguages = "/languages"; + static String getLanguages = "${Environment.choreoApi}/choreo/languages"; /// ---------------------- Users -------------------------------------- static String createUser = "/account/create"; @@ -56,11 +56,9 @@ class PApiUrls { "${Environment.choreoApi}/practice/message"; ///-------------------------------- revenue cat -------------------------- - static String rcApiV1 = "https://api.revenuecat.com/v1"; - static String rcApiV2 = - "https://api.revenuecat.com/v2/projects/${Environment.rcProjectId}"; - static String rcApps = "$rcApiV2/apps"; - static String rcProducts = "$rcApiV2/offerings?expand=items.package.product"; - static String rcSubscribers = "$rcApiV1/subscribers"; -} + static String rcAppsChoreo = "${Environment.choreoApi}/revenue/app_ids"; + static String rcProductsChoreo = + "${Environment.choreoApi}/revenue/all_products"; + static String rcSubscriptionChoreo = + "${Environment.choreoApi}/revenue/subscription"; \ No newline at end of file diff --git a/lib/pangea/repo/subscription_repo.dart b/lib/pangea/repo/subscription_repo.dart index 16ea60c4d..f791ce8c3 100644 --- a/lib/pangea/repo/subscription_repo.dart +++ b/lib/pangea/repo/subscription_repo.dart @@ -1,14 +1,15 @@ import 'dart:convert'; -import 'package:flutter/material.dart'; - import 'package:collection/collection.dart'; -import 'package:http/http.dart' as http; - import 'package:fluffychat/pangea/config/environment.dart'; import 'package:fluffychat/pangea/controllers/subscription_controller.dart'; +import 'package:fluffychat/pangea/network/requests.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/subscription_app_id.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; + import '../network/urls.dart'; class SubscriptionRepo { @@ -18,14 +19,19 @@ class SubscriptionRepo { 'Authorization': 'Bearer ${Environment.rcKey}', }; - static Future getAppIds() async { + static Future getAppIds(String accessToken) async { try { - final http.Response res = await http.get( - Uri.parse(PApiUrls.rcApps), - headers: SubscriptionRepo.requestHeaders, + final Requests req = Requests( + choreoApiKey: Environment.choreoApiKey, + accessToken: accessToken, + ); + final http.Response res = await req.get( + url: PApiUrls.rcAppsChoreo, + ); + + return SubscriptionAppIds.fromJson( + jsonDecode(res.body), ); - final json = jsonDecode(res.body); - return SubscriptionAppIds.fromJson(json); } catch (err) { ErrorHandler.logError( m: "Failed to fetch app information for revenuecat API", @@ -35,11 +41,16 @@ class SubscriptionRepo { } } - static Future?> getAllProducts() async { + static Future?> getAllProducts( + String accessToken, + ) async { try { - final http.Response res = await http.get( - Uri.parse(PApiUrls.rcProducts), - headers: SubscriptionRepo.requestHeaders, + final Requests req = Requests( + choreoApiKey: Environment.choreoApiKey, + accessToken: accessToken, + ); + final http.Response res = await req.get( + url: PApiUrls.rcProductsChoreo, ); final Map json = jsonDecode(res.body); final RCProductsResponseModel resp = @@ -89,26 +100,18 @@ class RCProductsResponseModel { Map json, ) { final List offerings = json["items"] as List; - final offering = offerings.firstWhereOrNull( - Environment.isStaging - ? (offering) => !(offering['is_current'] as bool) - : (offering) => offering['is_current'] as bool, - ); - final Map metadata = offering['metadata']; - - final List allProducts = []; - for (final packageDetails in offering['packages']['items']) { - final String packageId = packageDetails['id']; - final List products = - RCProductsResponseModel.productsFromPackageDetails( - packageDetails, - packageId, - metadata, - ); - allProducts.addAll(products); - } - - return RCProductsResponseModel(allProducts: allProducts); + final res = offerings + .map( + (offering) => SubscriptionDetails( + price: offering['price'], + duration: offering['duration'], + id: offering['id'], + appId: offering['appId'], + ), + ) + .toList() + .cast(); + return RCProductsResponseModel(allProducts: res); } static List productsFromPackageDetails( diff --git a/lib/pangea/utils/subscription_app_id.dart b/lib/pangea/utils/subscription_app_id.dart index 20a69d4a2..362e0d16a 100644 --- a/lib/pangea/utils/subscription_app_id.dart +++ b/lib/pangea/utils/subscription_app_id.dart @@ -22,24 +22,11 @@ class SubscriptionAppIds { return null; } - factory SubscriptionAppIds.fromJson(json) { - final SubscriptionAppIds appIds = SubscriptionAppIds(); - for (final appInfo in (json['items'] as List)) { - final String platform = appInfo['type']; - final String appId = appInfo['id']; - switch (platform) { - case 'stripe': - appIds.stripeId = appId; - continue; - case 'app_store': - appIds.appleId = appId; - continue; - case 'play_store': - appIds.androidId = appId; - continue; - } - } - return appIds; + factory SubscriptionAppIds.fromJson(Map json) { + return SubscriptionAppIds() + ..stripeId = json['stripe_id'] + ..androidId = json['android_id'] + ..appleId = json['apple_id']; } } From f14e14023d3f8d11ac058ac86c63a72f8f3ec6a9 Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Sat, 28 Sep 2024 19:34:34 +0200 Subject: [PATCH 03/10] removed urls --- lib/pangea/network/urls.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/pangea/network/urls.dart b/lib/pangea/network/urls.dart index 41fae28cd..3f8521bb2 100644 --- a/lib/pangea/network/urls.dart +++ b/lib/pangea/network/urls.dart @@ -15,10 +15,12 @@ class PApiUrls { static String getLanguages = "${Environment.choreoApi}/choreo/languages"; /// ---------------------- Users -------------------------------------- - static String createUser = "/account/create"; + static String paymentLink = "/account/payment_link"; static String userDetails = "/account/get_user_access_token?pangea_user_id="; + + // USED ?? + static String createUser = "/account/create"; static String updateUserProfile = "/account/update"; - static String paymentLink = "/account/payment_link"; static String subscriptionExpiration = "/account/premium_expires_date"; /// ---------------------- Conversation Partner ------------------------- From 14475a9d641a1e9fd1d030a8ec39ff9c583df341 Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Mon, 7 Oct 2024 18:27:39 +0200 Subject: [PATCH 04/10] removed old code --- lib/pangea/config/environment.dart | 1 + .../controllers/subscription_controller.dart | 26 +------- lib/pangea/controllers/user_controller.dart | 16 ----- lib/pangea/models/mobile_subscriptions.dart | 2 +- lib/pangea/models/web_subscriptions.dart | 2 +- lib/pangea/network/urls.dart | 63 ++++++++++--------- lib/pangea/repo/subscription_repo.dart | 12 +--- lib/pangea/repo/user_repo.dart | 54 ---------------- 8 files changed, 42 insertions(+), 134 deletions(-) diff --git a/lib/pangea/config/environment.dart b/lib/pangea/config/environment.dart index 4d4378999..c9069e183 100644 --- a/lib/pangea/config/environment.dart +++ b/lib/pangea/config/environment.dart @@ -56,6 +56,7 @@ class Environment { return dotenv.env["RC_IOS_KEY"] ?? 'appl_DUPqnxuLjkBLzhBPTWeDjqNENuv'; } + // This is a public key static String get rcStripeKey { return dotenv.env["RC_STRIPE_KEY"] ?? 'strp_YWZxWUeEfvagiefDNoofinaRCOl'; } diff --git a/lib/pangea/controllers/subscription_controller.dart b/lib/pangea/controllers/subscription_controller.dart index 73cf77dff..607917c33 100644 --- a/lib/pangea/controllers/subscription_controller.dart +++ b/lib/pangea/controllers/subscription_controller.dart @@ -308,7 +308,7 @@ class SubscriptionController extends BaseController { } Future getPaymentLink(String duration, {bool isPromo = false}) async { - final Requests req = Requests(baseUrl: PApiUrls.baseAPI); + final Requests req = Requests(); final String reqUrl = Uri.encodeFull( "${PApiUrls.paymentLink}?pangea_user_id=${_pangeaController.matrixState.client.userID}&duration=$duration&redeem=$isPromo", ); @@ -323,30 +323,6 @@ class SubscriptionController extends BaseController { return paymentLink; } - Future fetchSubscriptionStatus() async { - final Requests req = Requests(baseUrl: PApiUrls.baseAPI); - final String reqUrl = Uri.encodeFull( - "${PApiUrls.subscriptionExpiration}?pangea_user_id=${_pangeaController.matrixState.client.userID}", - ); - - DateTime? expiration; - try { - final Response res = await req.get(url: reqUrl); - final json = jsonDecode(res.body); - if (json["premium_expires_date"] != null) { - expiration = DateTime.parse(json["premium_expires_date"]); - } - } catch (err) { - ErrorHandler.logError( - e: "Failed to fetch subscripton status for user ${_pangeaController.matrixState.client.userID}", - s: StackTrace.current, - ); - } - final bool subscribed = - expiration == null ? false : DateTime.now().isBefore(expiration); - GoogleAnalytics.updateUserSubscriptionStatus(subscribed); - return subscribed; - } Future redeemPromoCode(BuildContext context) async { final List? promoCode = await showTextInputDialog( diff --git a/lib/pangea/controllers/user_controller.dart b/lib/pangea/controllers/user_controller.dart index 5ee8672ff..b4c0db914 100644 --- a/lib/pangea/controllers/user_controller.dart +++ b/lib/pangea/controllers/user_controller.dart @@ -10,7 +10,6 @@ import 'package:jwt_decode/jwt_decode.dart'; import 'package:matrix/matrix.dart' as matrix; import '../models/user_model.dart'; -import '../repo/user_repo.dart'; /// Controller that manages saving and reading of user/profile information class UserController extends BaseController { @@ -122,21 +121,6 @@ class UserController extends BaseController { /// data to profile, and migrating from the pangea profile if the account data is not present. Future _initialize() async { await _pangeaController.matrixState.client.waitForAccountData(); - if (profile.userSettings.dateOfBirth != null) { - return; - } - - final PangeaProfileResponse? resp = await PUserRepo.fetchPangeaUserInfo( - userID: userId!, - matrixAccessToken: _matrixAccessToken!, - ); - if (resp?.profile == null) { - return; - } - - final userSetting = UserSettings.fromJson(resp!.profile.toJson()); - final newProfile = Profile(userSettings: userSetting); - await newProfile.saveProfileData(waitForDataInSync: true); } /// Reinitializes the user's profile diff --git a/lib/pangea/models/mobile_subscriptions.dart b/lib/pangea/models/mobile_subscriptions.dart index d3c58ec82..917deebb6 100644 --- a/lib/pangea/models/mobile_subscriptions.dart +++ b/lib/pangea/models/mobile_subscriptions.dart @@ -31,7 +31,7 @@ class MobileSubscriptionInfo extends SubscriptionInfo { ); return; } - const accessToken = ""; + final accessToken = super.pangeaController.userController.accessToken; await setAppIds(accessToken); await setAllProducts(accessToken); await setCustomerInfo(); diff --git a/lib/pangea/models/web_subscriptions.dart b/lib/pangea/models/web_subscriptions.dart index d70d08c7c..92a3e4dd5 100644 --- a/lib/pangea/models/web_subscriptions.dart +++ b/lib/pangea/models/web_subscriptions.dart @@ -8,7 +8,7 @@ class WebSubscriptionInfo extends SubscriptionInfo { @override Future configure() async { - const accessToken = ""; + final accessToken = super.pangeaController.userController.accessToken; await setAppIds(accessToken); await setAllProducts(accessToken); await setCustomerInfo(); diff --git a/lib/pangea/network/urls.dart b/lib/pangea/network/urls.dart index 3f8521bb2..438ea6c92 100644 --- a/lib/pangea/network/urls.dart +++ b/lib/pangea/network/urls.dart @@ -9,58 +9,65 @@ import 'package:fluffychat/pangea/config/environment.dart'; /// /// https://api.staging.pangea.chat/api/v1/ class PApiUrls { - static String baseAPI = Environment.baseAPI; + static String choreoPrefix = "/choreo"; + static String revenuePrefix = "/revenue"; + static String accountPrefix = "/account"; + + static String choreoEndpoint = + "${Environment.choreoApi}${PApiUrls.choreoPrefix}"; + static String revenueEndpoint = + "${Environment.choreoApi}${PApiUrls.revenuePrefix}"; + static String accountEndpoint = + "${Environment.choreoApi}${PApiUrls.accountPrefix}"; /// ---------------------- Languages -------------------------------------- - static String getLanguages = "${Environment.choreoApi}/choreo/languages"; + static String getLanguages = "${PApiUrls.choreoEndpoint}/languages"; /// ---------------------- Users -------------------------------------- - static String paymentLink = "/account/payment_link"; - static String userDetails = "/account/get_user_access_token?pangea_user_id="; - - // USED ?? - static String createUser = "/account/create"; - static String updateUserProfile = "/account/update"; - static String subscriptionExpiration = "/account/premium_expires_date"; + static String paymentLink = "${PApiUrls.accountEndpoint}/payment_link"; /// ---------------------- Conversation Partner ------------------------- - static String searchUserProfiles = "/account/search"; + /// PTODO: Migrate or remove + static String searchUserProfiles = "${PApiUrls.accountEndpoint}/search"; ///-------------------------------- choreo -------------------------- - static String igc = "${Environment.choreoApi}/grammar"; + static String igc = "${PApiUrls.choreoEndpoint}/grammar"; static String languageDetection = - "${Environment.choreoApi}/language_detection"; + "${PApiUrls.choreoEndpoint}/language_detection"; - static String igcLite = "${Environment.choreoApi}/grammar_lite"; - static String spanDetails = "${Environment.choreoApi}/span_details"; + static String igcLite = "${PApiUrls.choreoEndpoint}/grammar_lite"; + static String spanDetails = "${PApiUrls.choreoEndpoint}/span_details"; - static String wordNet = "${Environment.choreoApi}/wordnet"; + static String wordNet = "${PApiUrls.choreoEndpoint}/wordnet"; static String contextualizedTranslation = - "${Environment.choreoApi}/translation/contextual"; + "${PApiUrls.choreoEndpoint}/translation/contextual"; static String simpleTranslation = - "${Environment.choreoApi}/translation/direct"; - static String tokenize = "${Environment.choreoApi}/tokenize"; + "${PApiUrls.choreoEndpoint}/translation/direct"; + static String tokenize = "${PApiUrls.choreoEndpoint}/tokenize"; static String contextualDefinition = - "${Environment.choreoApi}/contextual_definition"; - static String similarity = "${Environment.choreoApi}/similarity"; - static String topicInfo = "${Environment.choreoApi}/vocab_list"; + "${PApiUrls.choreoEndpoint}/contextual_definition"; + static String similarity = "${PApiUrls.choreoEndpoint}/similarity"; + static String topicInfo = "${PApiUrls.choreoEndpoint}/vocab_list"; - static String itFeedback = "${Environment.choreoApi}/translation/feedback"; + static String itFeedback = "${PApiUrls.choreoEndpoint}/translation/feedback"; static String firstStep = "/it_initialstep"; static String subseqStep = "/it_step"; - static String textToSpeech = "${Environment.choreoApi}/text_to_speech"; - static String speechToText = "${Environment.choreoApi}/speech_to_text"; + static String textToSpeech = "${PApiUrls.choreoEndpoint}/text_to_speech"; + static String speechToText = "${PApiUrls.choreoEndpoint}/speech_to_text"; static String messageActivityGeneration = "${Environment.choreoApi}/practice/message"; ///-------------------------------- revenue cat -------------------------- - static String rcAppsChoreo = "${Environment.choreoApi}/revenue/app_ids"; + static String rcApiV1 = "https://api.revenuecat.com/v1"; + + static String rcAppsChoreo = "${PApiUrls.revenueEndpoint}/app_ids"; static String rcProductsChoreo = - "${Environment.choreoApi}/revenue/all_products"; - static String rcSubscriptionChoreo = - "${Environment.choreoApi}/revenue/subscription"; \ No newline at end of file + "${PApiUrls.revenueEndpoint}/all_products"; + + static String rcSubscription = "$rcApiV1/subscribers"; +} diff --git a/lib/pangea/repo/subscription_repo.dart b/lib/pangea/repo/subscription_repo.dart index f791ce8c3..4c30a0c0e 100644 --- a/lib/pangea/repo/subscription_repo.dart +++ b/lib/pangea/repo/subscription_repo.dart @@ -13,17 +13,11 @@ import 'package:http/http.dart' as http; import '../network/urls.dart'; class SubscriptionRepo { - static final Map requestHeaders = { - 'Content-type': 'application/json', - 'Accept': 'application/json', - 'Authorization': 'Bearer ${Environment.rcKey}', - }; - static Future getAppIds(String accessToken) async { try { final Requests req = Requests( choreoApiKey: Environment.choreoApiKey, - accessToken: accessToken, + matrixAccessToken: accessToken, ); final http.Response res = await req.get( url: PApiUrls.rcAppsChoreo, @@ -47,7 +41,7 @@ class SubscriptionRepo { try { final Requests req = Requests( choreoApiKey: Environment.choreoApiKey, - accessToken: accessToken, + matrixAccessToken: accessToken, ); final http.Response res = await req.get( url: PApiUrls.rcProductsChoreo, @@ -74,7 +68,7 @@ class SubscriptionRepo { 'Accept': 'application/json', 'Authorization': 'Bearer ${Environment.rcStripeKey}', }; - final String url = "${PApiUrls.rcSubscribers}/$userId"; + final String url = "${PApiUrls.rcSubscription}/$userId"; final http.Response res = await http.get( Uri.parse(url), headers: stripeHeaders, diff --git a/lib/pangea/repo/user_repo.dart b/lib/pangea/repo/user_repo.dart index 7f3efc48f..a89009cda 100644 --- a/lib/pangea/repo/user_repo.dart +++ b/lib/pangea/repo/user_repo.dart @@ -1,66 +1,13 @@ import 'dart:convert'; -import 'dart:developer'; import 'package:fluffychat/pangea/constants/model_keys.dart'; import 'package:http/http.dart'; -import '../models/user_model.dart'; import '../models/user_profile_search_model.dart'; import '../network/requests.dart'; import '../network/urls.dart'; class PUserRepo { - // static Future repoCreatePangeaUser({ - // required String userID, - // required String dob, - // required fullName, - // required String matrixAccessToken, - // }) async { - // try { - // final Requests req = Requests( - // baseUrl: PApiUrls.baseAPI, - // matrixAccessToken: matrixAccessToken, - // ); - - // final Map body = { - // ModelKey.userFullName: fullName, - // ModelKey.userPangeaUserId: userID, - // ModelKey.userDateOfBirth: dob, - // }; - // final resp = await req.post( - // url: PApiUrls.createUser, - // body: body, - // ); - // return PangeaProfileResponse.fromJson(jsonDecode(resp.body)); - // } catch (err, s) { - // ErrorHandler.logError(e: err, s: s); - // return null; - // } - // } - - static Future fetchPangeaUserInfo({ - required String userID, - required String matrixAccessToken, - }) async { - Response res; - try { - final Requests req = Requests( - baseUrl: PApiUrls.baseAPI, - matrixAccessToken: matrixAccessToken, - ); - res = await req.get( - url: PApiUrls.userDetails, - objectId: userID, - ); - - return PangeaProfileResponse.fromJson(jsonDecode(res.body)); - } catch (err) { - //status code should be 400 - PTODO - check ffor this. - log("Most likely a first signup and needs to make an account"); - return null; - } - } - static Future searchUserProfiles({ // List? interests, String? targetLanguage, @@ -72,7 +19,6 @@ class PUserRepo { required int limit, }) async { final Requests req = Requests( - baseUrl: PApiUrls.baseAPI, accessToken: accessToken, ); final Map body = {}; From e55a7c453dd832eee7abee7cc9002c2dbd370c6b Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Tue, 8 Oct 2024 15:13:31 +0200 Subject: [PATCH 05/10] updated urls to subscription --- lib/pangea/network/urls.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pangea/network/urls.dart b/lib/pangea/network/urls.dart index 438ea6c92..58b9c61b1 100644 --- a/lib/pangea/network/urls.dart +++ b/lib/pangea/network/urls.dart @@ -10,13 +10,13 @@ import 'package:fluffychat/pangea/config/environment.dart'; /// https://api.staging.pangea.chat/api/v1/ class PApiUrls { static String choreoPrefix = "/choreo"; - static String revenuePrefix = "/revenue"; + static String subscriptionPrefix = "/subscription"; static String accountPrefix = "/account"; static String choreoEndpoint = "${Environment.choreoApi}${PApiUrls.choreoPrefix}"; - static String revenueEndpoint = - "${Environment.choreoApi}${PApiUrls.revenuePrefix}"; + static String subscriptionEndpoint = + "${Environment.choreoApi}${PApiUrls.subscriptionPrefix}"; static String accountEndpoint = "${Environment.choreoApi}${PApiUrls.accountPrefix}"; @@ -65,9 +65,9 @@ class PApiUrls { static String rcApiV1 = "https://api.revenuecat.com/v1"; - static String rcAppsChoreo = "${PApiUrls.revenueEndpoint}/app_ids"; + static String rcAppsChoreo = "${PApiUrls.subscriptionEndpoint}/app_ids"; static String rcProductsChoreo = - "${PApiUrls.revenueEndpoint}/all_products"; + "${PApiUrls.subscriptionEndpoint}/all_products"; static String rcSubscription = "$rcApiV1/subscribers"; } From c600621cac115113af770b535fd000191ec11229 Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Tue, 8 Oct 2024 15:32:03 +0200 Subject: [PATCH 06/10] remoived accestoken --- lib/pangea/models/base_subscription_info.dart | 8 ++++---- lib/pangea/models/mobile_subscriptions.dart | 5 ++--- lib/pangea/models/web_subscriptions.dart | 5 ++--- lib/pangea/repo/subscription_repo.dart | 8 ++------ 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/pangea/models/base_subscription_info.dart b/lib/pangea/models/base_subscription_info.dart index 8792284e6..469ac5786 100644 --- a/lib/pangea/models/base_subscription_info.dart +++ b/lib/pangea/models/base_subscription_info.dart @@ -36,14 +36,14 @@ class SubscriptionInfo { Fetch App Ids for each RC app (iOS, Android, and Stripe). Used to determine which app a user with an active subscription purchased that subscription. */ - Future setAppIds(String accessToken) async { + Future setAppIds() async { if (appIds != null) return; - appIds = await SubscriptionRepo.getAppIds(accessToken); + appIds = await SubscriptionRepo.getAppIds(); } - Future setAllProducts(String accessToken) async { + Future setAllProducts() async { if (allProducts != null) return; - allProducts = await SubscriptionRepo.getAllProducts(accessToken); + allProducts = await SubscriptionRepo.getAllProducts(); } bool get isNewUserTrial => diff --git a/lib/pangea/models/mobile_subscriptions.dart b/lib/pangea/models/mobile_subscriptions.dart index 917deebb6..00fc6e3fd 100644 --- a/lib/pangea/models/mobile_subscriptions.dart +++ b/lib/pangea/models/mobile_subscriptions.dart @@ -31,9 +31,8 @@ class MobileSubscriptionInfo extends SubscriptionInfo { ); return; } - final accessToken = super.pangeaController.userController.accessToken; - await setAppIds(accessToken); - await setAllProducts(accessToken); + await setAppIds(); + await setAllProducts(); await setCustomerInfo(); await setMobilePackages(); if (allProducts != null && appIds != null) { diff --git a/lib/pangea/models/web_subscriptions.dart b/lib/pangea/models/web_subscriptions.dart index 92a3e4dd5..1a6cc722a 100644 --- a/lib/pangea/models/web_subscriptions.dart +++ b/lib/pangea/models/web_subscriptions.dart @@ -8,9 +8,8 @@ class WebSubscriptionInfo extends SubscriptionInfo { @override Future configure() async { - final accessToken = super.pangeaController.userController.accessToken; - await setAppIds(accessToken); - await setAllProducts(accessToken); + await setAppIds(); + await setAllProducts(); await setCustomerInfo(); if (allProducts == null || appIds == null) { diff --git a/lib/pangea/repo/subscription_repo.dart b/lib/pangea/repo/subscription_repo.dart index 4c30a0c0e..d5b8ae4c7 100644 --- a/lib/pangea/repo/subscription_repo.dart +++ b/lib/pangea/repo/subscription_repo.dart @@ -13,11 +13,10 @@ import 'package:http/http.dart' as http; import '../network/urls.dart'; class SubscriptionRepo { - static Future getAppIds(String accessToken) async { + static Future getAppIds() async { try { final Requests req = Requests( choreoApiKey: Environment.choreoApiKey, - matrixAccessToken: accessToken, ); final http.Response res = await req.get( url: PApiUrls.rcAppsChoreo, @@ -35,13 +34,10 @@ class SubscriptionRepo { } } - static Future?> getAllProducts( - String accessToken, - ) async { + static Future?> getAllProducts() async { try { final Requests req = Requests( choreoApiKey: Environment.choreoApiKey, - matrixAccessToken: accessToken, ); final http.Response res = await req.get( url: PApiUrls.rcProductsChoreo, From 21641f514a560bc25401a4d57732490194af4160 Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Tue, 8 Oct 2024 15:53:19 +0200 Subject: [PATCH 07/10] removed base url from languages --- lib/pangea/repo/language_repo.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pangea/repo/language_repo.dart b/lib/pangea/repo/language_repo.dart index 9ca12b25e..bbd802c9b 100644 --- a/lib/pangea/repo/language_repo.dart +++ b/lib/pangea/repo/language_repo.dart @@ -7,12 +7,11 @@ import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart'; -import '../config/environment.dart'; import '../network/requests.dart'; class LanguageRepo { static Future> fetchLanguages() async { - final Requests req = Requests(baseUrl: Environment.choreoApi); + final Requests req = Requests(); final Response res = await req.get(url: PApiUrls.getLanguages); final decodedBody = From e7debbdd399a6791ea02df80c16afcdf871279df Mon Sep 17 00:00:00 2001 From: ggurdin Date: Mon, 21 Oct 2024 10:33:54 -0400 Subject: [PATCH 08/10] fixed some incorrect URLs and request setups --- lib/pangea/controllers/subscription_controller.dart | 7 +++++-- lib/pangea/network/urls.dart | 6 +++--- lib/pangea/repo/image_repo.dart | 13 +++++++++---- lib/pangea/repo/interactive_translation_repo.dart | 7 ++++--- lib/pangea/repo/language_repo.dart | 7 ++++++- lib/pangea/repo/subscription_repo.dart | 3 +++ lib/pangea/repo/user_repo.dart | 2 ++ 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/pangea/controllers/subscription_controller.dart b/lib/pangea/controllers/subscription_controller.dart index 607917c33..1f47ecb39 100644 --- a/lib/pangea/controllers/subscription_controller.dart +++ b/lib/pangea/controllers/subscription_controller.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:fluffychat/config/app_config.dart'; +import 'package:fluffychat/pangea/config/environment.dart'; import 'package:fluffychat/pangea/constants/local.key.dart'; import 'package:fluffychat/pangea/controllers/base_controller.dart'; import 'package:fluffychat/pangea/controllers/pangea_controller.dart'; @@ -308,7 +309,10 @@ class SubscriptionController extends BaseController { } Future getPaymentLink(String duration, {bool isPromo = false}) async { - final Requests req = Requests(); + final Requests req = Requests( + choreoApiKey: Environment.choreoApiKey, + accessToken: _pangeaController.userController.accessToken, + ); final String reqUrl = Uri.encodeFull( "${PApiUrls.paymentLink}?pangea_user_id=${_pangeaController.matrixState.client.userID}&duration=$duration&redeem=$isPromo", ); @@ -323,7 +327,6 @@ class SubscriptionController extends BaseController { return paymentLink; } - Future redeemPromoCode(BuildContext context) async { final List? promoCode = await showTextInputDialog( useRootNavigator: false, diff --git a/lib/pangea/network/urls.dart b/lib/pangea/network/urls.dart index 58b9c61b1..da774858b 100644 --- a/lib/pangea/network/urls.dart +++ b/lib/pangea/network/urls.dart @@ -52,14 +52,14 @@ class PApiUrls { static String itFeedback = "${PApiUrls.choreoEndpoint}/translation/feedback"; - static String firstStep = "/it_initialstep"; - static String subseqStep = "/it_step"; + static String firstStep = "${PApiUrls.choreoEndpoint}/it_initialstep"; + static String subseqStep = "${PApiUrls.choreoEndpoint}/it_step"; static String textToSpeech = "${PApiUrls.choreoEndpoint}/text_to_speech"; static String speechToText = "${PApiUrls.choreoEndpoint}/speech_to_text"; static String messageActivityGeneration = - "${Environment.choreoApi}/practice/message"; + "${PApiUrls.choreoEndpoint}/practice/message"; ///-------------------------------- revenue cat -------------------------- diff --git a/lib/pangea/repo/image_repo.dart b/lib/pangea/repo/image_repo.dart index 624e06e22..d12f02975 100644 --- a/lib/pangea/repo/image_repo.dart +++ b/lib/pangea/repo/image_repo.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:developer'; import 'package:fluffychat/pangea/utils/error_handler.dart'; +import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart'; @@ -44,9 +45,12 @@ class GenerateImageRequest { class ImageRepo { static Future fetchImage( - GenerateImageRequest request) async { - final Requests req = - Requests(baseUrl: Environment.choreoApi); // Set your API base URL + GenerateImageRequest request, + ) async { + final Requests req = Requests( + choreoApiKey: Environment.choreoApiKey, + accessToken: MatrixState.pangeaController.userController.accessToken, + ); // Set your API base URL final requestBody = request.toJson(); try { @@ -58,7 +62,8 @@ class ImageRepo { if (res.statusCode == 200) { final decodedBody = jsonDecode(utf8.decode(res.bodyBytes)); return GenerateImageeResponse.fromJson( - decodedBody); // Convert response to ImageModel + decodedBody, + ); // Convert response to ImageModel } else { throw Exception('Failed to load image'); } diff --git a/lib/pangea/repo/interactive_translation_repo.dart b/lib/pangea/repo/interactive_translation_repo.dart index ab5d3b1d6..6e1739ecf 100644 --- a/lib/pangea/repo/interactive_translation_repo.dart +++ b/lib/pangea/repo/interactive_translation_repo.dart @@ -1,8 +1,9 @@ import 'dart:convert'; +import 'package:fluffychat/pangea/config/environment.dart'; +import 'package:fluffychat/widgets/matrix.dart'; import 'package:http/http.dart'; -import 'package:fluffychat/pangea/config/environment.dart'; import '../models/custom_input_translation_model.dart'; import '../models/it_response_model.dart'; import '../models/system_choice_translation_model.dart'; @@ -14,8 +15,8 @@ class ITRepo { CustomInputRequestModel initalText, ) async { final Requests req = Requests( - baseUrl: Environment.choreoApi, choreoApiKey: Environment.choreoApiKey, + accessToken: MatrixState.pangeaController.userController.accessToken, ); final Response res = await req.post(url: PApiUrls.firstStep, body: initalText.toJson()); @@ -29,8 +30,8 @@ class ITRepo { SystemChoiceRequestModel subseqText, ) async { final Requests req = Requests( - baseUrl: Environment.choreoApi, choreoApiKey: Environment.choreoApiKey, + accessToken: MatrixState.pangeaController.userController.accessToken, ); final Response res = diff --git a/lib/pangea/repo/language_repo.dart b/lib/pangea/repo/language_repo.dart index bbd802c9b..ab764623c 100644 --- a/lib/pangea/repo/language_repo.dart +++ b/lib/pangea/repo/language_repo.dart @@ -1,9 +1,11 @@ import 'dart:convert'; import 'dart:developer'; +import 'package:fluffychat/pangea/config/environment.dart'; import 'package:fluffychat/pangea/models/language_model.dart'; import 'package:fluffychat/pangea/network/urls.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; +import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart'; @@ -11,7 +13,10 @@ import '../network/requests.dart'; class LanguageRepo { static Future> fetchLanguages() async { - final Requests req = Requests(); + final Requests req = Requests( + choreoApiKey: Environment.choreoApiKey, + accessToken: MatrixState.pangeaController.userController.accessToken, + ); final Response res = await req.get(url: PApiUrls.getLanguages); final decodedBody = diff --git a/lib/pangea/repo/subscription_repo.dart b/lib/pangea/repo/subscription_repo.dart index d5b8ae4c7..7a9dc48c8 100644 --- a/lib/pangea/repo/subscription_repo.dart +++ b/lib/pangea/repo/subscription_repo.dart @@ -6,6 +6,7 @@ import 'package:fluffychat/pangea/controllers/subscription_controller.dart'; import 'package:fluffychat/pangea/network/requests.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/subscription_app_id.dart'; +import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; @@ -17,6 +18,7 @@ class SubscriptionRepo { try { final Requests req = Requests( choreoApiKey: Environment.choreoApiKey, + accessToken: MatrixState.pangeaController.userController.accessToken, ); final http.Response res = await req.get( url: PApiUrls.rcAppsChoreo, @@ -38,6 +40,7 @@ class SubscriptionRepo { try { final Requests req = Requests( choreoApiKey: Environment.choreoApiKey, + accessToken: MatrixState.pangeaController.userController.accessToken, ); final http.Response res = await req.get( url: PApiUrls.rcProductsChoreo, diff --git a/lib/pangea/repo/user_repo.dart b/lib/pangea/repo/user_repo.dart index a89009cda..ec6f29c01 100644 --- a/lib/pangea/repo/user_repo.dart +++ b/lib/pangea/repo/user_repo.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:fluffychat/pangea/config/environment.dart'; import 'package:fluffychat/pangea/constants/model_keys.dart'; import 'package:http/http.dart'; @@ -20,6 +21,7 @@ class PUserRepo { }) async { final Requests req = Requests( accessToken: accessToken, + choreoApiKey: Environment.choreoApiKey, ); final Map body = {}; // if (interests != null) body[ModelKey.userInterests] = interests.toString(); From 542958dcb3f7230b5035f0efa31480cc3c516476 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Mon, 4 Nov 2024 09:40:07 -0500 Subject: [PATCH 09/10] cast subscription duration as enum value --- lib/pangea/repo/subscription_repo.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/pangea/repo/subscription_repo.dart b/lib/pangea/repo/subscription_repo.dart index 4b0174cf3..d50cd1c6f 100644 --- a/lib/pangea/repo/subscription_repo.dart +++ b/lib/pangea/repo/subscription_repo.dart @@ -49,11 +49,8 @@ class SubscriptionRepo { final RCProductsResponseModel resp = RCProductsResponseModel.fromJson(json); return resp.allProducts; - } catch (err) { - ErrorHandler.logError( - m: "Failed to fetch entitlement information for revenuecat API", - s: StackTrace.current, - ); + } catch (err, s) { + ErrorHandler.logError(e: err, s: s); return null; } } @@ -97,7 +94,9 @@ class RCProductsResponseModel { .map( (offering) => SubscriptionDetails( price: offering['price'], - duration: offering['duration'], + duration: SubscriptionDuration.values.firstWhereOrNull( + (duration) => duration.value == offering['duration'], + ), id: offering['id'], appId: offering['appId'], ), From d0e306d0d0e2dd2b19520cc4b0ece4a1b52e6509 Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Mon, 4 Nov 2024 17:20:19 +0100 Subject: [PATCH 10/10] correct url --- lib/pangea/network/urls.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pangea/network/urls.dart b/lib/pangea/network/urls.dart index da774858b..6a4ba5607 100644 --- a/lib/pangea/network/urls.dart +++ b/lib/pangea/network/urls.dart @@ -24,7 +24,7 @@ class PApiUrls { static String getLanguages = "${PApiUrls.choreoEndpoint}/languages"; /// ---------------------- Users -------------------------------------- - static String paymentLink = "${PApiUrls.accountEndpoint}/payment_link"; + static String paymentLink = "${PApiUrls.subscriptionEndpoint}/payment_link"; /// ---------------------- Conversation Partner ------------------------- /// PTODO: Migrate or remove