encode<V> static method
V
encode<
V>( - PromotionCode instance,
- Encoder<V> encoder
)
override
Implementation
static V encode<V>(
PromotionCode instance,
Encoder<V> encoder,
) {
final container = encoder.container<String>();
container.encodeBool(
'active',
instance.active,
);
container.encodeString(
'code',
instance.code,
);
Coupon.encode(
instance.coupon,
container.nestedSingleValueContainer('coupon').encoder,
);
container.encodeDateTime(
'created',
instance.created,
);
if (instance.customer != null) {
BankAccountCustomerOrId.encode(
instance.customer!,
container.nestedSingleValueContainer('customer').encoder,
);
}
if (instance.expiresAt != null) {
container.encodeDateTime(
'expires_at',
instance.expiresAt!,
);
}
container.encodeString(
'id',
instance.id,
);
container.encodeBool(
'livemode',
instance.livemode,
);
if (instance.maxRedemptions != null) {
container.encodeInt(
'max_redemptions',
instance.maxRedemptions!,
);
}
if (instance.metadata != null) {
container.encodeMap(
'metadata',
(container) => instance.metadata!.forEach((
key,
value,
) =>
container.encodeString(
key,
value,
)),
);
}
container.encodeString(
'object',
'promotion_code',
);
PromotionCodesResourceRestrictions.encode(
instance.restrictions,
container.nestedSingleValueContainer('restrictions').encoder,
);
container.encodeInt(
'times_redeemed',
instance.timesRedeemed,
);
return container.value;
}