SubscriptionSchedulePhaseConfiguration.fromJson constructor

SubscriptionSchedulePhaseConfiguration.fromJson(
  1. Object? json
)

Implementation

factory SubscriptionSchedulePhaseConfiguration.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return SubscriptionSchedulePhaseConfiguration(
    addInvoiceItems: (map['add_invoice_items'] as List<Object?>)
        .map((el) => SubscriptionScheduleAddInvoiceItem.fromJson(el))
        .toList(),
    applicationFeePercent: map['application_fee_percent'] == null
        ? null
        : (map['application_fee_percent'] as num).toDouble(),
    automaticTax: map['automatic_tax'] == null
        ? null
        : SchedulesPhaseAutomaticTax.fromJson(map['automatic_tax']),
    billingCycleAnchor: map['billing_cycle_anchor'] == null
        ? null
        : SubscriptionSchedulePhaseConfigurationBillingCycleAnchor.fromJson(
            map['billing_cycle_anchor']),
    billingThresholds: map['billing_thresholds'] == null
        ? null
        : SubscriptionBillingThresholds.fromJson(map['billing_thresholds']),
    collectionMethod: map['collection_method'] == null
        ? null
        : SubscriptionSchedulePhaseConfigurationCollectionMethod.fromJson(
            map['collection_method']),
    coupon: map['coupon'] == null
        ? null
        : SubscriptionSchedulePhaseConfigurationCouponOrId.fromJson(
            map['coupon']),
    currency: (map['currency'] as String),
    defaultPaymentMethod: map['default_payment_method'] == null
        ? null
        : PaymentMethodOrId.fromJson(map['default_payment_method']),
    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),
    endDate:
        DateTime.fromMillisecondsSinceEpoch((map['end_date'] as int).toInt()),
    invoiceSettings: map['invoice_settings'] == null
        ? null
        : InvoiceSettingSubscriptionSchedulePhaseSetting.fromJson(
            map['invoice_settings']),
    items: (map['items'] as List<Object?>)
        .map((el) => SubscriptionScheduleConfigurationItem.fromJson(el))
        .toList(),
    metadata: map['metadata'] == null
        ? null
        : (map['metadata'] as Map).cast<String, Object?>().map((
              key,
              value,
            ) =>
                MapEntry(
                  key,
                  (value as String),
                )),
    onBehalfOf: map['on_behalf_of'] == null
        ? null
        : AccountOrId.fromJson(map['on_behalf_of']),
    prorationBehavior: PortalSubscriptionCancelProrationBehavior.fromJson(
        map['proration_behavior']),
    startDate: DateTime.fromMillisecondsSinceEpoch(
        (map['start_date'] as int).toInt()),
    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()),
  );
}