Price.fromJson constructor

Price.fromJson(
  1. Object? json
)

Implementation

factory Price.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return Price(
    active: (map['active'] as bool),
    billingScheme:
        InvoiceitemPlanBillingScheme.fromJson(map['billing_scheme']),
    created:
        DateTime.fromMillisecondsSinceEpoch((map['created'] as int).toInt()),
    currency: (map['currency'] as String),
    currencyOptions: map['currency_options'] == null
        ? null
        : (map['currency_options'] as Map).cast<String, Object?>().map((
              key,
              value,
            ) =>
                MapEntry(
                  key,
                  CurrencyOption.fromJson(value),
                )),
    customUnitAmount: map['custom_unit_amount'] == null
        ? null
        : CustomUnitAmount.fromJson(map['custom_unit_amount']),
    id: (map['id'] as String),
    livemode: (map['livemode'] as bool),
    lookupKey:
        map['lookup_key'] == null ? null : (map['lookup_key'] as String),
    metadata: (map['metadata'] as Map).cast<String, Object?>().map((
          key,
          value,
        ) =>
            MapEntry(
              key,
              (value as String),
            )),
    nickname: map['nickname'] == null ? null : (map['nickname'] as String),
    product: InvoiceitemPlanProductOrId.fromJson(map['product']),
    recurring: map['recurring'] == null
        ? null
        : InvoiceitemPriceRecurring.fromJson(map['recurring']),
    taxBehavior: map['tax_behavior'] == null
        ? null
        : CurrencyOptionTaxBehavior.fromJson(map['tax_behavior']),
    tiers: map['tiers'] == null
        ? null
        : (map['tiers'] as List<Object?>)
            .map((el) => PriceTier.fromJson(el))
            .toList(),
    tiersMode: map['tiers_mode'] == null
        ? null
        : InvoiceitemPlanTiersMode.fromJson(map['tiers_mode']),
    transformQuantity: map['transform_quantity'] == null
        ? null
        : InvoiceitemPlanTransformUsage.fromJson(map['transform_quantity']),
    type: InvoiceitemPriceType.fromJson(map['type']),
    unitAmount: map['unit_amount'] == null
        ? null
        : (map['unit_amount'] as num).toInt(),
    unitAmountDecimal: map['unit_amount_decimal'] == null
        ? null
        : (map['unit_amount_decimal'] as String),
  );
}