Implementation
static V encode<V>(
Subscription instance,
Encoder<V> encoder,
) {
final container = encoder.container<String>();
if (instance.application != null) {
BillingPortalConfigurationApplicationOrId.encode(
instance.application!,
container.nestedSingleValueContainer('application').encoder,
);
}
if (instance.applicationFeePercent != null) {
container.encodeDouble(
'application_fee_percent',
instance.applicationFeePercent!,
);
}
SubscriptionAutomaticTax.encode(
instance.automaticTax,
container.nestedSingleValueContainer('automatic_tax').encoder,
);
container.encodeDateTime(
'billing_cycle_anchor',
instance.billingCycleAnchor,
);
if (instance.billingCycleAnchorConfig != null) {
SubscriptionBillingCycleAnchorConfig.encode(
instance.billingCycleAnchorConfig!,
container
.nestedSingleValueContainer('billing_cycle_anchor_config')
.encoder,
);
}
if (instance.billingThresholds != null) {
SubscriptionBillingThresholds.encode(
instance.billingThresholds!,
container.nestedSingleValueContainer('billing_thresholds').encoder,
);
}
if (instance.cancelAt != null) {
container.encodeDateTime(
'cancel_at',
instance.cancelAt!,
);
}
container.encodeBool(
'cancel_at_period_end',
instance.cancelAtPeriodEnd,
);
if (instance.canceledAt != null) {
container.encodeDateTime(
'canceled_at',
instance.canceledAt!,
);
}
if (instance.cancellationDetails != null) {
CancellationDetails.encode(
instance.cancellationDetails!,
container.nestedSingleValueContainer('cancellation_details').encoder,
);
}
InvoiceCollectionMethod.encode(
instance.collectionMethod,
container.nestedSingleValueContainer('collection_method').encoder,
);
container.encodeDateTime(
'created',
instance.created,
);
container.encodeString(
'currency',
instance.currency,
);
container.encodeDateTime(
'current_period_end',
instance.currentPeriodEnd,
);
container.encodeDateTime(
'current_period_start',
instance.currentPeriodStart,
);
BankAccountCustomerOrId.encode(
instance.customer,
container.nestedSingleValueContainer('customer').encoder,
);
if (instance.daysUntilDue != null) {
container.encodeInt(
'days_until_due',
instance.daysUntilDue!,
);
}
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,
);
}
if (instance.defaultTaxRates != null) {
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.endedAt != null) {
container.encodeDateTime(
'ended_at',
instance.endedAt!,
);
}
container.encodeString(
'id',
instance.id,
);
SubscriptionItems.encode(
instance.items,
container.nestedSingleValueContainer('items').encoder,
);
if (instance.latestInvoice != null) {
InvoiceOrId.encode(
instance.latestInvoice!,
container.nestedSingleValueContainer('latest_invoice').encoder,
);
}
container.encodeBool(
'livemode',
instance.livemode,
);
container.encodeMap(
'metadata',
(container) => instance.metadata.forEach((
key,
value,
) =>
container.encodeString(
key,
value,
)),
);
if (instance.nextPendingInvoiceItemInvoice != null) {
container.encodeDateTime(
'next_pending_invoice_item_invoice',
instance.nextPendingInvoiceItemInvoice!,
);
}
container.encodeString(
'object',
'subscription',
);
if (instance.onBehalfOf != null) {
AccountOrId.encode(
instance.onBehalfOf!,
container.nestedSingleValueContainer('on_behalf_of').encoder,
);
}
if (instance.pauseCollection != null) {
SubscriptionPauseCollection.encode(
instance.pauseCollection!,
container.nestedSingleValueContainer('pause_collection').encoder,
);
}
if (instance.paymentSettings != null) {
SubscriptionPaymentSettings.encode(
instance.paymentSettings!,
container.nestedSingleValueContainer('payment_settings').encoder,
);
}
if (instance.pendingInvoiceItemInterval != null) {
SubscriptionPendingInvoiceItemInterval.encode(
instance.pendingInvoiceItemInterval!,
container
.nestedSingleValueContainer('pending_invoice_item_interval')
.encoder,
);
}
if (instance.pendingSetupIntent != null) {
SetupIntentOrId.encode(
instance.pendingSetupIntent!,
container.nestedSingleValueContainer('pending_setup_intent').encoder,
);
}
if (instance.pendingUpdate != null) {
SubscriptionPendingUpdate.encode(
instance.pendingUpdate!,
container.nestedSingleValueContainer('pending_update').encoder,
);
}
if (instance.schedule != null) {
SubscriptionScheduleOrId.encode(
instance.schedule!,
container.nestedSingleValueContainer('schedule').encoder,
);
}
container.encodeDateTime(
'start_date',
instance.startDate,
);
container.encodeString(
'status',
instance.status,
);
if (instance.testClock != null) {
TestHelpersTestClockOrId.encode(
instance.testClock!,
container.nestedSingleValueContainer('test_clock').encoder,
);
}
if (instance.transferData != null) {
SubscriptionTransferData.encode(
instance.transferData!,
container.nestedSingleValueContainer('transfer_data').encoder,
);
}
if (instance.trialEnd != null) {
container.encodeDateTime(
'trial_end',
instance.trialEnd!,
);
}
if (instance.trialSettings != null) {
PaymentLinkSubscriptionDataTrialSettings.encode(
instance.trialSettings!,
container.nestedSingleValueContainer('trial_settings').encoder,
);
}
if (instance.trialStart != null) {
container.encodeDateTime(
'trial_start',
instance.trialStart!,
);
}
return container.value;
}