LineItem.fromJson constructor

LineItem.fromJson(
  1. Object? json
)

Implementation

factory LineItem.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return LineItem(
    amount: (map['amount'] as num).toInt(),
    amountExcludingTax: map['amount_excluding_tax'] == null
        ? null
        : (map['amount_excluding_tax'] as num).toInt(),
    currency: (map['currency'] as String),
    description:
        map['description'] == null ? null : (map['description'] as String),
    discountAmounts: map['discount_amounts'] == null
        ? null
        : (map['discount_amounts'] as List<Object?>)
            .map((el) => DiscountsResourceDiscountAmount.fromJson(el))
            .toList(),
    discountable: (map['discountable'] as bool),
    discounts: map['discounts'] == null
        ? null
        : (map['discounts'] as List<Object?>)
            .map((el) => DiscountOrId.fromJson(el))
            .toList(),
    id: (map['id'] as String),
    invoice: map['invoice'] == null ? null : (map['invoice'] as String),
    invoiceItem: map['invoice_item'] == null
        ? null
        : InvoiceitemOrId.fromJson(map['invoice_item']),
    livemode: (map['livemode'] as bool),
    metadata: (map['metadata'] as Map).cast<String, Object?>().map((
          key,
          value,
        ) =>
            MapEntry(
              key,
              (value as String),
            )),
    period: InvoiceLineItemPeriod.fromJson(map['period']),
    plan: map['plan'] == null ? null : InvoiceitemPlan.fromJson(map['plan']),
    price:
        map['price'] == null ? null : InvoiceitemPrice.fromJson(map['price']),
    proration: (map['proration'] as bool),
    prorationDetails: map['proration_details'] == null
        ? null
        : InvoicesResourceLineItemsProrationDetails.fromJson(
            map['proration_details']),
    quantity:
        map['quantity'] == null ? null : (map['quantity'] as num).toInt(),
    subscription: map['subscription'] == null
        ? null
        : SubscriptionOrId.fromJson(map['subscription']),
    subscriptionItem: map['subscription_item'] == null
        ? null
        : SubscriptionItemOrId.fromJson(map['subscription_item']),
    taxAmounts: map['tax_amounts'] == null
        ? null
        : (map['tax_amounts'] as List<Object?>)
            .map((el) => InvoiceTaxAmount.fromJson(el))
            .toList(),
    taxRates: map['tax_rates'] == null
        ? null
        : (map['tax_rates'] as List<Object?>)
            .map((el) => TaxRate.fromJson(el))
            .toList(),
    type: LineItemType.fromJson(map['type']),
    unitAmountExcludingTax: map['unit_amount_excluding_tax'] == null
        ? null
        : (map['unit_amount_excluding_tax'] as String),
  );
}