registerCustomer method

Future<RegisterCustomerResult> registerCustomer(
  1. String customerId, [
  2. RegisterCustomerOptions? options
])

Register a customer ID for this client.

This should be called after generating a customer ID to associate it with optional customer information (email, name).

customerId - The customer ID from generateCustomerId() options - Optional customer information Returns registration result

Implementation

Future<RegisterCustomerResult> registerCustomer(
  String customerId, [
  RegisterCustomerOptions? options,
]) async {
  final response = await _post(
    '/api/customers',
    json.encode({
      'clientId': _clientId,
      'customerId': customerId,
      if (options?.email != null) 'email': options!.email,
      if (options?.name != null) 'name': options!.name,
    }),
  );

  if (response.statusCode != 200) {
    final error = json.decode(response.body) as Map<String, dynamic>;
    throw Exception(error['error'] ?? 'Failed to register customer');
  }

  return RegisterCustomerResult.fromJson(
    json.decode(response.body) as Map<String, dynamic>,
  );
}