11/12/1
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user