PromotionCode.fromJson constructor

PromotionCode.fromJson(
  1. Object? json
)

Implementation

factory PromotionCode.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return PromotionCode(
    active: (map['active'] as bool),
    code: (map['code'] as String),
    coupon: Coupon.fromJson(map['coupon']),
    created:
        DateTime.fromMillisecondsSinceEpoch((map['created'] as int).toInt()),
    customer: map['customer'] == null
        ? null
        : BankAccountCustomerOrId.fromJson(map['customer']),
    expiresAt: map['expires_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['expires_at'] as int).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),
                )),
    restrictions:
        PromotionCodesResourceRestrictions.fromJson(map['restrictions']),
    timesRedeemed: (map['times_redeemed'] as num).toInt(),
  );
}