CouponCreateOptions.fromJson constructor
CouponCreateOptions.fromJson(
- Object? json
Implementation
factory CouponCreateOptions.fromJson(Object? json) {
final map = (json as Map).cast<String, Object?>();
return CouponCreateOptions(
amountOff:
map['amount_off'] == null ? null : (map['amount_off'] as num).toInt(),
appliesTo: map['applies_to'] == null
? null
: CouponAppliesTo.fromJson(map['applies_to']),
currency: map['currency'] == null ? null : (map['currency'] as String),
currencyOptions: map['currency_options'] == null
? null
: (map['currency_options'] as Map).cast<String, Object?>().map((
key,
value,
) =>
MapEntry(
key,
CouponCurrencyOption.fromJson(value),
)),
duration: map['duration'] == null
? null
: CouponDuration.fromJson(map['duration']),
durationInMonths: map['duration_in_months'] == null
? null
: (map['duration_in_months'] as num).toInt(),
expand: map['expand'] == null
? null
: (map['expand'] as List<Object?>)
.map((el) => (el as String))
.toList(),
id: map['id'] == null ? null : (map['id'] as String),
maxRedemptions: map['max_redemptions'] == null
? null
: (map['max_redemptions'] as num).toInt(),
metadata: map['metadata'] == null
? null
: (map['metadata'] as Map).cast<String, Object?>().map((
key,
value,
) =>
MapEntry(
key,
(value as String),
)),
name: map['name'] == null ? null : (map['name'] as String),
percentOff: map['percent_off'] == null
? null
: (map['percent_off'] as num).toDouble(),
redeemBy: map['redeem_by'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(
(map['redeem_by'] as int).toInt()),
);
}