Quotation
This commit is contained in:
@@ -2,7 +2,7 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
import 'package:pshared/provider/payment/quotation.dart';
|
||||
import 'package:pshared/provider/payment/quotation/quotation.dart';
|
||||
import 'package:pshared/provider/resource.dart';
|
||||
import 'package:pshared/service/payment/service.dart';
|
||||
|
||||
@@ -31,18 +31,23 @@ class PaymentProvider extends ChangeNotifier {
|
||||
|
||||
Future<Payment?> pay({String? idempotencyKey, Map<String, String>? metadata}) async {
|
||||
if (!_organization.isOrganizationSet) throw StateError('Organization is not set');
|
||||
if (!_quotation.isReady) throw StateError('Quotation is not ready');
|
||||
final quoteRef = _quotation.quotation?.quoteRef;
|
||||
if (quoteRef == null || quoteRef.isEmpty) {
|
||||
throw StateError('Quotation reference is not set');
|
||||
}
|
||||
final expiresAt = _quotation.quoteExpiresAt;
|
||||
if (expiresAt != null && expiresAt.isBefore(DateTime.now().toUtc())) {
|
||||
throw StateError('Quotation is expired');
|
||||
}
|
||||
|
||||
_setResource(_payment.copyWith(isLoading: true, error: null));
|
||||
try {
|
||||
final resolvedIdempotencyKey =
|
||||
idempotencyKey ?? _quotation.quotation?.idempotencyKey;
|
||||
final response = await PaymentService.pay(
|
||||
_organization.current.id,
|
||||
quoteRef,
|
||||
idempotencyKey: idempotencyKey,
|
||||
idempotencyKey: resolvedIdempotencyKey,
|
||||
metadata: metadata,
|
||||
);
|
||||
_isLoaded = true;
|
||||
|
||||
Reference in New Issue
Block a user