This commit is contained in:
Hamza-Ayed
2023-12-03 10:35:27 +03:00
parent e095cf564a
commit 2501292424
50 changed files with 1841 additions and 730 deletions

View File

@@ -5,7 +5,6 @@ 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';
@@ -53,16 +52,51 @@ class PaymentController extends GetxController {
update();
}
void onChangedPaymentMethodWallet(bool? value) {
isWalletChecked = !isWalletChecked;
isWalletChecked ? isCashChecked = false : isCashChecked = true;
addPassengerWallet() async {
isLoading = true;
update();
// double sallaryAccountNowBeforeAdding =
// double.parse(box.read(BoxName.passengerWalletTotal).toString());
await CRUD().post(link: AppLink.addPassengersWallet, payload: {
'passenger_id': box.read(BoxName.passengerID).toString(),
'balance': selectedAmount.toString()
}).then((value) {
getPassengerWallet();
// sallaryAccountNowBeforeAdding = sallaryAccountNowBeforeAdding +
// double.parse(selectedAmount.toString());
// box.write(BoxName.passengerWalletTotal, sallaryAccountNowBeforeAdding);
});
isLoading = false;
update();
}
void onChangedPaymentMethodWallet(bool? value) {
if (box.read(BoxName.passengerWalletTotal) == null ||
double.parse(box.read(BoxName.passengerWalletTotal).toString()) <
totalPassenger) {
isWalletChecked = false;
isWalletChecked ? isCashChecked = true : isCashChecked = true;
update();
} else {
isWalletChecked = !isWalletChecked;
isWalletChecked ? isCashChecked = false : isCashChecked = true;
update();
}
}
void onChangedPaymentMethodCash(bool? value) {
isCashChecked = !isCashChecked;
isCashChecked ? isWalletChecked = false : isWalletChecked = true;
update();
if (box.read(BoxName.passengerWalletTotal) == null ||
double.parse(box.read(BoxName.passengerWalletTotal)) < totalPassenger) {
isWalletChecked = false;
isCashChecked = !isCashChecked;
isCashChecked ? isWalletChecked = false : isWalletChecked = false;
update();
} else {
isCashChecked = !isCashChecked;
isCashChecked ? isWalletChecked = false : isWalletChecked = true;
update();
}
}
void applyPromoCodeToPassenger() async {
@@ -120,6 +154,72 @@ class PaymentController extends GetxController {
}
}
Future<void> initializePaymentSheet(String clientSecret) async {
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
// intentConfiguration: IntentConfiguration.fromJson({}),
// applePay: const PaymentSheetApplePay(merchantCountryCode: 'US'),
// googlePay: const PaymentSheetGooglePay(merchantCountryCode: 'US'),
paymentIntentClientSecret: clientSecret,
merchantDisplayName: 'Sefer',
billingDetails: BillingDetails(
name: box.read(BoxName.nameDriver) == null
? box.read(BoxName.name).toString()
: box.read(BoxName.nameDriver).toString(),
email: box.read(BoxName.emailDriver) == null
? box.read(BoxName.email).toString()
: box.read(BoxName.emailDriver).toString(),
phone: box.read(BoxName.phoneDriver) == null
? box.read(BoxName.phone).toString()
: box.read(BoxName.phoneDriver).toString(),
address: const Address(
city: 'city',
country: 'United States',
line1: '',
line2: '',
postalCode: '12345',
state: 'Boston')),
allowsDelayedPaymentMethods: true,
customerEphemeralKeySecret: Stripe.merchantIdentifier,
appearance: const PaymentSheetAppearance(
shapes: PaymentSheetShape(borderRadius: 12),
colors: PaymentSheetAppearanceColors(
background: AppColor.secondaryColor,
),
),
billingDetailsCollectionConfiguration:
const BillingDetailsCollectionConfiguration(
name: CollectionMode.always,
phone: CollectionMode.always,
email: CollectionMode.always,
),
),
);
}
Future<String> getClientSecret(String amount, currency) async {
var res = await CRUD().postStripe(
link: 'https://api.stripe.com/v1/payment_intents',
payload: {'amount': amount, 'currency': currency},
);
// Convert the res object to a JSON object
final jsonResponse = jsonDecode(res);
print(jsonResponse);
// Check if the client_secret property exists and is not null
if (jsonResponse.containsKey('client_secret') &&
jsonResponse['client_secret'] != null) {
// Return the client_secret property
return jsonResponse['client_secret'] as String;
} else {
throw Exception('Failed to fetch client secret');
}
}
Future<void> configure3dSecureFuture() async {
await Stripe.instance.openApplePaySetup();
}
Future<void> makePaymentPayPal(BuildContext context) async {
try {
// Check if local authentication is available
@@ -189,12 +289,7 @@ class PaymentController extends GetxController {
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()
});
addPassengerWallet();
changePromoSheetDialogue();
await getPassengerWallet();
},
@@ -223,44 +318,6 @@ class PaymentController extends GetxController {
}
}
Future<void> initializePaymentSheet(String clientSecret) async {
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: clientSecret,
merchantDisplayName: 'Sefer',
billingDetails: BillingDetails(
name: box.read(BoxName.nameDriver).toString(),
email: box.read(BoxName.emailDriver).toString(),
phone: box.read(BoxName.phoneDriver).toString(),
),
billingDetailsCollectionConfiguration:
const BillingDetailsCollectionConfiguration(
name: CollectionMode.always,
phone: CollectionMode.always,
email: CollectionMode.always,
)),
);
}
Future<String> getClientSecret(String amount, currency) async {
var res = await CRUD().postStripe(
link: 'https://api.stripe.com/v1/payment_intents',
payload: {'amount': amount, 'currency': currency},
);
// Convert the res object to a JSON object
final jsonResponse = jsonDecode(res);
print(jsonResponse);
// Check if the client_secret property exists and is not null
if (jsonResponse.containsKey('client_secret') &&
jsonResponse['client_secret'] != null) {
// Return the client_secret property
return jsonResponse['client_secret'] as String;
} else {
throw Exception('Failed to fetch client secret');
}
}
@override
void onInit() {
getPassengerWallet();