74 lines
2.2 KiB
Dart
74 lines
2.2 KiB
Dart
import 'package:pshared/data/dto/payment/operation.dart';
|
|
import 'package:pshared/data/mapper/money.dart';
|
|
import 'package:pshared/models/payment/execution_operation.dart';
|
|
|
|
extension PaymentOperationDTOMapper on PaymentOperationDTO {
|
|
PaymentExecutionOperation toDomain() => PaymentExecutionOperation(
|
|
stepRef: stepRef,
|
|
operationRef: operationRef,
|
|
gateway: gateway,
|
|
code: code,
|
|
state: state,
|
|
label: label,
|
|
money: money?.toDomain(),
|
|
failureCode: failureCode,
|
|
failureReason: failureReason,
|
|
startedAt: _parseDateTime(startedAt),
|
|
completedAt: _parseDateTime(completedAt),
|
|
);
|
|
}
|
|
|
|
extension PaymentExecutionOperationMapper on PaymentExecutionOperation {
|
|
PaymentOperationDTO toDTO() => PaymentOperationDTO(
|
|
stepRef: stepRef,
|
|
operationRef: operationRef,
|
|
gateway: gateway,
|
|
code: code,
|
|
state: state,
|
|
label: label,
|
|
money: money?.toDTO(),
|
|
failureCode: failureCode,
|
|
failureReason: failureReason,
|
|
startedAt: startedAt?.toUtc().toIso8601String(),
|
|
completedAt: completedAt?.toUtc().toIso8601String(),
|
|
);
|
|
}
|
|
|
|
extension PaymentOperationMoneyDTOMapper on PaymentOperationMoneyDTO {
|
|
PaymentExecutionOperationMoney toDomain() => PaymentExecutionOperationMoney(
|
|
planned: planned?.toDomain(),
|
|
executed: executed?.toDomain(),
|
|
);
|
|
}
|
|
|
|
extension PaymentExecutionOperationMoneyMapper
|
|
on PaymentExecutionOperationMoney {
|
|
PaymentOperationMoneyDTO toDTO() => PaymentOperationMoneyDTO(
|
|
planned: planned?.toDTO(),
|
|
executed: executed?.toDTO(),
|
|
);
|
|
}
|
|
|
|
extension PaymentOperationMoneySnapshotDTOMapper
|
|
on PaymentOperationMoneySnapshotDTO {
|
|
PaymentExecutionOperationMoneySnapshot toDomain() =>
|
|
PaymentExecutionOperationMoneySnapshot(
|
|
amount: amount?.toDomain(),
|
|
convertedAmount: convertedAmount?.toDomain(),
|
|
);
|
|
}
|
|
|
|
extension PaymentExecutionOperationMoneySnapshotMapper
|
|
on PaymentExecutionOperationMoneySnapshot {
|
|
PaymentOperationMoneySnapshotDTO toDTO() => PaymentOperationMoneySnapshotDTO(
|
|
amount: amount?.toDTO(),
|
|
convertedAmount: convertedAmount?.toDTO(),
|
|
);
|
|
}
|
|
|
|
DateTime? _parseDateTime(String? value) {
|
|
final normalized = value?.trim();
|
|
if (normalized == null || normalized.isEmpty) return null;
|
|
return DateTime.tryParse(normalized);
|
|
}
|