PromotionCodeCreateOptions.fromJson constructor

PromotionCodeCreateOptions.fromJson(
  1. Object? json
)

Implementation

factory PromotionCodeCreateOptions.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return PromotionCodeCreateOptions(
    active: map['active'] == null ? null : (map['active'] as bool),
    code: map['code'] == null ? null : (map['code'] as String),
    coupon: (map['coupon'] as String),
    customer: map['customer'] == null ? null : (map['customer'] as String),
    expand: map['expand'] == null
        ? null
        : (map['expand'] as List<Object?>)
            .map((el) => (el as String))
            .toList(),
    expiresAt: map['expires_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['expires_at'] as int).toInt()),
    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),
                )),
    restrictions: map['restrictions'] == null
        ? null
        : PromotionCodeRestrictions.fromJson(map['restrictions']),
  );
}