fromJson static method

SchemasCommerceSubscriptionItem? fromJson(
  1. dynamic value
)

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

Implementation

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

    return SchemasCommerceSubscriptionItem(
      object: SchemasCommerceSubscriptionItemObjectEnum.fromJson(
          json[r'object'])!,
      id: mapValueOfType<String>(json, r'id')!,
      instanceId: mapValueOfType<String>(json, r'instance_id')!,
      status: SchemasCommerceSubscriptionItemStatusEnum.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: SchemasCommercePlan.fromJson(json[r'plan']),
      planPeriod: SchemasCommerceSubscriptionItemPlanPeriodEnum.fromJson(
          json[r'plan_period'])!,
      paymentSourceId: mapValueOfType<String>(json, r'payment_source_id')!,
      paymentSource:
          CommercePaymentSourceResponse.fromJson(json[r'payment_source']),
      lifetimePaid: CommerceMoneyResponse.fromJson(json[r'lifetime_paid']),
      amount: CommerceMoneyResponse.fromJson(json[r'amount']),
      nextInvoice: CommerceSubscriptionItemNextPaymentResponse.fromJson(
          json[r'next_invoice']),
      nextPayment: CommerceSubscriptionItemNextPaymentResponse.fromJson(
          json[r'next_payment']),
      payerId: mapValueOfType<String>(json, r'payer_id')!,
      payer: SchemasCommercePayerResponse.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: mapValueOfType<String>(json, r'proration_date')!,
      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;
}