Invoice.fromJson constructor
Invoice.fromJson(
- Object? json
Implementation
factory Invoice.fromJson(Object? json) {
final map = (json as Map).cast<String, Object?>();
return Invoice(
accountCountry: map['account_country'] == null
? null
: (map['account_country'] as String),
accountName:
map['account_name'] == null ? null : (map['account_name'] as String),
accountTaxIds: map['account_tax_ids'] == null
? null
: (map['account_tax_ids'] as List<Object?>)
.map((el) => InvoiceAccountTaxIdsItemOrId.fromJson(el))
.toList(),
amountDue: (map['amount_due'] as num).toInt(),
amountPaid: (map['amount_paid'] as num).toInt(),
amountRemaining: (map['amount_remaining'] as num).toInt(),
amountShipping: (map['amount_shipping'] as num).toInt(),
application: map['application'] == null
? null
: BillingPortalConfigurationApplicationOrId.fromJson(
map['application']),
applicationFeeAmount: map['application_fee_amount'] == null
? null
: (map['application_fee_amount'] as num).toInt(),
attemptCount: (map['attempt_count'] as num).toInt(),
attempted: (map['attempted'] as bool),
autoAdvance:
map['auto_advance'] == null ? null : (map['auto_advance'] as bool),
automaticTax: AutomaticTax.fromJson(map['automatic_tax']),
billingReason: map['billing_reason'] == null
? null
: InvoiceBillingReason.fromJson(map['billing_reason']),
charge: map['charge'] == null ? null : ChargeOrId.fromJson(map['charge']),
collectionMethod:
InvoiceCollectionMethod.fromJson(map['collection_method']),
created:
DateTime.fromMillisecondsSinceEpoch((map['created'] as int).toInt()),
currency: (map['currency'] as String),
customFields: map['custom_fields'] == null
? null
: (map['custom_fields'] as List<Object?>)
.map((el) => InvoiceSettingCustomField.fromJson(el))
.toList(),
customer: map['customer'] == null
? null
: BankAccountCustomerOrId.fromJson(map['customer']),
customerAddress: map['customer_address'] == null
? null
: Address.fromJson(map['customer_address']),
customerEmail: map['customer_email'] == null
? null
: (map['customer_email'] as String),
customerName: map['customer_name'] == null
? null
: (map['customer_name'] as String),
customerPhone: map['customer_phone'] == null
? null
: (map['customer_phone'] as String),
customerShipping: map['customer_shipping'] == null
? null
: ChargeShipping.fromJson(map['customer_shipping']),
customerTaxExempt: map['customer_tax_exempt'] == null
? null
: CheckoutSessionCustomerDetailsTaxExempt.fromJson(
map['customer_tax_exempt']),
customerTaxIds: map['customer_tax_ids'] == null
? null
: (map['customer_tax_ids'] as List<Object?>)
.map((el) => InvoicesResourceInvoiceTaxId.fromJson(el))
.toList(),
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'] 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']),
discounts: map['discounts'] == null
? null
: (map['discounts'] as List<Object?>)
.map((el) =>
DiscountsResourceDiscountAmountDiscountOrId.fromJson(el))
.toList(),
dueDate: map['due_date'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(
(map['due_date'] as int).toInt()),
effectiveAt: map['effective_at'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(
(map['effective_at'] as int).toInt()),
endingBalance: map['ending_balance'] == null
? null
: (map['ending_balance'] as num).toInt(),
footer: map['footer'] == null ? null : (map['footer'] as String),
fromInvoice: map['from_invoice'] == null
? null
: InvoiceFromInvoice.fromJson(map['from_invoice']),
hostedInvoiceUrl: map['hosted_invoice_url'] == null
? null
: (map['hosted_invoice_url'] as String),
id: map['id'] == null ? null : (map['id'] as String),
invoicePdf:
map['invoice_pdf'] == null ? null : (map['invoice_pdf'] as String),
issuer: ConnectAccountReference.fromJson(map['issuer']),
lastFinalizationError: map['last_finalization_error'] == null
? null
: ApiErrors.fromJson(map['last_finalization_error']),
latestRevision: map['latest_revision'] == null
? null
: InvoiceOrId.fromJson(map['latest_revision']),
lines: InvoiceLines.fromJson(map['lines']),
livemode: (map['livemode'] as bool),
metadata: map['metadata'] == null
? null
: (map['metadata'] as Map).cast<String, Object?>().map((
key,
value,
) =>
MapEntry(
key,
(value as String),
)),
nextPaymentAttempt: map['next_payment_attempt'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(
(map['next_payment_attempt'] as int).toInt()),
number: map['number'] == null ? null : (map['number'] as String),
onBehalfOf: map['on_behalf_of'] == null
? null
: AccountOrId.fromJson(map['on_behalf_of']),
paid: (map['paid'] as bool),
paidOutOfBand: (map['paid_out_of_band'] as bool),
paymentIntent: map['payment_intent'] == null
? null
: PaymentIntentOrId.fromJson(map['payment_intent']),
paymentSettings:
InvoicesPaymentSettings.fromJson(map['payment_settings']),
periodEnd: DateTime.fromMillisecondsSinceEpoch(
(map['period_end'] as int).toInt()),
periodStart: DateTime.fromMillisecondsSinceEpoch(
(map['period_start'] as int).toInt()),
postPaymentCreditNotesAmount:
(map['post_payment_credit_notes_amount'] as num).toInt(),
prePaymentCreditNotesAmount:
(map['pre_payment_credit_notes_amount'] as num).toInt(),
quote: map['quote'] == null ? null : QuoteOrId.fromJson(map['quote']),
receiptNumber: map['receipt_number'] == null
? null
: (map['receipt_number'] as String),
rendering: map['rendering'] == null
? null
: InvoiceRendering.fromJson(map['rendering']),
renderingOptions: map['rendering_options'] == null
? null
: InvoiceRenderingOptions.fromJson(map['rendering_options']),
shippingCost: map['shipping_cost'] == null
? null
: CheckoutSessionShippingCost.fromJson(map['shipping_cost']),
shippingDetails: map['shipping_details'] == null
? null
: ChargeShipping.fromJson(map['shipping_details']),
startingBalance: (map['starting_balance'] as num).toInt(),
statementDescriptor: map['statement_descriptor'] == null
? null
: (map['statement_descriptor'] as String),
status:
map['status'] == null ? null : InvoiceStatus.fromJson(map['status']),
statusTransitions:
InvoicesResourceStatusTransitions.fromJson(map['status_transitions']),
subscription: map['subscription'] == null
? null
: SubscriptionOrId.fromJson(map['subscription']),
subscriptionDetails: map['subscription_details'] == null
? null
: InvoiceSubscriptionDetails.fromJson(map['subscription_details']),
subscriptionProrationDate: map['subscription_proration_date'] == null
? null
: (map['subscription_proration_date'] as num).toInt(),
subtotal: (map['subtotal'] as num).toInt(),
subtotalExcludingTax: map['subtotal_excluding_tax'] == null
? null
: (map['subtotal_excluding_tax'] as num).toInt(),
tax: map['tax'] == null ? null : (map['tax'] as num).toInt(),
testClock: map['test_clock'] == null
? null
: TestHelpersTestClockOrId.fromJson(map['test_clock']),
thresholdReason: map['threshold_reason'] == null
? null
: InvoiceThresholdReason.fromJson(map['threshold_reason']),
total: (map['total'] as num).toInt(),
totalDiscountAmounts: map['total_discount_amounts'] == null
? null
: (map['total_discount_amounts'] as List<Object?>)
.map((el) => DiscountsResourceDiscountAmount.fromJson(el))
.toList(),
totalExcludingTax: map['total_excluding_tax'] == null
? null
: (map['total_excluding_tax'] as num).toInt(),
totalTaxAmounts: (map['total_tax_amounts'] as List<Object?>)
.map((el) => InvoiceTaxAmount.fromJson(el))
.toList(),
transferData: map['transfer_data'] == null
? null
: ChargeTransferData.fromJson(map['transfer_data']),
webhooksDeliveredAt: map['webhooks_delivered_at'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(
(map['webhooks_delivered_at'] as int).toInt()),
);
}