Coupon.fromJson constructor

Coupon.fromJson(
  1. Object? json
)

Implementation

factory Coupon.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return Coupon(
    amountOff:
        map['amount_off'] == null ? null : (map['amount_off'] as num).toInt(),
    appliesTo: map['applies_to'] == null
        ? null
        : CouponAppliesTo.fromJson(map['applies_to']),
    created:
        DateTime.fromMillisecondsSinceEpoch((map['created'] as int).toInt()),
    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: CouponDuration.fromJson(map['duration']),
    durationInMonths: map['duration_in_months'] == null
        ? null
        : (map['duration_in_months'] as num).toInt(),
    id: (map['id'] as String),
    livemode: (map['livemode'] as bool),
    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()),
    timesRedeemed: (map['times_redeemed'] as num).toInt(),
    valid: (map['valid'] as bool),
  );
}