improved logging in callbacks

This commit is contained in:
Stephan D
2026-03-03 01:07:35 +01:00
parent b10ec79fe0
commit bae4cd6e35
45 changed files with 226 additions and 146 deletions

View File

@@ -7,12 +7,15 @@ import 'package:pshared/provider/resource.dart';
import 'package:pshared/service/payment/service.dart';
import 'package:pshared/utils/exception.dart';
class PaymentProvider extends ChangeNotifier {
late OrganizationsProvider _organization;
late QuotationProvider _quotation;
Resource<Payment> _payment = Resource(data: null, isLoading: false, error: null);
Resource<Payment> _payment = Resource(
data: null,
isLoading: false,
error: null,
);
bool _isLoaded = false;
void update(OrganizationsProvider organization, QuotationProvider quotation) {
@@ -23,15 +26,21 @@ class PaymentProvider extends ChangeNotifier {
Payment? get payment => _payment.data;
bool get isLoading => _payment.isLoading;
Exception? get error => _payment.error;
bool get isReady => _isLoaded && !_payment.isLoading && _payment.error == null;
bool get isReady =>
_isLoaded && !_payment.isLoading && _payment.error == null;
void _setResource(Resource<Payment> payment) {
_payment = payment;
notifyListeners();
}
Future<Payment?> pay({String? idempotencyKey, Map<String, String>? metadata}) async {
if (!_organization.isOrganizationSet) throw StateError('Organization is not set');
Future<Payment?> pay({
String? idempotencyKey,
String? clientPaymentRef,
Map<String, String>? metadata,
}) async {
if (!_organization.isOrganizationSet)
throw StateError('Organization is not set');
final quoteRef = _quotation.quotation?.quoteRef;
if (quoteRef == null || quoteRef.isEmpty) {
throw StateError('Quotation reference is not set');
@@ -49,12 +58,17 @@ class PaymentProvider extends ChangeNotifier {
_organization.current.id,
quoteRef,
idempotencyKey: resolvedIdempotencyKey,
clientPaymentRef: clientPaymentRef,
metadata: metadata,
);
_isLoaded = true;
_setResource(_payment.copyWith(data: response, isLoading: false, error: null));
_setResource(
_payment.copyWith(data: response, isLoading: false, error: null),
);
} catch (e) {
_setResource(_payment.copyWith(data: null, error: toException(e), isLoading: false));
_setResource(
_payment.copyWith(data: null, error: toException(e), isLoading: false),
);
}
return _payment.data;
}