create promocode page

This commit is contained in:
2026-06-01 14:35:46 +03:00
parent 134ffdde60
commit 0b6757e26f
13 changed files with 343 additions and 112 deletions

View File

@@ -1150,4 +1150,31 @@ class ApiService {
}
return null;
}
Future<Map<String, dynamic>> applyPromoCode(String code) async {
final token = await _securityService.getAccessToken();
if (token == null) throw Exception('No access token');
final response = await _dio.post(
'$baseUrl/promocode/apply',
data: {'code': code},
options: Options(
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
},
),
);
if (response.statusCode == 201 || response.statusCode == 200) {
return response.data;
} else if (response.statusCode == 404) {
throw PromoCodeNotFoundException();
} else {
throw Exception('API Error: ${response.statusCode}');
}
}
}
// ✅ Добавь исключение (можно в отдельный файл)
class PromoCodeNotFoundException implements Exception {}