+ quotation provider

This commit is contained in:
Stephan D
2025-12-11 01:13:13 +01:00
parent bdf766075e
commit a4481fb63d
102 changed files with 2242 additions and 246 deletions

View File

@@ -0,0 +1,54 @@
import 'package:flutter/material.dart';
import 'package:pshared/api/requests/payment/quote.dart';
import 'package:pshared/data/mapper/payment/intent/payment.dart';
import 'package:pshared/models/payment/intent.dart';
import 'package:pshared/models/payment/quote.dart';
import 'package:pshared/provider/organizations.dart';
import 'package:pshared/provider/resource.dart';
import 'package:pshared/service/payment/quotation.dart';
import 'package:uuid/uuid.dart';
class QuotationProvider extends ChangeNotifier {
Resource<PaymentQuote> _quotation = Resource(data: null, isLoading: false, error: null);
late OrganizationsProvider _organizations;
bool _isLoaded = false;
void update(OrganizationsProvider venue) {
_organizations = venue;
}
PaymentQuote? get quotation => _quotation.data;
bool get isReady => _isLoaded && !_quotation.isLoading && _quotation.error == null;
Future<PaymentQuote?> getQuotation(PaymentIntent intent) async {
if (!_organizations.isOrganizationSet) throw StateError('Organization is not set');
try {
_quotation = _quotation.copyWith(isLoading: true, error: null);
final response = await QuotationService.getQuotation(
_organizations.current.id,
QuotePaymentRequest(
idempotencyKey: Uuid().v4(),
intent: intent.toDTO(),
),
);
_isLoaded = true;
_quotation = _quotation.copyWith(data: response, isLoading: false);
} catch (e) {
_quotation = _quotation.copyWith(
error: e is Exception ? e : Exception(e.toString()),
isLoading: false,
);
}
notifyListeners();
return _quotation.data;
}
void reset() {
_quotation = Resource(data: null, isLoading: false, error: null);
_isLoaded = false;
notifyListeners();
}
}