lot of work on rfplus

This commit is contained in:
Kima 2024-02-28 22:37:21 +01:00
parent 55a9a41722
commit 25464eff79
8 changed files with 214 additions and 30 deletions

View File

@ -50,6 +50,10 @@ class FilcAPI {
static const allGradeColors = "$gradeColorsGet/all"; static const allGradeColors = "$gradeColorsGet/all";
static const gradeColorsByID = "$gradeColorsGet/"; static const gradeColorsByID = "$gradeColorsGet/";
// Payment API
static const payment = "$baseUrl/v3/payment";
static const stripeSheet = "$payment/stripe-sheet";
static Future<bool> checkConnectivity() async => static Future<bool> checkConnectivity() async =>
(await Connectivity().checkConnectivity()) != ConnectivityResult.none; (await Connectivity().checkConnectivity()) != ConnectivityResult.none;
@ -340,6 +344,35 @@ class FilcAPI {
} }
return null; return null;
} }
// payment
static Future<Map?> createPaymentSheet(String product) async {
try {
Map body = {
"product": product,
};
var client = http.Client();
http.Response res = await client.post(
Uri.parse(stripeSheet),
body: body,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
);
if (res.statusCode != 200) {
throw "HTTP ${res.statusCode}: ${res.body}";
}
return jsonDecode(res.body);
} on Exception catch (error, stacktrace) {
log("ERROR: FilcAPI.sendReport: $error $stacktrace");
}
return null;
}
} }
class ErrorReport { class ErrorReport {

View File

@ -35,7 +35,7 @@ void main() async {
// initialize stripe key // initialize stripe key
stripe.Stripe.publishableKey = stripe.Stripe.publishableKey =
'pk_live_51OWSV2HW2TAy5tA6EELuXtpG6ombCCrOFbvz2fDwZlqLT42Ql64CfxptWem8NjN1dhnE6jaI77TRsVZbF8gfd29Q00OGMQRGqm'; 'pk_test_51Oo7iUBS0FxsTGxKjGZSQqzDKWHY5ZFYM9XeI0qSdIh2w8jWy6GhHlYpT7GLTzgpl1xhE5YP4BXpA4gMZqPmgMId00cGFYFzbh';
// Run App // Run App
runApp(App( runApp(App(

View File

@ -91,6 +91,7 @@ class SettingsProvider extends ChangeNotifier {
// more // more
bool _showBreaks; bool _showBreaks;
String _fontFamily; String _fontFamily;
String _plusSessionId;
SettingsProvider({ SettingsProvider({
DatabaseProvider? database, DatabaseProvider? database,
@ -148,6 +149,7 @@ class SettingsProvider extends ChangeNotifier {
required String pinSetNotify, required String pinSetNotify,
required String pinSetExtras, required String pinSetExtras,
required String fontFamily, required String fontFamily,
required String plusSessionId,
}) : _database = database, }) : _database = database,
_language = language, _language = language,
_startPage = startPage, _startPage = startPage,
@ -202,7 +204,8 @@ class SettingsProvider extends ChangeNotifier {
_pinSetPersonalize = pinSetPersonalize, _pinSetPersonalize = pinSetPersonalize,
_pinSetNotify = pinSetNotify, _pinSetNotify = pinSetNotify,
_pinSetExtras = pinSetExtras, _pinSetExtras = pinSetExtras,
_fontFamily = fontFamily; _fontFamily = fontFamily,
_plusSessionId = plusSessionId;
factory SettingsProvider.fromMap(Map map, factory SettingsProvider.fromMap(Map map,
{required DatabaseProvider database}) { {required DatabaseProvider database}) {
@ -277,6 +280,7 @@ class SettingsProvider extends ChangeNotifier {
pinSetNotify: map['notify_s_pin'], pinSetNotify: map['notify_s_pin'],
pinSetExtras: map['extras_s_pin'], pinSetExtras: map['extras_s_pin'],
fontFamily: map['font_family'], fontFamily: map['font_family'],
plusSessionId: map['plus_session_id'],
); );
} }
@ -339,6 +343,7 @@ class SettingsProvider extends ChangeNotifier {
"notify_s_pin": _pinSetNotify, "notify_s_pin": _pinSetNotify,
"extras_s_pin": _pinSetExtras, "extras_s_pin": _pinSetExtras,
"font_family": _fontFamily, "font_family": _fontFamily,
"plus_session_id": _plusSessionId,
}; };
} }
@ -405,6 +410,7 @@ class SettingsProvider extends ChangeNotifier {
pinSetNotify: '', pinSetNotify: '',
pinSetExtras: '', pinSetExtras: '',
fontFamily: '', fontFamily: '',
plusSessionId: '',
); );
} }
@ -462,6 +468,7 @@ class SettingsProvider extends ChangeNotifier {
String get currentThemeCreator => _currentThemeCreator; String get currentThemeCreator => _currentThemeCreator;
bool get showBreaks => _showBreaks; bool get showBreaks => _showBreaks;
String get fontFamily => _fontFamily; String get fontFamily => _fontFamily;
String get plusSessionId => _plusSessionId;
Future<void> update({ Future<void> update({
bool store = true, bool store = true,
@ -515,6 +522,7 @@ class SettingsProvider extends ChangeNotifier {
String? currentThemeCreator, String? currentThemeCreator,
bool? showBreaks, bool? showBreaks,
String? fontFamily, String? fontFamily,
String? plusSessionId,
}) async { }) async {
if (language != null && language != _language) _language = language; if (language != null && language != _language) _language = language;
if (startPage != null && startPage != _startPage) _startPage = startPage; if (startPage != null && startPage != _startPage) _startPage = startPage;
@ -662,6 +670,9 @@ class SettingsProvider extends ChangeNotifier {
if (fontFamily != null && fontFamily != _fontFamily) { if (fontFamily != null && fontFamily != _fontFamily) {
_fontFamily = fontFamily; _fontFamily = fontFamily;
} }
if (plusSessionId != null && plusSessionId != _plusSessionId) {
_plusSessionId = plusSessionId;
}
// store or not // store or not
if (store) await _database?.store.storeSettings(this); if (store) await _database?.store.storeSettings(this);
notifyListeners(); notifyListeners();

View File

@ -11,8 +11,10 @@ import 'package:googleapis/calendar/v3.dart';
import 'package:google_sign_in/google_sign_in.dart'; import 'package:google_sign_in/google_sign_in.dart';
class ThirdPartyProvider with ChangeNotifier { class ThirdPartyProvider with ChangeNotifier {
late List<Event>? _googleEvents;
late List<LinkedAccount> _linkedAccounts; late List<LinkedAccount> _linkedAccounts;
// google specific
late List<Event>? _googleEvents;
late List<Calendar>? _googleCalendars;
late BuildContext _context; late BuildContext _context;
@ -21,9 +23,12 @@ class ThirdPartyProvider with ChangeNotifier {
CalendarApi.calendarEventsScope, CalendarApi.calendarEventsScope,
]); ]);
List<Event> get googleEvents => _googleEvents ?? []; // public
List<LinkedAccount> get linkedAccounts => _linkedAccounts; List<LinkedAccount> get linkedAccounts => _linkedAccounts;
List<Event> get googleEvents => _googleEvents ?? [];
List<Calendar> get googleCalendars => _googleCalendars ?? [];
ThirdPartyProvider({ ThirdPartyProvider({
required BuildContext context, required BuildContext context,
List<LinkedAccount>? initialLinkedAccounts, List<LinkedAccount>? initialLinkedAccounts,
@ -64,6 +69,11 @@ class ThirdPartyProvider with ChangeNotifier {
return null; return null;
} }
Future<void> signOutAll() async {
await _googleSignIn.signOut();
_linkedAccounts.clear();
}
// Future<void> fetchGoogle() async { // Future<void> fetchGoogle() async {
// try { // try {
// var httpClient = (await _googleSignIn.authenticatedClient())!; // var httpClient = (await _googleSignIn.authenticatedClient())!;

View File

@ -1,4 +1,5 @@
import 'package:flutter_stripe/flutter_stripe.dart' as stripe; import 'package:flutter_stripe/flutter_stripe.dart' as stripe;
import 'package:refilc/api/client.dart';
import 'package:refilc/theme/colors/colors.dart'; import 'package:refilc/theme/colors/colors.dart';
import 'package:refilc_plus/providers/premium_provider.dart'; import 'package:refilc_plus/providers/premium_provider.dart';
import 'package:refilc_plus/ui/mobile/premium/activation_view/activation_view.dart'; import 'package:refilc_plus/ui/mobile/premium/activation_view/activation_view.dart';
@ -6,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart'; import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
class GithubLoginButton extends StatelessWidget { class GithubLoginButton extends StatelessWidget {
const GithubLoginButton({super.key}); const GithubLoginButton({super.key});
@ -40,10 +42,21 @@ class GithubLoginButton extends StatelessWidget {
// Navigator.of(context).push(MaterialPageRoute(builder: (context) { // Navigator.of(context).push(MaterialPageRoute(builder: (context) {
// return const PremiumActivationView(); // return const PremiumActivationView();
// })); // }));
bool initFinished = await initPaymentSheet(context); // bool initFinished = await initPaymentSheet(context);
if (initFinished) { // if (initFinished) {
await stripe.Stripe.instance.presentPaymentSheet(); // stripe.PaymentSheetPaymentOption? result =
} // await stripe.Stripe.instance.presentPaymentSheet();
// print(result == null);
// print(result?.label ?? 'nem label');
// }
launchUrl(
Uri.parse(
'https://api.refilc.hu/v3/payment/stripe-create-checkout?product=asdasd'),
mode: LaunchMode.inAppBrowserView,
);
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0), padding: const EdgeInsets.symmetric(vertical: 12.0),
@ -121,6 +134,10 @@ class GithubLoginButton extends StatelessWidget {
// 1. create payment intent on the server // 1. create payment intent on the server
final data = await _createPaymentSheet(); final data = await _createPaymentSheet();
if (data == null) {
throw "API error, can't create payment sheet!";
}
// 2. initialize the payment sheet // 2. initialize the payment sheet
await stripe.Stripe.instance.initPaymentSheet( await stripe.Stripe.instance.initPaymentSheet(
paymentSheetParameters: stripe.SetupPaymentSheetParameters( paymentSheetParameters: stripe.SetupPaymentSheetParameters(
@ -133,9 +150,9 @@ class GithubLoginButton extends StatelessWidget {
customerEphemeralKeySecret: data['ephemeralKey'], customerEphemeralKeySecret: data['ephemeralKey'],
customerId: data['customer'], customerId: data['customer'],
// Extra options // Extra options
applePay: const stripe.PaymentSheetApplePay( // applePay: const stripe.PaymentSheetApplePay(
merchantCountryCode: 'HU', // merchantCountryCode: 'HU',
), // ),
googlePay: const stripe.PaymentSheetGooglePay( googlePay: const stripe.PaymentSheetGooglePay(
merchantCountryCode: 'HU', merchantCountryCode: 'HU',
testEnv: true, testEnv: true,
@ -145,6 +162,7 @@ class GithubLoginButton extends StatelessWidget {
); );
return true; return true;
} catch (e) { } catch (e) {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: $e')), SnackBar(content: Text('Error: $e')),
); );
@ -152,9 +170,8 @@ class GithubLoginButton extends StatelessWidget {
} }
} }
Future<Map<String, String>> _createPaymentSheet() async { Future<Map?> _createPaymentSheet() async {
Map<String, String> asdasd = {}; Map? data = await FilcAPI.createPaymentSheet("refilcplus");
return data;
return asdasd;
} }
} }

View File

@ -100,6 +100,8 @@ extension SettingsLocalization on String {
"fonts": "Fonts", "fonts": "Fonts",
"font_family": "Font Family", "font_family": "Font Family",
"calendar_sync": "Calendar Sync", "calendar_sync": "Calendar Sync",
"choose_account": "Choose Account",
"your_account": "Your Account",
}, },
"hu_hu": { "hu_hu": {
"personal_details": "Személyes információk", "personal_details": "Személyes információk",
@ -198,6 +200,8 @@ extension SettingsLocalization on String {
"fonts": "Betűk", "fonts": "Betűk",
"font_family": "Betűtípus", "font_family": "Betűtípus",
"calendar_sync": "Naptár szinkronizálás", "calendar_sync": "Naptár szinkronizálás",
"choose_account": "Válassz fiókot",
"your_account": "Fiókod",
}, },
"de_de": { "de_de": {
"personal_details": "Persönliche Angaben", "personal_details": "Persönliche Angaben",
@ -295,7 +299,9 @@ extension SettingsLocalization on String {
"show_breaks": "Pausen anzeigen", "show_breaks": "Pausen anzeigen",
"fonts": "Schriftarten", "fonts": "Schriftarten",
"font_family": "Schriftfamilie", "font_family": "Schriftfamilie",
"calendar_sync": "heil hitler", "calendar_sync": "Kalender-Synchronisation",
"choose_account": "Konto auswählen",
"your_account": "Ihr Konto",
}, },
}; };

View File

@ -70,6 +70,7 @@ class CalendarSyncScreenState extends State<CalendarSyncScreen>
late SettingsProvider settingsProvider; late SettingsProvider settingsProvider;
late UserProvider user; late UserProvider user;
late ShareProvider shareProvider; late ShareProvider shareProvider;
late ThirdPartyProvider thirdPartyProvider;
late AnimationController _hideContainersController; late AnimationController _hideContainersController;
@ -87,6 +88,7 @@ class CalendarSyncScreenState extends State<CalendarSyncScreen>
Widget build(BuildContext context) { Widget build(BuildContext context) {
settingsProvider = Provider.of<SettingsProvider>(context); settingsProvider = Provider.of<SettingsProvider>(context);
user = Provider.of<UserProvider>(context); user = Provider.of<UserProvider>(context);
thirdPartyProvider = Provider.of<ThirdPartyProvider>(context);
return AnimatedBuilder( return AnimatedBuilder(
animation: _hideContainersController, animation: _hideContainersController,
@ -164,9 +166,7 @@ class CalendarSyncScreenState extends State<CalendarSyncScreen>
height: 18.0, height: 18.0,
), ),
// choose account if not logged in // choose account if not logged in
if (Provider.of<ThirdPartyProvider>(context) if (thirdPartyProvider.linkedAccounts.isEmpty)
.linkedAccounts
.isEmpty)
Column( Column(
children: [ children: [
SplittedPanel( SplittedPanel(
@ -180,6 +180,8 @@ class CalendarSyncScreenState extends State<CalendarSyncScreen>
await Provider.of<ThirdPartyProvider>(context, await Provider.of<ThirdPartyProvider>(context,
listen: false) listen: false)
.googleSignIn(); .googleSignIn();
setState(() {});
}, },
title: Text( title: Text(
'Google', 'Google',
@ -241,16 +243,121 @@ class CalendarSyncScreenState extends State<CalendarSyncScreen>
], ],
), ),
const SizedBox( // show options if logged in
height: 18.0, if (thirdPartyProvider.linkedAccounts.isNotEmpty)
), Column(
// own paints children: [
SplittedPanel( SplittedPanel(
title: Text('public_paint'.i18n), title: Text('your_account'.i18n),
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
cardPadding: const EdgeInsets.all(4.0), cardPadding: const EdgeInsets.all(4.0),
children: [], children: [
), PanelButton(
onPressed: null,
title: Text(
thirdPartyProvider
.linkedAccounts.first.username,
style: TextStyle(
color: AppColors.of(context)
.text
.withOpacity(.95),
),
),
leading: Image.asset(
'assets/images/ext_logo/${thirdPartyProvider.linkedAccounts.first.type == AccountType.google ? "google" : "apple"}.png',
width: 24.0,
height: 24.0,
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12),
bottom: Radius.circular(12),
),
),
PanelButton(
onPressed: () async {
await thirdPartyProvider.signOutAll();
setState(() {});
},
title: Text(
'change_account'.i18n,
style: TextStyle(
color: AppColors.of(context)
.text
.withOpacity(.95),
),
),
trailing: Icon(
FeatherIcons.chevronRight,
size: 22.0,
color: AppColors.of(context)
.text
.withOpacity(0.95),
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12),
bottom: Radius.circular(12),
),
),
],
),
const SizedBox(
height: 18.0,
),
SplittedPanel(
title: Text('choose_calendar'.i18n),
padding: EdgeInsets.zero,
cardPadding: const EdgeInsets.all(4.0),
children: [
PanelButton(
onPressed: null,
title: Text(
thirdPartyProvider
.linkedAccounts.first.username,
style: TextStyle(
color: AppColors.of(context)
.text
.withOpacity(.95),
),
),
leading: Image.asset(
'assets/images/ext_logo/${thirdPartyProvider.linkedAccounts.first.type == AccountType.google ? "google" : "apple"}.png',
width: 24.0,
height: 24.0,
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12),
bottom: Radius.circular(12),
),
),
PanelButton(
onPressed: () async {
await thirdPartyProvider.signOutAll();
setState(() {});
},
title: Text(
'change_account'.i18n,
style: TextStyle(
color: AppColors.of(context)
.text
.withOpacity(.95),
),
),
trailing: Icon(
FeatherIcons.chevronRight,
size: 22.0,
color: AppColors.of(context)
.text
.withOpacity(0.95),
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12),
bottom: Radius.circular(12),
),
),
],
),
],
),
], ],
), ),
), ),

@ -1 +1 @@
Subproject commit c22b3e0de6042e09ef1d3693ef7b02fd73e778c3 Subproject commit fea4d24e0727099654f3899f715c294af2eb72b5