36 lines
953 B
Dart
36 lines
953 B
Dart
class PaymentMethod {
|
|
const PaymentMethod({
|
|
required this.id,
|
|
required this.name,
|
|
this.paymentType,
|
|
this.conditionId,
|
|
this.conditionType,
|
|
this.installments,
|
|
});
|
|
|
|
final int id;
|
|
final String name;
|
|
final String? paymentType;
|
|
final int? conditionId;
|
|
final String? conditionType;
|
|
final int? installments;
|
|
|
|
factory PaymentMethod.fromJson(Map<String, dynamic> json) {
|
|
final id = json['id'];
|
|
final name = json['name'];
|
|
if (id is! num || name is! String) {
|
|
throw const FormatException('Resposta de forma de pagamento inválida.');
|
|
}
|
|
return PaymentMethod(
|
|
id: id.toInt(),
|
|
name: name,
|
|
paymentType: json['payment_type']?.toString(),
|
|
conditionId: _asInt(json['condition_id']),
|
|
conditionType: json['condition_type']?.toString(),
|
|
installments: _asInt(json['installments']),
|
|
);
|
|
}
|
|
|
|
static int? _asInt(dynamic value) => value is num ? value.toInt() : null;
|
|
}
|