fromJson static method

CommerceSubscriptionItem? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static CommerceSubscriptionItem? 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 "CommerceSubscriptionItem[$key]" is missing from JSON.');
        assert(json[key] != null,
            'Required key "CommerceSubscriptionItem[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return CommerceSubscriptionItem(
      object: CommerceSubscriptionItemObjectEnum.fromJson(json[r'object'])!,
      id: mapValueOfType<String>(json, r'id')!,
      instanceId: mapValueOfType<String>(json, r'instance_id')!,
      status: CommerceSubscriptionItemStatusEnum.fromJson(json[r'status'])!,
      credit: CommerceSubscriptionCreditResponse.fromJson(json[r'credit']),
      planId: mapValueOfType<String>(json, r'plan_id'),
      priceId: mapValueOfType<String>(json, r'price_id'),
      plan: CommercePlan.fromJson(json[r'plan']),
      planPeriod: CommerceSubscriptionItemPlanPeriodEnum.fromJson(
          json[r'plan_period'])!,
      paymentMethod:
          CommercePaymentMethodResponse.fromJson(json[r'payment_method']),
      lifetimePaid: CommerceMoneyResponse.fromJson(json[r'lifetime_paid']),
      nextPayment: CommerceSubscriptionItemNextPaymentResponse.fromJson(
          json[r'next_payment']),
      payerId: mapValueOfType<String>(json, r'payer_id')!,
      payer: CommercePayerResponse.fromJson(json[r'payer']),
      isFreeTrial: mapValueOfType<bool>(json, r'is_free_trial')!,
      periodStart: mapValueOfType<int>(json, r'period_start')!,
      periodEnd: mapValueOfType<int>(json, r'period_end'),
      prorationDate: mapDateTime(json, r'proration_date', r''),
      canceledAt: mapValueOfType<int>(json, r'canceled_at'),
      pastDueAt: mapValueOfType<int>(json, r'past_due_at'),
      endedAt: mapValueOfType<int>(json, r'ended_at'),
      createdAt: mapValueOfType<int>(json, r'created_at'),
      updatedAt: mapValueOfType<int>(json, r'updated_at'),
    );
  }
  return null;
}