finalizeAndSendToCustomer static method

Future<void> finalizeAndSendToCustomer({
  1. String? customerApiUrl,
  2. Map<String, String>? customHeaders,
})

Implementation

static Future<void> finalizeAndSendToCustomer({
  String? customerApiUrl,
  Map<String, String>? customHeaders,
}) async {
  var (action, info, error) = await DocumentReader.instance.finalizePackage();

  if (error != null) {
    // print("Finalize failed. Error: ${error.message}");
    throw Exception("Finalization failed: ${error.message}");
  } else if (action == DocReaderAction.COMPLETE && info != null) {
    // print("Finalize done. Transaction ID: ${info.transactionId!}");

    if (info.transactionId != null) {
      final success = await sendToCustomerBackend(
        transactionId: info.transactionId!,
        customerApiUrl: customerApiUrl,
        customHeaders: customHeaders,
      );

      if (!success) {
        throw Exception("Failed to send transaction ID to customer backend");
      }
    }
  }
}