SubscriptionCreateOptions.fromJson constructor

SubscriptionCreateOptions.fromJson(
  1. Object? json
)

Implementation

factory SubscriptionCreateOptions.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return SubscriptionCreateOptions(
    addInvoiceItems: map['add_invoice_items'] == null
        ? null
        : (map['add_invoice_items'] as List<Object?>)
            .map((el) => SubscriptionScheduleAddInvoiceItemsItem.fromJson(el))
            .toList(),
    applicationFeePercent: map['application_fee_percent'] == null
        ? null
        : (map['application_fee_percent'] as num).toDouble(),
    automaticTax: map['automatic_tax'] == null
        ? null
        : SessionAutomaticTax.fromJson(map['automatic_tax']),
    backdateStartDate: map['backdate_start_date'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['backdate_start_date'] as int).toInt()),
    billingCycleAnchor: map['billing_cycle_anchor'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['billing_cycle_anchor'] as int).toInt()),
    billingCycleAnchorConfig: map['billing_cycle_anchor_config'] == null
        ? null
        : SubscriptionCreateOptionsBillingCycleAnchorConfig.fromJson(
            map['billing_cycle_anchor_config']),
    billingThresholds: map['billing_thresholds'] == null
        ? null
        : SubscriptionScheduleBillingThresholds.fromJson(
            map['billing_thresholds']),
    cancelAt: map['cancel_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['cancel_at'] as int).toInt()),
    cancelAtPeriodEnd: map['cancel_at_period_end'] == null
        ? null
        : (map['cancel_at_period_end'] as bool),
    collectionMethod: map['collection_method'] == null
        ? null
        : InvoiceCollectionMethod.fromJson(map['collection_method']),
    coupon: map['coupon'] == null ? null : (map['coupon'] as String),
    currency: map['currency'] == null ? null : (map['currency'] as String),
    customer: (map['customer'] as String),
    daysUntilDue: map['days_until_due'] == null
        ? null
        : (map['days_until_due'] as num).toInt(),
    defaultPaymentMethod: map['default_payment_method'] == null
        ? null
        : (map['default_payment_method'] as String),
    defaultSource: map['default_source'] == null
        ? null
        : (map['default_source'] as String),
    defaultTaxRates: map['default_tax_rates'] == null
        ? null
        : (map['default_tax_rates'] as List<Object?>)
            .map((el) => (el as String))
            .toList(),
    description:
        map['description'] == null ? null : (map['description'] as String),
    expand: map['expand'] == null
        ? null
        : (map['expand'] as List<Object?>)
            .map((el) => (el as String))
            .toList(),
    invoiceSettings: map['invoice_settings'] == null
        ? null
        : SubscriptionInvoiceSettings.fromJson(map['invoice_settings']),
    items: map['items'] == null
        ? null
        : (map['items'] as List<Object?>)
            .map((el) => SubscriptionScheduleItemsItem.fromJson(el))
            .toList(),
    metadata: map['metadata'] == null
        ? null
        : (map['metadata'] as Map).cast<String, Object?>().map((
              key,
              value,
            ) =>
                MapEntry(
                  key,
                  (value as String),
                )),
    offSession:
        map['off_session'] == null ? null : (map['off_session'] as bool),
    onBehalfOf:
        map['on_behalf_of'] == null ? null : (map['on_behalf_of'] as String),
    paymentBehavior: map['payment_behavior'] == null
        ? null
        : SubscriptionItemPaymentBehavior.fromJson(map['payment_behavior']),
    paymentSettings: map['payment_settings'] == null
        ? null
        : SubscriptionCreateOptionsPaymentSettings.fromJson(
            map['payment_settings']),
    pendingInvoiceItemInterval: map['pending_invoice_item_interval'] == null
        ? null
        : SessionRecurring.fromJson(map['pending_invoice_item_interval']),
    promotionCode: map['promotion_code'] == null
        ? null
        : (map['promotion_code'] as String),
    prorationBehavior: map['proration_behavior'] == null
        ? null
        : PortalSubscriptionCancelProrationBehavior.fromJson(
            map['proration_behavior']),
    transferData: map['transfer_data'] == null
        ? null
        : SessionTransferData.fromJson(map['transfer_data']),
    trialEnd: map['trial_end'] == null
        ? null
        : SubscriptionTrialEnd.fromJson(map['trial_end']),
    trialFromPlan: map['trial_from_plan'] == null
        ? null
        : (map['trial_from_plan'] as bool),
    trialPeriodDays: map['trial_period_days'] == null
        ? null
        : (map['trial_period_days'] as num).toInt(),
    trialSettings: map['trial_settings'] == null
        ? null
        : SessionTrialSettings.fromJson(map['trial_settings']),
  );
}