verification before payment and email fixes
This commit is contained in:
@@ -4,16 +4,14 @@ import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/models/payment/status.dart';
|
||||
import 'package:pshared/provider/payment/payments.dart';
|
||||
|
||||
import 'package:pweb/app/router/payout_routes.dart';
|
||||
import 'package:pweb/controllers/payment_details.dart';
|
||||
import 'package:pweb/pages/report/details/content.dart';
|
||||
import 'package:pweb/pages/report/details/states/error.dart';
|
||||
import 'package:pweb/pages/report/details/states/not_found.dart';
|
||||
import 'package:pweb/utils/report/download_act.dart';
|
||||
import 'package:pweb/utils/report/payment_mapper.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
@@ -26,39 +24,48 @@ class PaymentDetailsPage extends StatelessWidget {
|
||||
required this.paymentId,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProxyProvider<PaymentsProvider, PaymentDetailsController>(
|
||||
create: (_) => PaymentDetailsController(paymentId: paymentId),
|
||||
update: (_, payments, controller) => controller!
|
||||
..update(payments, paymentId),
|
||||
child: const _PaymentDetailsView(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PaymentDetailsView extends StatelessWidget {
|
||||
const _PaymentDetailsView();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Consumer<PaymentsProvider>(
|
||||
builder: (context, provider, child) {
|
||||
child: Consumer<PaymentDetailsController>(
|
||||
builder: (context, controller, child) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
if (provider.isLoading) {
|
||||
if (controller.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (provider.error != null) {
|
||||
if (controller.error != null) {
|
||||
return PaymentDetailsError(
|
||||
message: provider.error?.toString() ?? loc.noErrorInformation,
|
||||
onRetry: () => provider.refresh(),
|
||||
message: controller.error?.toString() ?? loc.noErrorInformation,
|
||||
onRetry: () => controller.refresh(),
|
||||
);
|
||||
}
|
||||
|
||||
final payment = _findPayment(provider.payments, paymentId);
|
||||
final payment = controller.payment;
|
||||
if (payment == null) {
|
||||
return PaymentDetailsNotFound(onBack: () => _handleBack(context));
|
||||
}
|
||||
|
||||
final status = statusFromPayment(payment);
|
||||
final paymentRef = payment.paymentRef ?? '';
|
||||
final canDownload = status == OperationStatus.success &&
|
||||
paymentRef.trim().isNotEmpty;
|
||||
|
||||
return PaymentDetailsContent(
|
||||
payment: payment,
|
||||
onBack: () => _handleBack(context),
|
||||
onDownloadAct: canDownload
|
||||
? () => downloadPaymentAct(context, paymentRef)
|
||||
onDownloadAct: controller.canDownload
|
||||
? () => downloadPaymentAct(context, payment.paymentRef ?? '')
|
||||
: null,
|
||||
);
|
||||
},
|
||||
@@ -66,16 +73,6 @@ class PaymentDetailsPage extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Payment? _findPayment(List<Payment> payments, String paymentId) {
|
||||
final trimmed = paymentId.trim();
|
||||
if (trimmed.isEmpty) return null;
|
||||
for (final payment in payments) {
|
||||
if (payment.paymentRef == trimmed) return payment;
|
||||
if (payment.idempotencyKey == trimmed) return payment;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void _handleBack(BuildContext context) {
|
||||
final router = GoRouter.of(context);
|
||||
if (router.canPop()) {
|
||||
|
||||
Reference in New Issue
Block a user