57 lines
1.6 KiB
Dart
57 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pshared/models/payment/status.dart';
|
|
|
|
import 'package:pweb/generated/i18n/app_localizations.dart';
|
|
|
|
|
|
class StatusView {
|
|
final String label;
|
|
final Color color;
|
|
|
|
const StatusView(this.label, this.color);
|
|
}
|
|
|
|
StatusView statusView(AppLocalizations l10n, String? raw) {
|
|
final trimmed = (raw ?? '').trim();
|
|
final upper = trimmed.toUpperCase();
|
|
final normalized = upper.startsWith('PAYMENT_STATE_')
|
|
? upper.substring('PAYMENT_STATE_'.length)
|
|
: upper;
|
|
|
|
switch (normalized) {
|
|
case 'SETTLED':
|
|
return StatusView(l10n.paymentStatusPending, Colors.orange);
|
|
case 'SUCCESS':
|
|
return StatusView(l10n.paymentStatusSuccessful, Colors.green);
|
|
case 'FUNDS_RESERVED':
|
|
return StatusView(l10n.paymentStatusReserved, Colors.blue);
|
|
case 'ACCEPTED':
|
|
return StatusView(l10n.paymentStatusProcessing, Colors.orange);
|
|
case 'SUBMITTED':
|
|
return StatusView(l10n.paymentStatusProcessing, Colors.blue);
|
|
case 'FAILED':
|
|
return StatusView(l10n.paymentStatusFailed, Colors.red);
|
|
case 'CANCELLED':
|
|
return StatusView(l10n.paymentStatusCancelled, Colors.grey);
|
|
case 'UNSPECIFIED':
|
|
case '':
|
|
default:
|
|
return StatusView(l10n.paymentStatusPending, Colors.grey);
|
|
}
|
|
}
|
|
|
|
StatusView operationStatusView(
|
|
AppLocalizations l10n,
|
|
OperationStatus status,
|
|
) {
|
|
switch (status) {
|
|
case OperationStatus.success:
|
|
return statusView(l10n, 'SUCCESS');
|
|
case OperationStatus.error:
|
|
return statusView(l10n, 'FAILED');
|
|
case OperationStatus.processing:
|
|
return statusView(l10n, 'ACCEPTED');
|
|
}
|
|
}
|