Subscription.fromJson constructor

Subscription.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory Subscription.fromJson(Map<String, dynamic> json) {
  try {
    print("Parsing Subscription with ID: ${json['id']}");
    return Subscription(
      id: json['id'] ?? '',
      subscriberId: json['subscriberId'] ?? '',
      price: json['price'] ?? '',
      status: json['status'] ?? 'N/A',
      wallet: json['wallet'] ?? 'N/A',
      paymentHash: json['paymentHash'] ?? '',
      currency: json['currency'] ?? '',
      passengerChangeCounter: json['passengerChangeCounter'] ?? 0,
      package: json['package'] ?? '',
      name: json['name'] ?? '',
      expiryDate: json['expiryDate'] != null ? DateTime.parse(json['expiryDate']) : DateTime.now(),
      type: json['type'] ?? '',
      maxTotalBooking: json['maxTotalBooking'] ?? 0,
      neoMilesPaymentPercentage: json['neoMilesPaymentPercentage'] ?? 0,
      neoOneMonthlySubscription: json['neoOneMonthlySubscription'] ?? 0,
      paymentId: json['paymentId'] ?? '',
      createdAt: json['createdAt'] != null ? DateTime.parse(json['createdAt']) : DateTime.now(),
      updatedAt: json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : DateTime.now(),
    );
  } catch (e) {
    print("Error parsing Subscription: $e");
    return Subscription(
      id: '',
      subscriberId: '',
      price: '',
      status: 'N/A',
      wallet: 'N/A',
      paymentHash: '',
      currency: '',
      passengerChangeCounter: 0,
      package: '',
      name: '',
      expiryDate: DateTime.now(),
      type: '',
      maxTotalBooking: 0,
      neoMilesPaymentPercentage: 0,
      neoOneMonthlySubscription: 0,
      paymentId: '',
      createdAt: DateTime.now(),
      updatedAt: DateTime.now(),
    );
  }
}