createCustomer method
Implementation
Future<Map> createCustomer(String name, String email,
{String? city, String? region, String? country}) async {
if (apiKey.isEmpty) {
return {'error': 'API key is empty'};
}
final Map<String, dynamic> data = {
'data': {
'type': 'customers',
'attributes': {
'name': name,
'email': email,
if (city != null) 'city': city,
if (region != null) 'region': region,
if (country != null) 'country': country,
},
}
};
Options dioOptions = Options(
headers: {
"Authorization ": "Bearer $apiKey",
"Accept": "application/vnd.api+json",
"Content-Type": "application/vnd.api+json",
},
);
try {
Response response = await dio.post(
"https://api.lemonsqueezy.com/v1/customers",
options: dioOptions,
data: data,
);
return response.data;
} catch (e) {
return {'error': e.toString()};
}
}