Subscription.fromJson constructor

Subscription.fromJson(
  1. Object? json
)

Implementation

factory Subscription.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return Subscription(
    application: map['application'] == null
        ? null
        : BillingPortalConfigurationApplicationOrId.fromJson(
            map['application']),
    applicationFeePercent: map['application_fee_percent'] == null
        ? null
        : (map['application_fee_percent'] as num).toDouble(),
    automaticTax: SubscriptionAutomaticTax.fromJson(map['automatic_tax']),
    billingCycleAnchor: DateTime.fromMillisecondsSinceEpoch(
        (map['billing_cycle_anchor'] as int).toInt()),
    billingCycleAnchorConfig: map['billing_cycle_anchor_config'] == null
        ? null
        : SubscriptionBillingCycleAnchorConfig.fromJson(
            map['billing_cycle_anchor_config']),
    billingThresholds: map['billing_thresholds'] == null
        ? null
        : SubscriptionBillingThresholds.fromJson(map['billing_thresholds']),
    cancelAt: map['cancel_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['cancel_at'] as int).toInt()),
    cancelAtPeriodEnd: (map['cancel_at_period_end'] as bool),
    canceledAt: map['canceled_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['canceled_at'] as int).toInt()),
    cancellationDetails: map['cancellation_details'] == null
        ? null
        : CancellationDetails.fromJson(map['cancellation_details']),
    collectionMethod:
        InvoiceCollectionMethod.fromJson(map['collection_method']),
    created:
        DateTime.fromMillisecondsSinceEpoch((map['created'] as int).toInt()),
    currency: (map['currency'] as String),
    currentPeriodEnd: DateTime.fromMillisecondsSinceEpoch(
        (map['current_period_end'] as int).toInt()),
    currentPeriodStart: DateTime.fromMillisecondsSinceEpoch(
        (map['current_period_start'] as int).toInt()),
    customer: BankAccountCustomerOrId.fromJson(map['customer']),
    daysUntilDue: map['days_until_due'] == null
        ? null
        : (map['days_until_due'] as num).toInt(),
    defaultPaymentMethod: map['default_payment_method'] == null
        ? null
        : PaymentMethodOrId.fromJson(map['default_payment_method']),
    defaultSource: map['default_source'] == null
        ? null
        : PaymentSourceOrId.fromJson(map['default_source']),
    defaultTaxRates: map['default_tax_rates'] == null
        ? null
        : (map['default_tax_rates'] as List<Object?>)
            .map((el) => TaxRate.fromJson(el))
            .toList(),
    description:
        map['description'] == null ? null : (map['description'] as String),
    discount:
        map['discount'] == null ? null : Discount.fromJson(map['discount']),
    endedAt: map['ended_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['ended_at'] as int).toInt()),
    id: (map['id'] as String),
    items: SubscriptionItems.fromJson(map['items']),
    latestInvoice: map['latest_invoice'] == null
        ? null
        : InvoiceOrId.fromJson(map['latest_invoice']),
    livemode: (map['livemode'] as bool),
    metadata: (map['metadata'] as Map).cast<String, Object?>().map((
          key,
          value,
        ) =>
            MapEntry(
              key,
              (value as String),
            )),
    nextPendingInvoiceItemInvoice:
        map['next_pending_invoice_item_invoice'] == null
            ? null
            : DateTime.fromMillisecondsSinceEpoch(
                (map['next_pending_invoice_item_invoice'] as int).toInt()),
    onBehalfOf: map['on_behalf_of'] == null
        ? null
        : AccountOrId.fromJson(map['on_behalf_of']),
    pauseCollection: map['pause_collection'] == null
        ? null
        : SubscriptionPauseCollection.fromJson(map['pause_collection']),
    paymentSettings: map['payment_settings'] == null
        ? null
        : SubscriptionPaymentSettings.fromJson(map['payment_settings']),
    pendingInvoiceItemInterval: map['pending_invoice_item_interval'] == null
        ? null
        : SubscriptionPendingInvoiceItemInterval.fromJson(
            map['pending_invoice_item_interval']),
    pendingSetupIntent: map['pending_setup_intent'] == null
        ? null
        : SetupIntentOrId.fromJson(map['pending_setup_intent']),
    pendingUpdate: map['pending_update'] == null
        ? null
        : SubscriptionPendingUpdate.fromJson(map['pending_update']),
    schedule: map['schedule'] == null
        ? null
        : SubscriptionScheduleOrId.fromJson(map['schedule']),
    startDate: DateTime.fromMillisecondsSinceEpoch(
        (map['start_date'] as int).toInt()),
    status: SubscriptionStatus.fromJson(map['status']),
    testClock: map['test_clock'] == null
        ? null
        : TestHelpersTestClockOrId.fromJson(map['test_clock']),
    transferData: map['transfer_data'] == null
        ? null
        : SubscriptionTransferData.fromJson(map['transfer_data']),
    trialEnd: map['trial_end'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['trial_end'] as int).toInt()),
    trialSettings: map['trial_settings'] == null
        ? null
        : PaymentLinkSubscriptionDataTrialSettings.fromJson(
            map['trial_settings']),
    trialStart: map['trial_start'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['trial_start'] as int).toInt()),
  );
}