payment quotation v2 + payment orchestration v2 draft
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
81
frontend/pshared/lib/models/payment/state.dart
Normal file
81
frontend/pshared/lib/models/payment/state.dart
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user