Files
sendico/frontend/pshared/lib/data/dto/payment/payment.dart
2026-03-10 19:15:20 +01:00

49 lines
1.4 KiB
Dart

import 'package:json_annotation/json_annotation.dart';
import 'package:pshared/data/dto/payment/operation.dart';
import 'package:pshared/data/dto/payment/payment_quote.dart';
import 'package:pshared/data/dto/payment/response_endpoint.dart';
part 'payment.g.dart';
@JsonSerializable()
class PaymentDTO {
final String? paymentRef;
final String? state;
final PaymentResponseEndpointDTO? source;
final PaymentResponseEndpointDTO? destination;
final String? failureCode;
final String? failureReason;
final List<PaymentOperationDTO> operations;
final PaymentQuoteDTO? lastQuote;
final Map<String, String>? metadata;
final String? createdAt;
const PaymentDTO({
this.paymentRef,
this.state,
this.source,
this.destination,
this.failureCode,
this.failureReason,
this.operations = const <PaymentOperationDTO>[],
this.lastQuote,
this.metadata,
this.createdAt,
});
factory PaymentDTO.fromJson(Map<String, dynamic> json) =>
_$PaymentDTOFromJson(_normalizeJson(json));
Map<String, dynamic> toJson() => _$PaymentDTOToJson(this);
static Map<String, dynamic> _normalizeJson(Map<String, dynamic> json) {
if (json.containsKey('metadata') || !json.containsKey('meta')) {
return json;
}
final normalized = Map<String, dynamic>.from(json);
normalized['metadata'] = normalized['meta'];
return normalized;
}
}