CreditNote.fromJson constructor
CreditNote.fromJson(
- Object? json
Implementation
factory CreditNote.fromJson(Object? json) {
final map = (json as Map).cast<String, Object?>();
return CreditNote(
amount: (map['amount'] as num).toInt(),
amountShipping: (map['amount_shipping'] as num).toInt(),
created:
DateTime.fromMillisecondsSinceEpoch((map['created'] as int).toInt()),
currency: (map['currency'] as String),
customer: BankAccountCustomerOrId.fromJson(map['customer']),
customerBalanceTransaction: map['customer_balance_transaction'] == null
? null
: CustomerBalanceTransactionOrId.fromJson(
map['customer_balance_transaction']),
discountAmount: (map['discount_amount'] as num).toInt(),
discountAmounts: (map['discount_amounts'] as List<Object?>)
.map((el) => DiscountsResourceDiscountAmount.fromJson(el))
.toList(),
effectiveAt: map['effective_at'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(
(map['effective_at'] as int).toInt()),
id: (map['id'] as String),
invoice: InvoiceOrId.fromJson(map['invoice']),
lines: CreditNoteLines.fromJson(map['lines']),
livemode: (map['livemode'] as bool),
memo: map['memo'] == null ? null : (map['memo'] as String),
metadata: map['metadata'] == null
? null
: (map['metadata'] as Map).cast<String, Object?>().map((
key,
value,
) =>
MapEntry(
key,
(value as String),
)),
number: (map['number'] as String),
outOfBandAmount: map['out_of_band_amount'] == null
? null
: (map['out_of_band_amount'] as num).toInt(),
pdf: (map['pdf'] as String),
reason: map['reason'] == null
? null
: CreditNoteReason.fromJson(map['reason']),
refund: map['refund'] == null ? null : RefundOrId.fromJson(map['refund']),
shippingCost: map['shipping_cost'] == null
? null
: CheckoutSessionShippingCost.fromJson(map['shipping_cost']),
status: CreditNoteStatus.fromJson(map['status']),
subtotal: (map['subtotal'] as num).toInt(),
subtotalExcludingTax: map['subtotal_excluding_tax'] == null
? null
: (map['subtotal_excluding_tax'] as num).toInt(),
taxAmounts: (map['tax_amounts'] as List<Object?>)
.map((el) => CreditNoteTaxAmount.fromJson(el))
.toList(),
total: (map['total'] as num).toInt(),
totalExcludingTax: map['total_excluding_tax'] == null
? null
: (map['total_excluding_tax'] as num).toInt(),
type: CreditNoteType.fromJson(map['type']),
voidedAt: map['voided_at'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(
(map['voided_at'] as int).toInt()),
);
}