SEND063
This commit is contained in:
56
frontend/pshared/lib/data/dto/payment/operation.dart
Normal file
56
frontend/pshared/lib/data/dto/payment/operation.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
class PaymentOperationDTO {
|
||||
final String? stepRef;
|
||||
final String? operationRef;
|
||||
final String? code;
|
||||
final String? state;
|
||||
final String? label;
|
||||
final String? failureCode;
|
||||
final String? failureReason;
|
||||
final String? startedAt;
|
||||
final String? completedAt;
|
||||
|
||||
const PaymentOperationDTO({
|
||||
this.stepRef,
|
||||
this.operationRef,
|
||||
this.code,
|
||||
this.state,
|
||||
this.label,
|
||||
this.failureCode,
|
||||
this.failureReason,
|
||||
this.startedAt,
|
||||
this.completedAt,
|
||||
});
|
||||
|
||||
factory PaymentOperationDTO.fromJson(Map<String, dynamic> json) =>
|
||||
PaymentOperationDTO(
|
||||
stepRef: _asString(json['stepRef'] ?? json['step_ref']),
|
||||
operationRef: _asString(json['operationRef'] ?? json['operation_ref']),
|
||||
code: _asString(json['code']),
|
||||
state: _asString(json['state']),
|
||||
label: _asString(json['label']),
|
||||
failureCode: _asString(json['failureCode'] ?? json['failure_code']),
|
||||
failureReason: _asString(
|
||||
json['failureReason'] ?? json['failure_reason'],
|
||||
),
|
||||
startedAt: _asString(json['startedAt'] ?? json['started_at']),
|
||||
completedAt: _asString(json['completedAt'] ?? json['completed_at']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'stepRef': stepRef,
|
||||
'operationRef': operationRef,
|
||||
'code': code,
|
||||
'state': state,
|
||||
'label': label,
|
||||
'failureCode': failureCode,
|
||||
'failureReason': failureReason,
|
||||
'startedAt': startedAt,
|
||||
'completedAt': completedAt,
|
||||
};
|
||||
}
|
||||
|
||||
String? _asString(Object? value) {
|
||||
final text = value?.toString().trim();
|
||||
if (text == null || text.isEmpty) return null;
|
||||
return text;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/data/dto/payment/operation.dart';
|
||||
import 'package:pshared/data/dto/payment/payment_quote.dart';
|
||||
|
||||
part 'payment.g.dart';
|
||||
@@ -12,6 +13,8 @@ class PaymentDTO {
|
||||
final String? state;
|
||||
final String? failureCode;
|
||||
final String? failureReason;
|
||||
@JsonKey(defaultValue: <PaymentOperationDTO>[])
|
||||
final List<PaymentOperationDTO> operations;
|
||||
final PaymentQuoteDTO? lastQuote;
|
||||
final Map<String, String>? metadata;
|
||||
final String? createdAt;
|
||||
@@ -22,6 +25,7 @@ class PaymentDTO {
|
||||
this.state,
|
||||
this.failureCode,
|
||||
this.failureReason,
|
||||
this.operations = const <PaymentOperationDTO>[],
|
||||
this.lastQuote,
|
||||
this.metadata,
|
||||
this.createdAt,
|
||||
|
||||
37
frontend/pshared/lib/data/mapper/payment/operation.dart
Normal file
37
frontend/pshared/lib/data/mapper/payment/operation.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:pshared/data/dto/payment/operation.dart';
|
||||
import 'package:pshared/models/payment/execution_operation.dart';
|
||||
|
||||
|
||||
extension PaymentOperationDTOMapper on PaymentOperationDTO {
|
||||
PaymentExecutionOperation toDomain() => PaymentExecutionOperation(
|
||||
stepRef: stepRef,
|
||||
operationRef: operationRef,
|
||||
code: code,
|
||||
state: state,
|
||||
label: label,
|
||||
failureCode: failureCode,
|
||||
failureReason: failureReason,
|
||||
startedAt: _parseDateTime(startedAt),
|
||||
completedAt: _parseDateTime(completedAt),
|
||||
);
|
||||
}
|
||||
|
||||
extension PaymentExecutionOperationMapper on PaymentExecutionOperation {
|
||||
PaymentOperationDTO toDTO() => PaymentOperationDTO(
|
||||
stepRef: stepRef,
|
||||
operationRef: operationRef,
|
||||
code: code,
|
||||
state: state,
|
||||
label: label,
|
||||
failureCode: failureCode,
|
||||
failureReason: failureReason,
|
||||
startedAt: startedAt?.toUtc().toIso8601String(),
|
||||
completedAt: completedAt?.toUtc().toIso8601String(),
|
||||
);
|
||||
}
|
||||
|
||||
DateTime? _parseDateTime(String? value) {
|
||||
final normalized = value?.trim();
|
||||
if (normalized == null || normalized.isEmpty) return null;
|
||||
return DateTime.tryParse(normalized);
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:pshared/data/dto/payment/payment.dart';
|
||||
import 'package:pshared/data/mapper/payment/operation.dart';
|
||||
import 'package:pshared/data/mapper/payment/quote.dart';
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/models/payment/state.dart';
|
||||
|
||||
|
||||
extension PaymentDTOMapper on PaymentDTO {
|
||||
Payment toDomain() => Payment(
|
||||
paymentRef: paymentRef,
|
||||
@@ -11,6 +13,7 @@ extension PaymentDTOMapper on PaymentDTO {
|
||||
orchestrationState: paymentOrchestrationStateFromValue(state),
|
||||
failureCode: failureCode,
|
||||
failureReason: failureReason,
|
||||
operations: operations.map((item) => item.toDomain()).toList(),
|
||||
lastQuote: lastQuote?.toDomain(),
|
||||
metadata: metadata,
|
||||
createdAt: createdAt == null ? null : DateTime.tryParse(createdAt!),
|
||||
@@ -24,6 +27,7 @@ extension PaymentMapper on Payment {
|
||||
state: state ?? paymentOrchestrationStateToValue(orchestrationState),
|
||||
failureCode: failureCode,
|
||||
failureReason: failureReason,
|
||||
operations: operations.map((item) => item.toDTO()).toList(),
|
||||
lastQuote: lastQuote?.toDTO(),
|
||||
metadata: metadata,
|
||||
createdAt: createdAt?.toUtc().toIso8601String(),
|
||||
|
||||
Reference in New Issue
Block a user