This commit is contained in:
Hamza-Ayed
2023-11-11 23:02:56 +03:00
parent e4292198c1
commit 8d405c5381
10 changed files with 193 additions and 239 deletions

View File

@@ -2,6 +2,8 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
<application android:label="SEFER" android:name="${applicationName}" android:icon="@mipmap/launcher_icon">
<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as

View File

@@ -7,6 +7,9 @@
<key>NSPhotoLibraryUsageDescription</key>
<string>Explanation of why your app needs access to the photo library.</string>
<key>NSFaceIDUsageDescription</key>
<string>Use Face ID to securely authenticate payment accounts.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app requires access to your microphone to record audio, allowing you to add voice recordings to your photos and videos.</string>
<key>NSCameraUsageDescription</key>

View File

@@ -15,6 +15,7 @@ class AppCredintials {
'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';
static const String chatGPTkeySefer =
'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';
// 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
String getBasicAuthCredentials() {
return base64Encode(utf8.encode(basicAuthCredentials));
}
@@ -31,6 +32,7 @@ class StripeKey {
'sk_test_51O4WTODMEVrOCA5SBgaoSS69nNFRyfZx2Tl5ODswYyjqLpc0RxBHW3hhcP38Tp78TZ1PQoZo7eHFllRiQd3rMHPN00Lr9WD3n2';
}
//
class MyClass {
static const String mapAPIKEY = 'AIzaSyCyfwRXTwSTLOFQSQgN5p7QZgGJVZnEKq0';
static const String twilloRecoveryCode = 'TQF13XUVU2NJ3VFU8JWBWYBS';

View File

@@ -1,15 +1,20 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_paypal/flutter_paypal.dart';
import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:get/get.dart';
import 'package:local_auth/local_auth.dart';
import 'package:ride/constant/credential.dart';
import 'package:ride/controller/home/map_passenger_controller.dart';
import '../../constant/box_name.dart';
import '../../constant/colors.dart';
import '../../constant/info.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../functions/crud.dart';
import '../functions/toast.dart';
class PaymentController extends GetxController {
bool isLoading = false;
@@ -81,14 +86,138 @@ class PaymentController extends GetxController {
late String clientSecret;
Future<void> makePayment(int amount, String currency, Function method) async {
Future<void> makePaymentStripe(
int amount, String currency, Function method) async {
var newAmount = amount * 100;
try {
clientSecret = await getClientSecret(newAmount.toString(), currency);
await initializePaymentSheet(clientSecret);
await Stripe.instance.presentPaymentSheet();
method();
// Check if local authentication is available
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
);
if (didAuthenticate) {
// User authenticated successfully, proceed with payment
clientSecret = await getClientSecret(newAmount.toString(), currency);
await initializePaymentSheet(clientSecret);
await Stripe.instance.presentPaymentSheet();
method();
} else {
// Authentication failed, handle accordingly
print('Authentication failed');
}
} else {
// Local authentication not available, proceed with payment without authentication
clientSecret = await getClientSecret(newAmount.toString(), currency);
await initializePaymentSheet(clientSecret);
await Stripe.instance.presentPaymentSheet();
method();
}
} catch (e) {
rethrow;
}
}
Future<void> makePaymentPayPal(BuildContext context) async {
try {
// Check if local authentication is available
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
);
if (didAuthenticate) {
// User authenticated successfully, proceed with payment
if (selectedAmount != 0) {
print(selectedAmount);
changePromoSheetDialogue();
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) => UsePaypal(
sandboxMode: true,
clientId:
"AW1TdvpSGbIM5iP4HJNI5TyTmwpY9Gv9dYw8_8yW5lYIbCqf326vrkrp0ce9TAqjEGMHiV3OqJM_aRT0",
secretKey:
"EHHtTDjnmTZATYBPiGzZC_AZUfMpMAzj2VZUeqlFUrRJA_C0pQNCxDccB5qoRQSEdcOnnKQhycuOWdP9",
returnURL: "https://samplesite.com/return",
cancelURL: "https://samplesite.com/cancel",
transactions: [
{
"amount": {
//sb-opsju26682403@personal.example.com
"total": '$selectedAmount',
"currency": "USD",
"details": {
"subtotal": '$selectedAmount',
"shipping": '0',
"shipping_discount": 0
}
},
"description": "The payment transaction description.",
"payment_options": const {
"allowed_payment_method": "INSTANT_FUNDING_SOURCE"
},
"item_list": {
"items": [
{
"name": "${AppInformation.appName} Wallet ",
"quantity": 1,
"price": '$selectedAmount',
"currency": "USD"
}
],
// shipping address is not required though
"shipping_address": const {
"recipient_name":
"${AppInformation.appName} Wallet",
"line1": "Shafa Badran",
"line2": "",
"city": "Amman",
"country_code": "JO",
"postal_code": "13112",
"phone": "+962798583052",
"state": "Amman"
},
}
}
],
note: "Contact us for any questions on your order.",
onSuccess: (Map params) async {
print("onSuccess: $params");
await CRUD()
.post(link: AppLink.addPassengersWallet, payload: {
'passenger_id':
box.read(BoxName.passengerID).toString(),
'balance': selectedAmount.toString()
});
changePromoSheetDialogue();
await getPassengerWallet();
},
onError: (error) {
print("onError: $error");
Toast.show(context, ' $error'.tr, AppColor.redColor);
},
onCancel: (params) {
print('cancelled: $params');
Toast.show(context, 'Pyament Cancelled .'.tr,
AppColor.yellowColor);
}),
),
);
} else {
Toast.show(context, 'You will choose one of above !'.tr,
AppColor.redColor);
}
} else {
// Authentication failed, handle accordingly
print('Authentication failed');
}
}
} catch (e) {
rethrow;
}
@@ -135,6 +264,7 @@ class PaymentController extends GetxController {
@override
void onInit() {
getPassengerWallet();
final localAuth = LocalAuthentication();
super.onInit();
}
}

