payment quotation v2 + payment orchestration v2 draft

This commit is contained in:
Stephan D
2026-02-24 13:01:35 +01:00
parent 0646f55189
commit 6444813f38
289 changed files with 17005 additions and 16065 deletions

View File

@@ -1,10 +1,11 @@
import 'package:pshared/models/payment/quote/quote.dart';
import 'package:pshared/models/payment/state.dart';
class Payment {
final String? paymentRef;
final String? idempotencyKey;
final String? state;
final PaymentOrchestrationState orchestrationState;
final String? failureCode;
final String? failureReason;
final PaymentQuote? lastQuote;
@@ -15,6 +16,7 @@ class Payment {
required this.paymentRef,
required this.idempotencyKey,
required this.state,
required this.orchestrationState,
required this.failureCode,
required this.failureReason,
required this.lastQuote,
@@ -22,9 +24,12 @@ class Payment {
required this.createdAt,
});
bool get isPending => orchestrationState.isPending;
bool get isTerminal => orchestrationState.isTerminal;
bool get isFailure {
if ((failureCode ?? '').trim().isNotEmpty) return true;
final normalized = (state ?? '').trim().toLowerCase();
return normalized.contains('fail') || normalized.contains('cancel');
return orchestrationState == PaymentOrchestrationState.failed;
}
}

View File

@@ -0,0 +1,81 @@
enum PaymentOrchestrationState {
created,
executing,
needsAttention,
settled,
failed,
unspecified,
}
PaymentOrchestrationState paymentOrchestrationStateFromValue(String? value) {
final normalized = _normalizePaymentState(value);
switch (normalized) {
case 'CREATED':
case 'ACCEPTED':
return PaymentOrchestrationState.created;
case 'EXECUTING':
case 'PROCESSING':
case 'FUNDS_RESERVED':
case 'SUBMITTED':
return PaymentOrchestrationState.executing;
case 'NEEDS_ATTENTION':
return PaymentOrchestrationState.needsAttention;
case 'SETTLED':
case 'SUCCESS':
return PaymentOrchestrationState.settled;
case 'FAILED':
case 'CANCELLED':
return PaymentOrchestrationState.failed;
default:
return PaymentOrchestrationState.unspecified;
}
}
String paymentOrchestrationStateToValue(PaymentOrchestrationState state) {
switch (state) {
case PaymentOrchestrationState.created:
return 'orchestration_state_created';
case PaymentOrchestrationState.executing:
return 'orchestration_state_executing';
case PaymentOrchestrationState.needsAttention:
return 'orchestration_state_needs_attention';
case PaymentOrchestrationState.settled:
return 'orchestration_state_settled';
case PaymentOrchestrationState.failed:
return 'orchestration_state_failed';
case PaymentOrchestrationState.unspecified:
return 'orchestration_state_unspecified';
}
}
extension PaymentOrchestrationStateX on PaymentOrchestrationState {
bool get isTerminal {
switch (this) {
case PaymentOrchestrationState.settled:
case PaymentOrchestrationState.failed:
return true;
case PaymentOrchestrationState.created:
case PaymentOrchestrationState.executing:
case PaymentOrchestrationState.needsAttention:
case PaymentOrchestrationState.unspecified:
return false;
}
}
bool get isPending => !isTerminal;
}
String _normalizePaymentState(String? value) {
final trimmed = (value ?? '').trim().toUpperCase();
if (trimmed.isEmpty) {
return '';
}
if (trimmed.startsWith('ORCHESTRATION_STATE_')) {
return trimmed.substring('ORCHESTRATION_STATE_'.length);
}
if (trimmed.startsWith('PAYMENT_STATE_')) {
return trimmed.substring('PAYMENT_STATE_'.length);
}
return trimmed;
}

View File

@@ -1,12 +1,11 @@
import 'package:flutter/foundation.dart';
import 'package:pshared/config/web.dart';
import 'package:pshared/config/constants.dart';
abstract class Storable {
String get id;
DateTime get createdAt;
DateTime get updatedAt;
DateTime get updatedAt;
}
@immutable
@@ -23,11 +22,11 @@ class _StorableImp implements Storable {
required this.createdAt,
required this.updatedAt,
});
}
Storable newStorable({String? id, DateTime? createdAt, DateTime? updatedAt}) => _StorableImp(
id: id ?? Constants.nilObjectRef,
createdAt: createdAt ?? DateTime.now().toUtc(),
updatedAt: updatedAt ?? DateTime.now().toUtc(),
);
Storable newStorable({String? id, DateTime? createdAt, DateTime? updatedAt}) =>
_StorableImp(
id: id ?? Constants.nilObjectRef,
createdAt: createdAt ?? DateTime.now().toUtc(),
updatedAt: updatedAt ?? DateTime.now().toUtc(),
);