|
|
|
|
@ -1,19 +1,14 @@
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/scheduler.dart';
|
|
|
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
|
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
|
|
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
|
|
|
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
|
|
|
|
import 'package:mc_common_app/repositories/payments_repo.dart';
|
|
|
|
|
import 'package:mc_common_app/services/payments_service.dart';
|
|
|
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
|
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
|
|
|
import 'package:mc_common_app/utils/utils.dart';
|
|
|
|
|
import 'package:mc_common_app/view_models/ad_view_model.dart';
|
|
|
|
|
import 'package:mc_common_app/view_models/dashboard_view_model_customer.dart';
|
|
|
|
|
import 'package:mc_common_app/view_models/dashboard_view_model_provider.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
|
|
|
|
|
@ -66,7 +61,7 @@ class PaymentVM extends ChangeNotifier {
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log("Could not get AdVM reference: $e");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (selectedPaymentMethod) {
|
|
|
|
|
case PaymentMethods.mada:
|
|
|
|
|
break;
|
|
|
|
|
@ -84,8 +79,14 @@ class PaymentVM extends ChangeNotifier {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> verifyPayments(
|
|
|
|
|
{required BuildContext context, required int id, List<int>? appointmentIds, required int paymentTypeId, required Function() onVerified, bool isForAppointment = false}) async {
|
|
|
|
|
Future<void> verifyPayments({
|
|
|
|
|
required BuildContext context,
|
|
|
|
|
required int id,
|
|
|
|
|
List<int>? appointmentIds,
|
|
|
|
|
required int paymentTypeId,
|
|
|
|
|
required Function() onVerified,
|
|
|
|
|
bool isForAppointment = false,
|
|
|
|
|
}) async {
|
|
|
|
|
try {
|
|
|
|
|
// Utils.showLoading(context); // Commented out: causes BuildContext error after screen is popped
|
|
|
|
|
bool isPaid = await paymentRepo.verifyPayment(
|
|
|
|
|
@ -209,7 +210,7 @@ class PaymentVM extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
void onRequestPaymentSuccess(BuildContext context) {
|
|
|
|
|
log("🔵 onRequestPaymentSuccess called");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait a bit for browser to close and context to be ready
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 500), () {
|
|
|
|
|
log("Attempting navigation after delay...");
|
|
|
|
|
@ -218,20 +219,20 @@ class PaymentVM extends ChangeNotifier {
|
|
|
|
|
log("❌ navigatorKey.currentState is still null after delay");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nav.pushNamedAndRemoveUntil(
|
|
|
|
|
AppRoutes.dashboard,
|
|
|
|
|
(route) => false,
|
|
|
|
|
arguments: DashboardRouteEnum.fromRequestPayment,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log("✅ Navigation executed successfully");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onAdsPaymentSuccess(BuildContext context) {
|
|
|
|
|
log("🔵 onAdsPaymentSuccess called");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update local ad state immediately so UI reflects payment success
|
|
|
|
|
if (_cachedAdVM != null && currentAdId != -1) {
|
|
|
|
|
try {
|
|
|
|
|
@ -248,7 +249,7 @@ class PaymentVM extends ChangeNotifier {
|
|
|
|
|
log("⚠️ Could not update local ad state: $e");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait a bit for browser to close and context to be ready
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 500), () {
|
|
|
|
|
log("Attempting navigation after delay...");
|
|
|
|
|
@ -257,20 +258,20 @@ class PaymentVM extends ChangeNotifier {
|
|
|
|
|
log("❌ navigatorKey.currentState is still null after delay");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nav.pushNamedAndRemoveUntil(
|
|
|
|
|
AppRoutes.dashboard,
|
|
|
|
|
(route) => false,
|
|
|
|
|
arguments: DashboardRouteEnum.fromAdsPayment,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log("✅ Navigation executed successfully");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onAdReservePaymentSuccess(BuildContext context) {
|
|
|
|
|
log("🔵 onAdReservePaymentSuccess called");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait a bit for browser to close and context to be ready
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 500), () {
|
|
|
|
|
log("Attempting navigation after delay...");
|
|
|
|
|
@ -279,20 +280,20 @@ class PaymentVM extends ChangeNotifier {
|
|
|
|
|
log("❌ navigatorKey.currentState is still null after delay");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nav.pushNamedAndRemoveUntil(
|
|
|
|
|
AppRoutes.dashboard,
|
|
|
|
|
(route) => false,
|
|
|
|
|
arguments: DashboardRouteEnum.fromReserveAdsPayment,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log("✅ Navigation executed successfully");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onSubscriptionPaymentSuccess() {
|
|
|
|
|
log("🔵 onSubscriptionPaymentSuccess called");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait a bit for browser to close and context to be ready
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 500), () {
|
|
|
|
|
log("Attempting navigation after delay...");
|
|
|
|
|
@ -301,19 +302,19 @@ class PaymentVM extends ChangeNotifier {
|
|
|
|
|
log("❌ navigatorKey.currentState is still null after delay");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nav.pushNamedAndRemoveUntil(
|
|
|
|
|
AppRoutes.dashboard,
|
|
|
|
|
(route) => false,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log("✅ Navigation executed successfully");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onAppointmentSuccess(BuildContext context) {
|
|
|
|
|
log("🔵 onAppointmentSuccess called");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait a bit for browser to close and context to be ready
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 500), () {
|
|
|
|
|
log("Attempting navigation after delay...");
|
|
|
|
|
@ -322,13 +323,13 @@ class PaymentVM extends ChangeNotifier {
|
|
|
|
|
log("❌ navigatorKey.currentState is still null after delay");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nav.pushNamedAndRemoveUntil(
|
|
|
|
|
AppRoutes.dashboard,
|
|
|
|
|
(route) => false,
|
|
|
|
|
arguments: DashboardRouteEnum.fromAppointmentPayment,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log("✅ Navigation executed successfully");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|