KnotSuccess.fromJson constructor
KnotSuccess.fromJson(
- dynamic json
Factory method to create a KnotSuccess from a json
map.
Implementation
factory KnotSuccess.fromJson(dynamic json) {
if (json is! Map) {
throw ArgumentError('Expected a Map<String, dynamic>, got ${json.runtimeType}');
}
final Map<String, Object?> jsonMap = json.cast<String, Object?>();
String? productName = jsonMap["product"] as String?;
// Map to a product
Product? product;
switch (productName) {
case "transaction_link":
product = Product.transactionLink;
break;
case "card_switcher":
product = Product.cardSwitcher;
break;
}
if (product == null) {
throw ArgumentError('Expected product to be non-null');
}
return KnotSuccess(
merchant: json["merchant"],
product: product
);
}