Source.fromJson constructor
Implementation
Source.fromJson(Map<String, dynamic> json) {
id = optString(json, FIELD_ID);
amount = optInteger(json, FIELD_AMOUNT);
clientSecret = optString(json, FIELD_CLIENT_SECRET);
final codeVerf = json[FIELD_CODE_VERIFICATION];
if (codeVerf != null) {
codeVerification =
SourceCodeVerification.fromJson(codeVerf.cast<String, dynamic>());
}
created = optInteger(
json, FIELD_CREATED); // TODO:: maybe we need to convert it into long
currency = optString(json, FIELD_CURRENCY);
flow = asSourceFlow(optString(json, FIELD_FLOW));
liveMode = optBoolean(json, FIELD_LIVEMODE);
var metaDataObj = json[FIELD_METADATA];
if (metaDataObj != null) {
metaData = metaDataObj.cast<String, String>();
} else {
metaData = Map();
}
final ownerObject = json[FIELD_OWNER];
if (ownerObject != null) {
owner = SourceOwner.fromJson(ownerObject.cast<String, dynamic>());
}
var receiverObject = json[FIELD_RECEIVER];
if (receiverObject != null) {
receiver =
SourceReceiver.fromJson(receiverObject.cast<String, dynamic>());
}
var redirectObject = json[FIELD_REDIRECT];
if (redirectObject != null) {
redirect =
SourceRedirect.fromJson(redirectObject.cast<String, dynamic>());
}
status = asSourceStatus(optString(json, FIELD_STATUS));
String? typeRaw = optString(json, FIELD_TYPE);
typeRaw ??= UNKNOWN;
type = asSourceType(typeRaw);
type ??= UNKNOWN;
// Until we have models for all types, keep the original hash and the
// model object. The customType variable can be any field, and is not altered by
// trying to force it to be a type that we know of.
/*
sourceTypeData = json[typeRaw];
if (MODELED_TYPES.contains(typeRaw)) {
sourceTypeModel = new StripeSourceTypeModel(json[typeRaw]);
}
*/
usage = asUsage(optString(json, FIELD_USAGE));
}