Coupon.fromPresta constructor

Coupon.fromPresta(
  1. Map<String, dynamic> json
)

Implementation

Coupon.fromPresta(Map<String, dynamic> json) {
  try {
    code = json['code'];
    id = json['id'].toString();
    usageCount = int.parse(json['quantity'].toString());
    if (double.parse(json['reduction_percent']) > 0.0) {
      discountType = 'percent';
      amount = double.parse(json['reduction_percent']);
    } else {
      discountType = 'fixed_cart';
      amount = double.parse(json['reduction_amount']);
    }
    emailRestrictions = [];
    description = json['name'];
    minimumAmount = 0.0;
    maximumAmount = 0.0;
    dateExpires = DateTime.parse(json['date_to']);
    message = '';
  } catch (e) {
    // ignore: avoid_print
    print(e.toString());
  }
}