encode<V> static method

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

Implementation

static V encode<V>(
  ShippingRate instance,
  Encoder<V> encoder,
) {
  final container = encoder.container<String>();
  container.encodeBool(
    'active',
    instance.active,
  );
  container.encodeDateTime(
    'created',
    instance.created,
  );
  if (instance.deliveryEstimate != null) {
    ShippingRateDeliveryEstimate.encode(
      instance.deliveryEstimate!,
      container.nestedSingleValueContainer('delivery_estimate').encoder,
    );
  }
  if (instance.displayName != null) {
    container.encodeString(
      'display_name',
      instance.displayName!,
    );
  }
  if (instance.fixedAmount != null) {
    ShippingRateFixedAmount.encode(
      instance.fixedAmount!,
      container.nestedSingleValueContainer('fixed_amount').encoder,
    );
  }
  container.encodeString(
    'id',
    instance.id,
  );
  container.encodeBool(
    'livemode',
    instance.livemode,
  );
  container.encodeMap(
    'metadata',
    (container) => instance.metadata.forEach((
      key,
      value,
    ) =>
        container.encodeString(
          key,
          value,
        )),
  );
  container.encodeString(
    'object',
    'shipping_rate',
  );
  if (instance.taxBehavior != null) {
    CurrencyOptionTaxBehavior.encode(
      instance.taxBehavior!,
      container.nestedSingleValueContainer('tax_behavior').encoder,
    );
  }
  if (instance.taxCode != null) {
    TaxCodeOrId.encode(
      instance.taxCode!,
      container.nestedSingleValueContainer('tax_code').encoder,
    );
  }
  container.encodeString(
    'type',
    'fixed_amount',
  );
  return container.value;
}