View File

@@ -1,4 +1,3 @@
import 'package:chat_gpt_flutter/chat_gpt_flutter.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ride/constant/colors.dart';
@@ -26,7 +25,7 @@ class HomeScreen extends StatelessWidget {
body: Obx(() => IndexedStack(
index: controller.currentIndex.value,
children: [
HomeView(chatGpt: ChatGpt(apiKey: AppCredintials.chatGPTkey)),
HomeView(),
const ProfileView(),
const StatisticsView(),
const WalletView(),
@@ -72,8 +71,8 @@ class HomeScreen extends StatelessWidget {
}
class HomeView extends StatelessWidget {
const HomeView({super.key, required this.chatGpt});
final ChatGpt chatGpt;
const HomeView({super.key});
@override
Widget build(BuildContext context) {
Map<String, dynamic> data;

View File

@@ -318,105 +318,7 @@ class PassengerWallet extends StatelessWidget {
title: 'Pay with Your PayPal'.tr,
onPressed: () {
if (controller.selectedAmount != 0) {
print(controller.selectedAmount);
controller.changePromoSheetDialogue();
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) =>
UsePaypal(
sandboxMode: true,
clientId:
"AW1TdvpSGbIM5iP4HJNI5TyTmwpY9Gv9dYw8_8yW5lYIbCqf326vrkrp0ce9TAqjEGMHiV3OqJM_aRT0",
secretKey:
"EHHtTDjnmTZATYBPiGzZC_AZUfMpMAzj2VZUeqlFUrRJA_C0pQNCxDccB5qoRQSEdcOnnKQhycuOWdP9",
returnURL:
"https://samplesite.com/return",
cancelURL:
"https://samplesite.com/cancel",
transactions: [
{
"amount": {
//sb-opsju26682403@personal.example.com
"total":
'${controller.selectedAmount}',
"currency": "USD",
"details": {
"subtotal":
'${controller.selectedAmount}',
"shipping": '0',
"shipping_discount": 0
}
},
"description":
"The payment transaction description.",
"payment_options": const {
"allowed_payment_method":
"INSTANT_FUNDING_SOURCE"
},
"item_list": {
"items": [
{
"name":
"${AppInformation.appName} Wallet ",
"quantity": 1,
"price":
'${controller.selectedAmount}',
"currency": "USD"
}
],
// shipping address is not required though
"shipping_address": const {
"recipient_name":
"${AppInformation.appName} Wallet",
"line1": "Shafa Badran",
"line2": "",
"city": "Amman",
"country_code": "JO",
"postal_code": "13112",
"phone": "+962798583052",
"state": "Amman"
},
}
}
],
note:
"Contact us for any questions on your order.",
onSuccess: (Map params) async {
print("onSuccess: $params");
await CRUD().post(
link: AppLink
.addPassengersWallet,
payload: {
'passenger_id': box
.read(BoxName
.passengerID)
.toString(),
'balance': controller
.selectedAmount
.toString()
});
controller
.changePromoSheetDialogue();
await controller
.getPassengerWallet();
},
onError: (error) {
print("onError: $error");
Toast.show(
context,
' $error'.tr,
AppColor.redColor);
},
onCancel: (params) {
print('cancelled: $params');
Toast.show(
context,
'Pyament Cancelled .'.tr,
AppColor.yellowColor);
}),
),
);
controller.makePaymentPayPal(context);
} else {
Toast.show(
context,
@@ -427,9 +329,9 @@ class PassengerWallet extends StatelessWidget {
),
MyElevatedButton(
title: 'Pay with Credit Card'.tr,
onPressed: () => controller.makePayment(
onPressed: () => controller.makePaymentStripe(
controller.selectedAmount as int,
'JOD',
'USD',
() => Get.snackbar('Hi', '')),
),
MyElevatedButton(

View File

@@ -1,14 +1,6 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
_fe_analyzer_shared:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: eb376e9acf6938204f90eb3b1f00b578640d3188b4c8a8ec054f9f479af8d051
url: "https://pub.dev"
source: hosted
version: "64.0.0"
_flutterfire_internals:
dependency: transitive
description:
@@ -17,14 +9,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.5"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: "69f54f967773f6c26c7dcb13e93d7ccee8b17a641689da39e878d5cf13b06893"
url: "https://pub.dev"
source: hosted
version: "6.2.0"
animated_text_kit:
dependency: "direct main"
description:
@@ -73,22 +57,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
build:
dependency: transitive
description:
name: build
sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
build_config:
dependency: transitive
description:
name: build_config
sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1
url: "https://pub.dev"
source: hosted
version: "1.1.1"
cached_network_image:
dependency: transitive
description:
@@ -161,14 +129,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.0"
chat_gpt_flutter:
dependency: "direct main"
description:
name: chat_gpt_flutter
sha256: "38d56435c16e9d8743fcdcc9d361a315e6c0e15b4eb91a8638cca235ffbb03bc"
url: "https://pub.dev"
source: hosted
version: "1.0.13"
checked_yaml:
dependency: transitive
description:
@@ -257,14 +217,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
dart_style:
dependency: transitive
description:
name: dart_style
sha256: abd7625e16f51f554ea244d090292945ec4d4be7bfbaf2ec8cccea568919d334
url: "https://pub.dev"
source: hosted
version: "2.3.3"
dbus:
dependency: transitive
description:
@@ -289,14 +241,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.0"
dio:
dependency: transitive
description:
name: dio
sha256: "7d328c4d898a61efc3cd93655a0955858e29a0aa647f0f9e02d59b3bb275e2e8"
url: "https://pub.dev"
source: hosted
version: "4.0.6"
fake_async:
dependency: transitive
description:
@@ -704,14 +648,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
glob:
dependency: transitive
description:
name: glob
sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
google_fonts:
dependency: "direct main"
description:
@@ -976,14 +912,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.8.1"
json_serializable:
dependency: transitive
description:
name: json_serializable
sha256: aa1f5a8912615733e0fdc7a02af03308933c93235bdc8d50d0b0c8a8ccb0b969
url: "https://pub.dev"
source: hosted
version: "6.7.1"
just_audio:
dependency: transitive
description:
@@ -1016,6 +944,46 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.1"
local_auth:
dependency: "direct main"
description:
name: local_auth
sha256: "7e6c63082e399b61e4af71266b012e767a5d4525dd6e9ba41e174fd42d76e115"
url: "https://pub.dev"
source: hosted
version: "2.1.7"
local_auth_android:
dependency: transitive
description:
name: local_auth_android
sha256: df4ccb3193525b8a60c78a5ca7bf188a47705bcf77bcc837a6b2cf6da64ae0e2
url: "https://pub.dev"
source: hosted
version: "1.0.35"
local_auth_ios:
dependency: transitive
description:
name: local_auth_ios
sha256: "8293faf72ef0ac4710f209edd03916c2d4c1eeab0483bdcf9b2e659c2f7d737b"
url: "https://pub.dev"
source: hosted
version: "1.1.5"
local_auth_platform_interface:
dependency: transitive
description:
name: local_auth_platform_interface
sha256: fc5bd537970a324260fda506cfb61b33ad7426f37a8ea5c461cf612161ebba54
url: "https://pub.dev"
source: hosted
version: "1.0.8"
local_auth_windows:
dependency: transitive
description:
name: local_auth_windows
sha256: "505ba3367ca781efb1c50d3132e44a2446bccc4163427bc203b9b4d8994d97ea"
url: "https://pub.dev"
source: hosted
version: "1.0.10"
location:
dependency: "direct main"
description:
@@ -1104,14 +1072,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
package_config:
dependency: transitive
description:
name: package_config
sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
package_info_plus:
dependency: transitive
description:
@@ -1224,14 +1184,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.7.3"
pretty_dio_logger:
dependency: transitive
description:
name: pretty_dio_logger
sha256: "948f7eeb36e7aa0760b51c1a8e3331d4b21e36fabd39efca81f585ed93893544"
url: "https://pub.dev"
source: hosted
version: "1.2.0-beta-1"
provider:
dependency: transitive
description:
@@ -1240,22 +1192,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.5"
pub_semver:
dependency: transitive
description:
name: pub_semver
sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
pubspec_parse:
dependency: transitive
description:
name: pubspec_parse
sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367
url: "https://pub.dev"
source: hosted
version: "1.2.3"
quiver:
dependency: transitive
description:
@@ -1285,22 +1221,6 @@ packages:
description: flutter
source: sdk
version: "0.0.99"
source_gen:
dependency: transitive
description:
name: source_gen
sha256: fc0da689e5302edb6177fdd964efcb7f58912f43c28c2047a808f5bfff643d16
url: "https://pub.dev"
source: hosted
version: "1.4.0"
source_helper:
dependency: transitive
description:
name: source_helper
sha256: "6adebc0006c37dd63fe05bca0a929b99f06402fc95aa35bf36d67f5c06de01fd"
url: "https://pub.dev"
source: hosted
version: "1.3.4"
source_span:
dependency: transitive
description:
@@ -1581,14 +1501,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
watcher:
dependency: transitive
description:
name: watcher
sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:

View File

@@ -44,7 +44,7 @@ dependencies:
flutter_stripe: ^9.5.0+1
camera: ^0.10.5+5
flutter_widget_from_html: ^0.14.6
chat_gpt_flutter:
local_auth: ^2.1.7

View File

@@ -10,6 +10,7 @@
#include <firebase_core/firebase_core_plugin_c_api.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <geolocator_windows/geolocator_windows.h>
#include <local_auth_windows/local_auth_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
@@ -21,6 +22,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
GeolocatorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("GeolocatorWindows"));
LocalAuthPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("LocalAuthPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}

View File

@@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
firebase_core
flutter_secure_storage_windows
geolocator_windows
local_auth_windows
url_launcher_windows
)