encode<V> static method

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

Implementation

static V encode<V>(
  InvoiceItemCreateOptions instance,
  Encoder<V> encoder,
) {
  final container = encoder.container<String>();
  if (instance.amount != null) {
    container.encodeInt(
      'amount',
      instance.amount!,
    );
  }
  if (instance.currency != null) {
    container.encodeString(
      'currency',
      instance.currency!,
    );
  }
  container.encodeString(
    'customer',
    instance.customer,
  );
  if (instance.description != null) {
    container.encodeString(
      'description',
      instance.description!,
    );
  }
  if (instance.discountable != null) {
    container.encodeBool(
      'discountable',
      instance.discountable!,
    );
  }
  if (instance.discounts != null) {
    container.encodeList(
      'discounts',
      (container) =>
          instance.discounts!.forEach((el) => InvoiceItemDiscountsItem.encode(
                el,
                container.nestedSingleValueContainer().encoder,
              )),
    );
  }
  if (instance.expand != null) {
    container.encodeList(
      'expand',
      (container) =>
          instance.expand!.forEach((el) => container.encodeString(el)),
    );
  }
  if (instance.invoice != null) {
    container.encodeString(
      'invoice',
      instance.invoice!,
    );
  }
  if (instance.metadata != null) {
    container.encodeMap(
      'metadata',
      (container) => instance.metadata!.forEach((
        key,
        value,
      ) =>
          container.encodeString(
            key,
            value,
          )),
    );
  }
  if (instance.period != null) {
    InvoiceLineItemPeriod.encode(
      instance.period!,
      container.nestedSingleValueContainer('period').encoder,
    );
  }
  if (instance.price != null) {
    container.encodeString(
      'price',
      instance.price!,
    );
  }
  if (instance.priceData != null) {
    InvoiceItemPriceData.encode(
      instance.priceData!,
      container.nestedSingleValueContainer('price_data').encoder,
    );
  }
  if (instance.quantity != null) {
    container.encodeInt(
      'quantity',
      instance.quantity!,
    );
  }
  if (instance.subscription != null) {
    container.encodeString(
      'subscription',
      instance.subscription!,
    );
  }
  if (instance.taxBehavior != null) {
    ShippingRateCurrencyOptionTaxBehavior.encode(
      instance.taxBehavior!,
      container.nestedSingleValueContainer('tax_behavior').encoder,
    );
  }
  if (instance.taxCode != null) {
    container.encodeString(
      'tax_code',
      instance.taxCode!,
    );
  }
  if (instance.taxRates != null) {
    container.encodeList(
      'tax_rates',
      (container) =>
          instance.taxRates!.forEach((el) => container.encodeString(el)),
    );
  }
  if (instance.unitAmount != null) {
    container.encodeInt(
      'unit_amount',
      instance.unitAmount!,
    );
  }
  if (instance.unitAmountDecimal != null) {
    container.encodeString(
      'unit_amount_decimal',
      instance.unitAmountDecimal!,
    );
  }
  return container.value;
}