diff --git a/refilc/lib/main.dart b/refilc/lib/main.dart index 91b569f..fe6a3ae 100644 --- a/refilc/lib/main.dart +++ b/refilc/lib/main.dart @@ -13,6 +13,7 @@ import 'package:flutter/services.dart'; import 'package:refilc_mobile_ui/screens/error_screen.dart'; import 'package:refilc_mobile_ui/screens/error_report_screen.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; +import 'package:flutter_stripe/flutter_stripe.dart' as stripe; // import 'package:firebase_core/firebase_core.dart'; // import 'firebase_options.dart'; @@ -32,6 +33,10 @@ void main() async { BackgroundFetch.registerHeadlessTask(backgroundHeadlessTask); + // initialize stripe key + stripe.Stripe.publishableKey = + 'pk_live_51OWSV2HW2TAy5tA6EELuXtpG6ombCCrOFbvz2fDwZlqLT42Ql64CfxptWem8NjN1dhnE6jaI77TRsVZbF8gfd29Q00OGMQRGqm'; + // Run App runApp(App( database: startup.database, diff --git a/refilc/pubspec.yaml b/refilc/pubspec.yaml index c5d9b22..e89da14 100644 --- a/refilc/pubspec.yaml +++ b/refilc/pubspec.yaml @@ -77,6 +77,7 @@ dependencies: extension_google_sign_in_as_googleapis_auth: ^2.0.12 maps_launcher: ^2.2.0 google_fonts: ^6.1.0 + flutter_stripe: ^10.0.0 dev_dependencies: flutter_lints: ^3.0.1 diff --git a/refilc_mobile_ui/lib/premium/components/github_button.dart b/refilc_mobile_ui/lib/premium/components/github_button.dart index 3801206..2a4b249 100644 --- a/refilc_mobile_ui/lib/premium/components/github_button.dart +++ b/refilc_mobile_ui/lib/premium/components/github_button.dart @@ -1,3 +1,4 @@ +import 'package:flutter_stripe/flutter_stripe.dart' as stripe; import 'package:refilc/theme/colors/colors.dart'; import 'package:refilc_plus/providers/premium_provider.dart'; import 'package:refilc_plus/ui/mobile/premium/activation_view/activation_view.dart'; @@ -20,25 +21,29 @@ class GithubLoginButton extends StatelessWidget { shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)), child: InkWell( borderRadius: BorderRadius.circular(14.0), - onTap: () { - if (premium.hasPremium) { - premium.auth.refreshAuth(removePremium: true); - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text( - "reFilc+ támogatás deaktiválva!", - style: TextStyle( - color: AppColors.of(context).text, - fontWeight: FontWeight.bold, - fontSize: 18.0), - ), - backgroundColor: Theme.of(context).scaffoldBackgroundColor, - )); - return; - } + onTap: () async { + // if (premium.hasPremium) { + // premium.auth.refreshAuth(removePremium: true); + // ScaffoldMessenger.of(context).showSnackBar(SnackBar( + // content: Text( + // "reFilc+ támogatás deaktiválva!", + // style: TextStyle( + // color: AppColors.of(context).text, + // fontWeight: FontWeight.bold, + // fontSize: 18.0), + // ), + // backgroundColor: Theme.of(context).scaffoldBackgroundColor, + // )); + // return; + // } - Navigator.of(context).push(MaterialPageRoute(builder: (context) { - return const PremiumActivationView(); - })); + // Navigator.of(context).push(MaterialPageRoute(builder: (context) { + // return const PremiumActivationView(); + // })); + bool initFinished = await initPaymentSheet(context); + if (initFinished) { + await stripe.Stripe.instance.presentPaymentSheet(); + } }, child: Padding( padding: const EdgeInsets.symmetric(vertical: 12.0), @@ -110,4 +115,46 @@ class GithubLoginButton extends StatelessWidget { ), ); } + + Future initPaymentSheet(BuildContext context) async { + try { + // 1. create payment intent on the server + final data = await _createPaymentSheet(); + + // 2. initialize the payment sheet + await stripe.Stripe.instance.initPaymentSheet( + paymentSheetParameters: stripe.SetupPaymentSheetParameters( + // Set to true for custom flow + customFlow: false, + // Main params + merchantDisplayName: 'reFilc', + paymentIntentClientSecret: data['paymentIntent'], + // Customer keys + customerEphemeralKeySecret: data['ephemeralKey'], + customerId: data['customer'], + // Extra options + applePay: const stripe.PaymentSheetApplePay( + merchantCountryCode: 'HU', + ), + googlePay: const stripe.PaymentSheetGooglePay( + merchantCountryCode: 'HU', + testEnv: true, + ), + style: ThemeMode.system, + ), + ); + return true; + } catch (e) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Error: $e')), + ); + rethrow; + } + } + + Future> _createPaymentSheet() async { + Map asdasd = {}; + + return asdasd; + } } diff --git a/refilc_mobile_ui/pubspec.yaml b/refilc_mobile_ui/pubspec.yaml index 18a381d..32762f7 100644 --- a/refilc_mobile_ui/pubspec.yaml +++ b/refilc_mobile_ui/pubspec.yaml @@ -64,6 +64,7 @@ dependencies: uuid: ^4.3.3 maps_launcher: ^2.2.0 google_fonts: ^6.1.0 + flutter_stripe: ^10.0.0 dev_dependencies: flutter_lints: ^3.0.1 diff --git a/refilc_plus b/refilc_plus index 960ab22..c22b3e0 160000 --- a/refilc_plus +++ b/refilc_plus @@ -1 +1 @@ -Subproject commit 960ab223654209f75b5c412a8f153e69968f7192 +Subproject commit c22b3e0de6042e09ef1d3693ef7b02fd73e778c3