Customer.fromJson constructor

Customer.fromJson(
  1. Map<String, dynamic> json
)

Implementation

Customer.fromJson(Map<String, dynamic> json) {
  id = optString(json, FIELD_ID);
  defaultSource = optString(json, FIELD_DEFAULT_SOURCE);
  final shipInfoObject = json[FIELD_SHIPPING]; //.cast<String, dynamic>()
  if (shipInfoObject != null) {
    shippingInformation =
        ShippingInformation.fromJson(shipInfoObject.cast<String, dynamic>());
  }

  final Map<String, dynamic> sources =
      json[FIELD_SOURCES].cast<String, dynamic>();
  if (sources != null && (VALUE_LIST == optString(sources, FIELD_OBJECT))) {
    hasMore = optBoolean(sources, FIELD_HAS_MORE);
    totalCount = optInteger(sources, FIELD_TOTAL_COUNT);
    url = optString(sources, FIELD_URL);

    List<CustomerSource> sourceDataList = [];
    List dataArray = sources[FIELD_DATA] ?? [];
    for (int i = 0; i < dataArray.length; i++) {
      try {
        var customerSourceObject = dataArray[i];
        CustomerSource sourceData = CustomerSource.fromJson(
            customerSourceObject.cast<String, dynamic>());
        if (VALUE_APPLE_PAY == sourceData.getTokenizationMethod()) {
          continue;
        }
        sourceDataList.add(sourceData);
      } catch (ignored) {
        print(ignored);
      }
    }
    this.sources = sourceDataList;
  }
}