encode<V> static method

V encode<V>(
  1. Invoiceitem instance,
  2. Encoder<V> encoder
)
override

Implementation

static V encode<V>(
  Invoiceitem instance,
  Encoder<V> encoder,
) {
  final container = encoder.container<String>();
  container.encodeInt(
    'amount',
    instance.amount,
  );
  container.encodeString(
    'currency',
    instance.currency,
  );
  BankAccountCustomerOrId.encode(
    instance.customer,
    container.nestedSingleValueContainer('customer').encoder,
  );
  container.encodeDateTime(
    'date',
    instance.date,
  );
  if (instance.description != null) {
    container.encodeString(
      'description',
      instance.description!,
    );
  }
  container.encodeBool(
    'discountable',
    instance.discountable,
  );
  if (instance.discounts != null) {
    container.encodeList(
      'discounts',
      (container) => instance.discounts!.forEach((el) => DiscountOrId.encode(
            el,
            container.nestedSingleValueContainer().encoder,
          )),
    );
  }
  container.encodeString(
    'id',
    instance.id,
  );
  if (instance.invoice != null) {
    InvoiceOrId.encode(
      instance.invoice!,
      container.nestedSingleValueContainer('invoice').encoder,
    );
  }
  container.encodeBool(
    'livemode',
    instance.livemode,
  );
  if (instance.metadata != null) {
    container.encodeMap(
      'metadata',
      (container) => instance.metadata!.forEach((
        key,
        value,
      ) =>
          container.encodeString(
            key,
            value,
          )),
    );
  }
  container.encodeString(
    'object',
    'invoiceitem',
  );
  InvoiceLineItemPeriod.encode(
    instance.period,
    container.nestedSingleValueContainer('period').encoder,
  );
  if (instance.plan != null) {
    InvoiceitemPlan.encode(
      instance.plan!,
      container.nestedSingleValueContainer('plan').encoder,
    );
  }
  if (instance.price != null) {
    InvoiceitemPrice.encode(
      instance.price!,
      container.nestedSingleValueContainer('price').encoder,
    );
  }
  container.encodeBool(
    'proration',
    instance.proration,
  );
  container.encodeInt(
    'quantity',
    instance.quantity,
  );
  if (instance.subscription != null) {
    SubscriptionOrId.encode(
      instance.subscription!,
      container.nestedSingleValueContainer('subscription').encoder,
    );
  }
  if (instance.subscriptionItem != null) {
    container.encodeString(
      'subscription_item',
      instance.subscriptionItem!,
    );
  }
  if (instance.taxRates != null) {
    container.encodeList(
      'tax_rates',
      (container) => instance.taxRates!.forEach((el) => TaxRate.encode(
            el,
            container.nestedSingleValueContainer().encoder,
          )),
    );
  }
  if (instance.testClock != null) {
    TestHelpersTestClockOrId.encode(
      instance.testClock!,
      container.nestedSingleValueContainer('test_clock').encoder,
    );
  }
  if (instance.unitAmount != null) {
    container.encodeInt(
      'unit_amount',
      instance.unitAmount!,
    );
  }
  if (instance.unitAmountDecimal != null) {
    container.encodeString(
      'unit_amount_decimal',
      instance.unitAmountDecimal!,
    );
  }
  return container.value;
}