encode<V> static method

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

Implementation

static V encode<V>(
  SubscriptionCreateOptions instance,
  Encoder<V> encoder,
) {
  final container = encoder.container<String>();
  if (instance.addInvoiceItems != null) {
    container.encodeList(
      'add_invoice_items',
      (container) => instance.addInvoiceItems!
          .forEach((el) => SubscriptionScheduleAddInvoiceItemsItem.encode(
                el,
                container.nestedSingleValueContainer().encoder,
              )),
    );
  }
  if (instance.applicationFeePercent != null) {
    container.encodeDouble(
      'application_fee_percent',
      instance.applicationFeePercent!,
    );
  }
  if (instance.automaticTax != null) {
    SessionAutomaticTax.encode(
      instance.automaticTax!,
      container.nestedSingleValueContainer('automatic_tax').encoder,
    );
  }
  if (instance.backdateStartDate != null) {
    container.encodeDateTime(
      'backdate_start_date',
      instance.backdateStartDate!,
    );
  }
  if (instance.billingCycleAnchor != null) {
    container.encodeDateTime(
      'billing_cycle_anchor',
      instance.billingCycleAnchor!,
    );
  }
  if (instance.billingCycleAnchorConfig != null) {
    SubscriptionCreateOptionsBillingCycleAnchorConfig.encode(
      instance.billingCycleAnchorConfig!,
      container
          .nestedSingleValueContainer('billing_cycle_anchor_config')
          .encoder,
    );
  }
  if (instance.billingThresholds != null) {
    SubscriptionScheduleBillingThresholds.encode(
      instance.billingThresholds!,
      container.nestedSingleValueContainer('billing_thresholds').encoder,
    );
  }
  if (instance.cancelAt != null) {
    container.encodeDateTime(
      'cancel_at',
      instance.cancelAt!,
    );
  }
  if (instance.cancelAtPeriodEnd != null) {
    container.encodeBool(
      'cancel_at_period_end',
      instance.cancelAtPeriodEnd!,
    );
  }
  if (instance.collectionMethod != null) {
    InvoiceCollectionMethod.encode(
      instance.collectionMethod!,
      container.nestedSingleValueContainer('collection_method').encoder,
    );
  }
  if (instance.coupon != null) {
    container.encodeString(
      'coupon',
      instance.coupon!,
    );
  }
  if (instance.currency != null) {
    container.encodeString(
      'currency',
      instance.currency!,
    );
  }
  container.encodeString(
    'customer',
    instance.customer,
  );
  if (instance.daysUntilDue != null) {
    container.encodeInt(
      'days_until_due',
      instance.daysUntilDue!,
    );
  }
  if (instance.defaultPaymentMethod != null) {
    container.encodeString(
      'default_payment_method',
      instance.defaultPaymentMethod!,
    );
  }
  if (instance.defaultSource != null) {
    container.encodeString(
      'default_source',
      instance.defaultSource!,
    );
  }
  if (instance.defaultTaxRates != null) {
    container.encodeList(
      'default_tax_rates',
      (container) => instance.defaultTaxRates!
          .forEach((el) => container.encodeString(el)),
    );
  }
  if (instance.description != null) {
    container.encodeString(
      'description',
      instance.description!,
    );
  }
  if (instance.expand != null) {
    container.encodeList(
      'expand',
      (container) =>
          instance.expand!.forEach((el) => container.encodeString(el)),
    );
  }
  if (instance.invoiceSettings != null) {
    SubscriptionInvoiceSettings.encode(
      instance.invoiceSettings!,
      container.nestedSingleValueContainer('invoice_settings').encoder,
    );
  }
  if (instance.items != null) {
    container.encodeList(
      'items',
      (container) => instance.items!
          .forEach((el) => SubscriptionScheduleItemsItem.encode(
                el,
                container.nestedSingleValueContainer().encoder,
              )),
    );
  }
  if (instance.metadata != null) {
    container.encodeMap(
      'metadata',
      (container) => instance.metadata!.forEach((
        key,
        value,
      ) =>
          container.encodeString(
            key,
            value,
          )),
    );
  }
  if (instance.offSession != null) {
    container.encodeBool(
      'off_session',
      instance.offSession!,
    );
  }
  if (instance.onBehalfOf != null) {
    container.encodeString(
      'on_behalf_of',
      instance.onBehalfOf!,
    );
  }
  if (instance.paymentBehavior != null) {
    SubscriptionItemPaymentBehavior.encode(
      instance.paymentBehavior!,
      container.nestedSingleValueContainer('payment_behavior').encoder,
    );
  }
  if (instance.paymentSettings != null) {
    SubscriptionCreateOptionsPaymentSettings.encode(
      instance.paymentSettings!,
      container.nestedSingleValueContainer('payment_settings').encoder,
    );
  }
  if (instance.pendingInvoiceItemInterval != null) {
    SessionRecurring.encode(
      instance.pendingInvoiceItemInterval!,
      container
          .nestedSingleValueContainer('pending_invoice_item_interval')
          .encoder,
    );
  }
  if (instance.promotionCode != null) {
    container.encodeString(
      'promotion_code',
      instance.promotionCode!,
    );
  }
  if (instance.prorationBehavior != null) {
    PortalSubscriptionCancelProrationBehavior.encode(
      instance.prorationBehavior!,
      container.nestedSingleValueContainer('proration_behavior').encoder,
    );
  }
  if (instance.transferData != null) {
    SessionTransferData.encode(
      instance.transferData!,
      container.nestedSingleValueContainer('transfer_data').encoder,
    );
  }
  if (instance.trialEnd != null) {
    container.encodePrimitive(
      'trial_end',
      instance.trialEnd!,
    );
  }
  if (instance.trialFromPlan != null) {
    container.encodeBool(
      'trial_from_plan',
      instance.trialFromPlan!,
    );
  }
  if (instance.trialPeriodDays != null) {
    container.encodeInt(
      'trial_period_days',
      instance.trialPeriodDays!,
    );
  }
  if (instance.trialSettings != null) {
    SessionTrialSettings.encode(
      instance.trialSettings!,
      container.nestedSingleValueContainer('trial_settings').encoder,
    );
  }
  return container.value;
}