encode<V> static method

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

Implementation

static V encode<V>(
  TaxTransaction instance,
  Encoder<V> encoder,
) {
  final container = encoder.container<String>();
  container.encodeDateTime(
    'created',
    instance.created,
  );
  container.encodeString(
    'currency',
    instance.currency,
  );
  if (instance.customer != null) {
    container.encodeString(
      'customer',
      instance.customer!,
    );
  }
  TaxProductResourceCustomerDetails.encode(
    instance.customerDetails,
    container.nestedSingleValueContainer('customer_details').encoder,
  );
  container.encodeString(
    'id',
    instance.id,
  );
  if (instance.lineItems != null) {
    TaxTransactionLineItems.encode(
      instance.lineItems!,
      container.nestedSingleValueContainer('line_items').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',
    'tax.transaction',
  );
  container.encodeString(
    'reference',
    instance.reference,
  );
  if (instance.reversal != null) {
    TaxTransactionReversal.encode(
      instance.reversal!,
      container.nestedSingleValueContainer('reversal').encoder,
    );
  }
  if (instance.shippingCost != null) {
    TaxCalculationShippingCost.encode(
      instance.shippingCost!,
      container.nestedSingleValueContainer('shipping_cost').encoder,
    );
  }
  container.encodeDateTime(
    'tax_date',
    instance.taxDate,
  );
  container.encodeString(
    'type',
    instance.type,
  );
  return container.value;
}