Implementation
static V encode<V>(
Charge instance,
Encoder<V> encoder,
) {
final container = encoder.container<String>();
container.encodeInt(
'amount',
instance.amount,
);
container.encodeInt(
'amount_captured',
instance.amountCaptured,
);
container.encodeInt(
'amount_refunded',
instance.amountRefunded,
);
if (instance.application != null) {
ApplicationOrId.encode(
instance.application!,
container.nestedSingleValueContainer('application').encoder,
);
}
if (instance.applicationFee != null) {
ApplicationFeeOrId.encode(
instance.applicationFee!,
container.nestedSingleValueContainer('application_fee').encoder,
);
}
if (instance.applicationFeeAmount != null) {
container.encodeInt(
'application_fee_amount',
instance.applicationFeeAmount!,
);
}
if (instance.authorizationCode != null) {
container.encodeString(
'authorization_code',
instance.authorizationCode!,
);
}
if (instance.balanceTransaction != null) {
BalanceTransactionOrId.encode(
instance.balanceTransaction!,
container.nestedSingleValueContainer('balance_transaction').encoder,
);
}
BillingDetails.encode(
instance.billingDetails,
container.nestedSingleValueContainer('billing_details').encoder,
);
if (instance.calculatedStatementDescriptor != null) {
container.encodeString(
'calculated_statement_descriptor',
instance.calculatedStatementDescriptor!,
);
}
container.encodeBool(
'captured',
instance.captured,
);
container.encodeDateTime(
'created',
instance.created,
);
container.encodeString(
'currency',
instance.currency,
);
if (instance.customer != null) {
BankAccountCustomerOrId.encode(
instance.customer!,
container.nestedSingleValueContainer('customer').encoder,
);
}
if (instance.description != null) {
container.encodeString(
'description',
instance.description!,
);
}
container.encodeBool(
'disputed',
instance.disputed,
);
if (instance.failureBalanceTransaction != null) {
BalanceTransactionOrId.encode(
instance.failureBalanceTransaction!,
container
.nestedSingleValueContainer('failure_balance_transaction')
.encoder,
);
}
if (instance.failureCode != null) {
container.encodeString(
'failure_code',
instance.failureCode!,
);
}
if (instance.failureMessage != null) {
container.encodeString(
'failure_message',
instance.failureMessage!,
);
}
if (instance.fraudDetails != null) {
ChargeFraudDetails.encode(
instance.fraudDetails!,
container.nestedSingleValueContainer('fraud_details').encoder,
);
}
container.encodeString(
'id',
instance.id,
);
if (instance.invoice != null) {
InvoiceOrId.encode(
instance.invoice!,
container.nestedSingleValueContainer('invoice').encoder,
);
}
if (instance.level3 != null) {
Level3.encode(
instance.level3!,
container.nestedSingleValueContainer('level3').encoder,
);
}
container.encodeBool(
'livemode',
instance.livemode,
);
container.encodeMap(
'metadata',
(container) => instance.metadata.forEach((
key,
value,
) =>
container.encodeString(
key,
value,
)),
);
container.encodeString(
'object',
'charge',
);
if (instance.onBehalfOf != null) {
AccountOrId.encode(
instance.onBehalfOf!,
container.nestedSingleValueContainer('on_behalf_of').encoder,
);
}
if (instance.outcome != null) {
ChargeOutcome.encode(
instance.outcome!,
container.nestedSingleValueContainer('outcome').encoder,
);
}
container.encodeBool(
'paid',
instance.paid,
);
if (instance.paymentIntent != null) {
PaymentIntentOrId.encode(
instance.paymentIntent!,
container.nestedSingleValueContainer('payment_intent').encoder,
);
}
if (instance.paymentMethod != null) {
container.encodeString(
'payment_method',
instance.paymentMethod!,
);
}
if (instance.paymentMethodDetails != null) {
ChargePaymentMethodDetails.encode(
instance.paymentMethodDetails!,
container.nestedSingleValueContainer('payment_method_details').encoder,
);
}
if (instance.radarOptions != null) {
RadarRadarOptions.encode(
instance.radarOptions!,
container.nestedSingleValueContainer('radar_options').encoder,
);
}
if (instance.receiptEmail != null) {
container.encodeString(
'receipt_email',
instance.receiptEmail!,
);
}
if (instance.receiptNumber != null) {
container.encodeString(
'receipt_number',
instance.receiptNumber!,
);
}
if (instance.receiptUrl != null) {
container.encodeString(
'receipt_url',
instance.receiptUrl!,
);
}
container.encodeBool(
'refunded',
instance.refunded,
);
if (instance.refunds != null) {
ChargeRefunds.encode(
instance.refunds!,
container.nestedSingleValueContainer('refunds').encoder,
);
}
if (instance.review != null) {
ReviewOrId.encode(
instance.review!,
container.nestedSingleValueContainer('review').encoder,
);
}
if (instance.shipping != null) {
ChargeShipping.encode(
instance.shipping!,
container.nestedSingleValueContainer('shipping').encoder,
);
}
if (instance.source != null) {
ChargeSource.encode(
instance.source!,
container.nestedSingleValueContainer('source').encoder,
);
}
if (instance.sourceTransfer != null) {
TransferOrId.encode(
instance.sourceTransfer!,
container.nestedSingleValueContainer('source_transfer').encoder,
);
}
if (instance.statementDescriptor != null) {
container.encodeString(
'statement_descriptor',
instance.statementDescriptor!,
);
}
if (instance.statementDescriptorSuffix != null) {
container.encodeString(
'statement_descriptor_suffix',
instance.statementDescriptorSuffix!,
);
}
BankConnectionsResourceBalanceRefreshStatus.encode(
instance.status,
container.nestedSingleValueContainer('status').encoder,
);
if (instance.transfer != null) {
TransferOrId.encode(
instance.transfer!,
container.nestedSingleValueContainer('transfer').encoder,
);
}
if (instance.transferData != null) {
ChargeTransferData.encode(
instance.transferData!,
container.nestedSingleValueContainer('transfer_data').encoder,
);
}
if (instance.transferGroup != null) {
container.encodeString(
'transfer_group',
instance.transferGroup!,
);
}
return container.value;
}