sendToCustomerBackend static method

Future<bool> sendToCustomerBackend({
  1. required String transactionId,
  2. String? customerApiUrl,
  3. Map<String, String>? customHeaders,
})

Sends transaction ID to customer's backend

transactionId - The transaction ID from Regula's finalize step customerApiUrl - Customer's backend endpoint URL (optional, can be configured) customHeaders - Custom headers for customer's API (optional)

Implementation

static Future<bool> sendToCustomerBackend({
  required String transactionId,
  String? customerApiUrl,
  Map<String, String>? customHeaders,
}) async {
  try {
    // Use provided URL or default
    final url =
        customerApiUrl ?? 'https://customer-backend.com/api/verify-document';

    // Prepare headers with defaults and custom additions
    final headers = {
      'Content-Type': 'application/json',
      ...?customHeaders, // Spread custom headers if provided
    };

    // Prepare request body
    final body = jsonEncode({
      'transactionId': transactionId,
      'timestamp': DateTime.now().toIso8601String(),
    });

    // print("Sending transaction ID to customer backend: $url");

    // Make HTTP POST request
    final response = await http.post(
      Uri.parse(url),
      headers: headers,
      body: body,
    );

    if (response.statusCode >= 200 && response.statusCode < 300) {
      // print(
      //   "Successfully sent to customer backend. Status: ${response.statusCode}",
      // );
      // print("Response: ${response.body}");
      return true;
    } else {
      // print(
      //   "Failed to send to customer backend. Status: ${response.statusCode}",
      // );
      // print("Response: ${response.body}");
      return false;
    }
  } catch (e) {
    // print("Error sending to customer backend: $e");
    return false;
  }
}