checkFlightAvailability method
Future<void>
checkFlightAvailability()
Implementation
Future <void> checkFlightAvailability() async {
try{
isCheckingSeatAvailability.value = true;
_startCheckAvailabilityTimer();
var response = await Requests.getDio(highTimeout: true).get(
"booking/v4/${paymentDetails.value.bookingId}/check-availability",
);
if(response.statusCode == 200){
isCheckingSeatAvailability.value = false;
Map<String, dynamic> data = response.data;
if(data.containsKey('data')){
BookingHistory? history = data['data']!=null? BookingHistory.fromJson(data['data']) : null;
if(history!=null){
paymentDetails.value = paymentDetails.value.copyWith(
isNonDiscounted: history.isNonDiscounted,
status: history.status ?? '',
bookingId: history.id ?? '',
tripType: history.tripType ?? '',
bookingTrips: history.bookingTrips ?? [],
totalOnlinePrice: double.tryParse(history.totalOnlinePrice ?? '0') ?? 0,
totalDiscountedPrice: double.tryParse(history.totalDiscountedPrice ?? '0') ?? 0,
discountPercentage: history.discountPercentage.toString(),
totalDiscountedPriceBTC: history.totalDiscountedPriceBTC ?? 0,
totalTax: double.tryParse(history.totalTax ?? '0') ?? 0,
totalMilesEarned: history.milesEarned,
totalPassengers: history.passengers?.length ?? 0,
fromAirport: history.fromAirport,
toAirport: history.toAirport,
adults: history.passengers?.where((e)=>e.type == 'ADULT').length ?? 0,
children: history.passengers?.where((e)=>e.type == 'CHILD').length ?? 0,
infantsInSeat: history.passengers?.where((e)=>e.type == 'INFANTWITHSEAT').length ?? 0,
infantsInLap: history.passengers?.where((e)=>e.type == 'INFANT').length ?? 0,
searchCreditEarned: history.isNonDiscounted == true ? 0 : 200,
searchCreditUsed: history.searchCredit ?? 0,
passengers: history.passengers,
donationAmount: double.tryParse(history.donationAmount.toString()) ?? 0,
rateConfirmedAt: history.confirmedRateAt == null ? null : DateTime.tryParse(history.confirmedRateAt!),
isStillAvailable: history.isStillAvailable,
availabilityCheckedAt: history.availabilityCheckedAt,
availabilityCheckCounter: history.availabilityCheckCounter,
// approvedAt: history.approvedAt,
createdAt: history.createdAt
);
await storePayment();
if(history.isStillAvailable ?? false){
allowPayment.value = true;
_startSeatConfrimationTimer(FlightSearchUtils().convertUnixTimestampSecondsToDateTime(history.availabilityCheckedAt ?? 0));
}else{
allowPayment.value = false;
}
} else{
allowPayment.value = false;
}
}else{
allowPayment.value = false;
}
_stopCheckAvailabilityTimer();
Get.find<AuthenticationController>().getUserProfile();
}else{
isCheckingSeatAvailability.value = false;
allowPayment.value = false;
_stopCheckAvailabilityTimer();
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Failed",
message: response.data['message'] ?? "Something unexcepted happened, please try again",
);
}
}catch(e){
debugPrint("### Error $e");
isCheckingSeatAvailability.value = false;
allowPayment.value = false;
_stopCheckAvailabilityTimer();
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Failed",
message: "Something unexcepted happened, please try again",
);
}
}