fromJson static method

CommercePriceTransitionDetails? fromJson(
  1. dynamic value
)

Returns a new CommercePriceTransitionDetails instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static CommercePriceTransitionDetails? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key),
            'Required key "CommercePriceTransitionDetails[$key]" is missing from JSON.');
        assert(json[key] != null,
            'Required key "CommercePriceTransitionDetails[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return CommercePriceTransitionDetails(
      previousPlan: SchemasCommercePlan.fromJson(json[r'previous_plan'])!,
      previousPrice: BillingPriceResponse.fromJson(json[r'previous_price'])!,
      effectiveAt: mapValueOfType<int>(json, r'effective_at')!,
      effectiveMode: CommercePriceTransitionDetailsEffectiveModeEnum.fromJson(
          json[r'effective_mode'])!,
      nextBillingDate: mapValueOfType<int>(json, r'next_billing_date'),
      chargedImmediately: mapValueOfType<bool>(json, r'charged_immediately')!,
      immediateCharge:
          CommerceMoneyResponse.fromJson(json[r'immediate_charge']),
      previousSubscriptionItemStatus:
          CommercePriceTransitionDetailsPreviousSubscriptionItemStatusEnum
              .fromJson(json[r'previous_subscription_item_status'])!,
      previousSubscriptionItemId:
          mapValueOfType<String>(json, r'previous_subscription_item_id')!,
    );
  }
  return null;
}