encode<V> static method

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

Implementation

static V encode<V>(
  SubscriptionItem instance,
  Encoder<V> encoder,
) {
  final container = encoder.container<String>();
  if (instance.billingThresholds != null) {
    SubscriptionItemBillingThresholds.encode(
      instance.billingThresholds!,
      container.nestedSingleValueContainer('billing_thresholds').encoder,
    );
  }
  container.encodeInt(
    'created',
    instance.created,
  );
  container.encodeString(
    'id',
    instance.id,
  );
  container.encodeMap(
    'metadata',
    (container) => instance.metadata.forEach((
      key,
      value,
    ) =>
        container.encodeString(
          key,
          value,
        )),
  );
  container.encodeString(
    'object',
    'subscription_item',
  );
  Plan.encode(
    instance.plan,
    container.nestedSingleValueContainer('plan').encoder,
  );
  Price.encode(
    instance.price,
    container.nestedSingleValueContainer('price').encoder,
  );
  if (instance.quantity != null) {
    container.encodeInt(
      'quantity',
      instance.quantity!,
    );
  }
  container.encodeString(
    'subscription',
    instance.subscription,
  );
  if (instance.taxRates != null) {
    container.encodeList(
      'tax_rates',
      (container) => instance.taxRates!.forEach((el) => TaxRate.encode(
            el,
            container.nestedSingleValueContainer().encoder,
          )),
    );
  }
  return container.value;
}