createUsageRecord method
Implementation
Future<Map<String, dynamic>> createUsageRecord(int quantity,
{int? subscriptionItemId, String action = 'increment'}) async {
if (apiKey.isEmpty) {
return {'error': 'API key is empty'};
}
final Map<String, dynamic> data = {
'data': {
'type': 'usage-records',
'attributes': {
'quantity': quantity,
'action': action,
},
'relationships': {
'subscription-item': {
'data': {
'type': 'subscription-items',
'id': subscriptionItemId.toString(),
}
}
}
}
};
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/usage-records",
options: dioOptions,
data: data,
);
return response.data;
} catch (e) {
return {'error': e.toString()};
}
}