Card.fromMap constructor
Implementation
factory Card.fromMap(Map<String, dynamic> map) {
assert(map['token'] != null || map['number'] != null,
"CardError -> token or number must be set.");
assert(map['expiration'] != null, "CardError -> expiration must be set.");
assert(map['cardholder_name'] != null,
"CardError -> cardholder_name name must be set.");
assert(
map['token'] != null || (map['number'] != null && map['cvv'] != null),
"CardError -> cvv must be specified for a new card.");
return Card(
client: map['client']?.toString() ?? '',
expiration: map['expiration']?.toString().padLeft(4, '0'),
token: map['token'],
address:
map['address'] != null ? Address.fromMap(map['address']) : null,
customer: map['customer'],
cardholderName: map['cardholder_name'],
currency: map['currency'],
number:
map['number']?.toString().replaceAll(' ', '').replaceAll('-', ''),
cvv: map['cvv'],
lastFour: map['last_four'],
providerReference: map['provider_reference'],
brand: (map['brand'] != null)
? CardBrand
.values[int.parse(map['brand'].toString().replaceAll('.0', ''))]
: CardBrand.none,
active: map['active'] ?? true);
}