downloadInvoice method

dynamic downloadInvoice(
  1. BookingHistory history
)

Implementation

downloadInvoice(BookingHistory history) async {
  final url = history.payment?.invoiceUrl ?? '';
  if (url.isEmpty) {
    try {
      var response = await Requests.getDio().get(
        "booking/${history.id}/download-invoice",
      );

      if (response.statusCode == 200) {
        final url = response.data['url'];
        await TicketService.downloadTicket(url, 'Invoice', 'invoice.pdf');
      } else {
        debugPrint("Error downloading invoice ${response.data}");
        CustomFlashWidget.showFlashMessage(
          title: "Error",
          message: response.data["message"] ?? 'Error downloading invoice',
          type: FlashType.error,
        );
      }
    } catch (e) {
      debugPrint("Error downloading invoice ${e.toString()}");
      CustomFlashWidget.showFlashMessage(
        title: "Error",
        message: 'Error downloading invoice',
        type: FlashType.error,
      );
    }
  } else {
    await TicketService.downloadTicket(url, 'Invoice', 'invoice.pdf');
  }
}