encode<V> static method

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

Implementation

static V encode<V>(
  Invoice instance,
  Encoder<V> encoder,
) {
  final container = encoder.container<String>();
  if (instance.accountCountry != null) {
    container.encodeString(
      'account_country',
      instance.accountCountry!,
    );
  }
  if (instance.accountName != null) {
    container.encodeString(
      'account_name',
      instance.accountName!,
    );
  }
  if (instance.accountTaxIds != null) {
    container.encodeList(
      'account_tax_ids',
      (container) => instance.accountTaxIds!
          .forEach((el) => InvoiceAccountTaxIdsItemOrId.encode(
                el,
                container.nestedSingleValueContainer().encoder,
              )),
    );
  }
  container.encodeInt(
    'amount_due',
    instance.amountDue,
  );
  container.encodeInt(
    'amount_paid',
    instance.amountPaid,
  );
  container.encodeInt(
    'amount_remaining',
    instance.amountRemaining,
  );
  container.encodeInt(
    'amount_shipping',
    instance.amountShipping,
  );
  if (instance.application != null) {
    BillingPortalConfigurationApplicationOrId.encode(
      instance.application!,
      container.nestedSingleValueContainer('application').encoder,
    );
  }
  if (instance.applicationFeeAmount != null) {
    container.encodeInt(
      'application_fee_amount',
      instance.applicationFeeAmount!,
    );
  }
  container.encodeInt(
    'attempt_count',
    instance.attemptCount,
  );
  container.encodeBool(
    'attempted',
    instance.attempted,
  );
  if (instance.autoAdvance != null) {
    container.encodeBool(
      'auto_advance',
      instance.autoAdvance!,
    );
  }
  AutomaticTax.encode(
    instance.automaticTax,
    container.nestedSingleValueContainer('automatic_tax').encoder,
  );
  if (instance.billingReason != null) {
    container.encodeString(
      'billing_reason',
      instance.billingReason!,
    );
  }
  if (instance.charge != null) {
    ChargeOrId.encode(
      instance.charge!,
      container.nestedSingleValueContainer('charge').encoder,
    );
  }
  container.encodeString(
    'collection_method',
    instance.collectionMethod,
  );
  container.encodeDateTime(
    'created',
    instance.created,
  );
  container.encodeString(
    'currency',
    instance.currency,
  );
  if (instance.customFields != null) {
    container.encodeList(
      'custom_fields',
      (container) => instance.customFields!
          .forEach((el) => InvoiceSettingCustomField.encode(
                el,
                container.nestedSingleValueContainer().encoder,
              )),
    );
  }
  if (instance.customer != null) {
    BankAccountCustomerOrId.encode(
      instance.customer!,
      container.nestedSingleValueContainer('customer').encoder,
    );
  }
  if (instance.customerAddress != null) {
    Address.encode(
      instance.customerAddress!,
      container.nestedSingleValueContainer('customer_address').encoder,
    );
  }
  if (instance.customerEmail != null) {
    container.encodeString(
      'customer_email',
      instance.customerEmail!,
    );
  }
  if (instance.customerName != null) {
    container.encodeString(
      'customer_name',
      instance.customerName!,
    );
  }
  if (instance.customerPhone != null) {
    container.encodeString(
      'customer_phone',
      instance.customerPhone!,
    );
  }
  if (instance.customerShipping != null) {
    ChargeShipping.encode(
      instance.customerShipping!,
      container.nestedSingleValueContainer('customer_shipping').encoder,
    );
  }
  if (instance.customerTaxExempt != null) {
    CheckoutSessionCustomerDetailsTaxExempt.encode(
      instance.customerTaxExempt!,
      container.nestedSingleValueContainer('customer_tax_exempt').encoder,
    );
  }
  if (instance.customerTaxIds != null) {
    container.encodeList(
      'customer_tax_ids',
      (container) => instance.customerTaxIds!
          .forEach((el) => InvoicesResourceInvoiceTaxId.encode(
                el,
                container.nestedSingleValueContainer().encoder,
              )),
    );
  }
  if (instance.defaultPaymentMethod != null) {
    PaymentMethodOrId.encode(
      instance.defaultPaymentMethod!,
      container.nestedSingleValueContainer('default_payment_method').encoder,
    );
  }
  if (instance.defaultSource != null) {
    PaymentSourceOrId.encode(
      instance.defaultSource!,
      container.nestedSingleValueContainer('default_source').encoder,
    );
  }
  container.encodeList(
    'default_tax_rates',
    (container) => instance.defaultTaxRates.forEach((el) => TaxRate.encode(
          el,
          container.nestedSingleValueContainer().encoder,
        )),
  );
  if (instance.description != null) {
    container.encodeString(
      'description',
      instance.description!,
    );
  }
  if (instance.discount != null) {
    Discount.encode(
      instance.discount!,
      container.nestedSingleValueContainer('discount').encoder,
    );
  }
  if (instance.discounts != null) {
    container.encodeList(
      'discounts',
      (container) => instance.discounts!
          .forEach((el) => DiscountsResourceDiscountAmountDiscountOrId.encode(
                el,
                container.nestedSingleValueContainer().encoder,
              )),
    );
  }
  if (instance.dueDate != null) {
    container.encodeDateTime(
      'due_date',
      instance.dueDate!,
    );
  }
  if (instance.effectiveAt != null) {
    container.encodeDateTime(
      'effective_at',
      instance.effectiveAt!,
    );
  }
  if (instance.endingBalance != null) {
    container.encodeInt(
      'ending_balance',
      instance.endingBalance!,
    );
  }
  if (instance.footer != null) {
    container.encodeString(
      'footer',
      instance.footer!,
    );
  }
  if (instance.fromInvoice != null) {
    InvoiceFromInvoice.encode(
      instance.fromInvoice!,
      container.nestedSingleValueContainer('from_invoice').encoder,
    );
  }
  if (instance.hostedInvoiceUrl != null) {
    container.encodeString(
      'hosted_invoice_url',
      instance.hostedInvoiceUrl!,
    );
  }
  if (instance.id != null) {
    container.encodeString(
      'id',
      instance.id!,
    );
  }
  if (instance.invoicePdf != null) {
    container.encodeString(
      'invoice_pdf',
      instance.invoicePdf!,
    );
  }
  ConnectAccountReference.encode(
    instance.issuer,
    container.nestedSingleValueContainer('issuer').encoder,
  );
  if (instance.lastFinalizationError != null) {
    ApiErrors.encode(
      instance.lastFinalizationError!,
      container.nestedSingleValueContainer('last_finalization_error').encoder,
    );
  }
  if (instance.latestRevision != null) {
    InvoiceOrId.encode(
      instance.latestRevision!,
      container.nestedSingleValueContainer('latest_revision').encoder,
    );
  }
  InvoiceLines.encode(
    instance.lines,
    container.nestedSingleValueContainer('lines').encoder,
  );
  container.encodeBool(
    'livemode',
    instance.livemode,
  );
  if (instance.metadata != null) {
    container.encodeMap(
      'metadata',
      (container) => instance.metadata!.forEach((
        key,
        value,
      ) =>
          container.encodeString(
            key,
            value,
          )),
    );
  }
  if (instance.nextPaymentAttempt != null) {
    container.encodeDateTime(
      'next_payment_attempt',
      instance.nextPaymentAttempt!,
    );
  }
  if (instance.number != null) {
    container.encodeString(
      'number',
      instance.number!,
    );
  }
  container.encodeString(
    'object',
    'invoice',
  );
  if (instance.onBehalfOf != null) {
    AccountOrId.encode(
      instance.onBehalfOf!,
      container.nestedSingleValueContainer('on_behalf_of').encoder,
    );
  }
  container.encodeBool(
    'paid',
    instance.paid,
  );
  container.encodeBool(
    'paid_out_of_band',
    instance.paidOutOfBand,
  );
  if (instance.paymentIntent != null) {
    PaymentIntentOrId.encode(
      instance.paymentIntent!,
      container.nestedSingleValueContainer('payment_intent').encoder,
    );
  }
  InvoicesPaymentSettings.encode(
    instance.paymentSettings,
    container.nestedSingleValueContainer('payment_settings').encoder,
  );
  container.encodeDateTime(
    'period_end',
    instance.periodEnd,
  );
  container.encodeDateTime(
    'period_start',
    instance.periodStart,
  );
  container.encodeInt(
    'post_payment_credit_notes_amount',
    instance.postPaymentCreditNotesAmount,
  );
  container.encodeInt(
    'pre_payment_credit_notes_amount',
    instance.prePaymentCreditNotesAmount,
  );
  if (instance.quote != null) {
    QuoteOrId.encode(
      instance.quote!,
      container.nestedSingleValueContainer('quote').encoder,
    );
  }
  if (instance.receiptNumber != null) {
    container.encodeString(
      'receipt_number',
      instance.receiptNumber!,
    );
  }
  if (instance.rendering != null) {
    InvoiceRendering.encode(
      instance.rendering!,
      container.nestedSingleValueContainer('rendering').encoder,
    );
  }
  if (instance.renderingOptions != null) {
    InvoiceRenderingOptions.encode(
      instance.renderingOptions!,
      container.nestedSingleValueContainer('rendering_options').encoder,
    );
  }
  if (instance.shippingCost != null) {
    CheckoutSessionShippingCost.encode(
      instance.shippingCost!,
      container.nestedSingleValueContainer('shipping_cost').encoder,
    );
  }
  if (instance.shippingDetails != null) {
    ChargeShipping.encode(
      instance.shippingDetails!,
      container.nestedSingleValueContainer('shipping_details').encoder,
    );
  }
  container.encodeInt(
    'starting_balance',
    instance.startingBalance,
  );
  if (instance.statementDescriptor != null) {
    container.encodeString(
      'statement_descriptor',
      instance.statementDescriptor!,
    );
  }
  if (instance.status != null) {
    container.encodeString(
      'status',
      instance.status!,
    );
  }
  InvoicesResourceStatusTransitions.encode(
    instance.statusTransitions,
    container.nestedSingleValueContainer('status_transitions').encoder,
  );
  if (instance.subscription != null) {
    SubscriptionOrId.encode(
      instance.subscription!,
      container.nestedSingleValueContainer('subscription').encoder,
    );
  }
  if (instance.subscriptionDetails != null) {
    InvoiceSubscriptionDetails.encode(
      instance.subscriptionDetails!,
      container.nestedSingleValueContainer('subscription_details').encoder,
    );
  }
  if (instance.subscriptionProrationDate != null) {
    container.encodeInt(
      'subscription_proration_date',
      instance.subscriptionProrationDate!,
    );
  }
  container.encodeInt(
    'subtotal',
    instance.subtotal,
  );
  if (instance.subtotalExcludingTax != null) {
    container.encodeInt(
      'subtotal_excluding_tax',
      instance.subtotalExcludingTax!,
    );
  }
  if (instance.tax != null) {
    container.encodeInt(
      'tax',
      instance.tax!,
    );
  }
  if (instance.testClock != null) {
    TestHelpersTestClockOrId.encode(
      instance.testClock!,
      container.nestedSingleValueContainer('test_clock').encoder,
    );
  }
  if (instance.thresholdReason != null) {
    InvoiceThresholdReason.encode(
      instance.thresholdReason!,
      container.nestedSingleValueContainer('threshold_reason').encoder,
    );
  }
  container.encodeInt(
    'total',
    instance.total,
  );
  if (instance.totalDiscountAmounts != null) {
    container.encodeList(
      'total_discount_amounts',
      (container) => instance.totalDiscountAmounts!
          .forEach((el) => DiscountsResourceDiscountAmount.encode(
                el,
                container.nestedSingleValueContainer().encoder,
              )),
    );
  }
  if (instance.totalExcludingTax != null) {
    container.encodeInt(
      'total_excluding_tax',
      instance.totalExcludingTax!,
    );
  }
  container.encodeList(
    'total_tax_amounts',
    (container) =>
        instance.totalTaxAmounts.forEach((el) => InvoiceTaxAmount.encode(
              el,
              container.nestedSingleValueContainer().encoder,
            )),
  );
  if (instance.transferData != null) {
    ChargeTransferData.encode(
      instance.transferData!,
      container.nestedSingleValueContainer('transfer_data').encoder,
    );
  }
  if (instance.webhooksDeliveredAt != null) {
    container.encodeDateTime(
      'webhooks_delivered_at',
      instance.webhooksDeliveredAt!,
    );
  }
  return container.value;
}