clearCart method
Implementation
void clearCart(ClearCart clearCart) async {
clearCart.onLoading();
final url = "https://api.plentrasphere.com/v2/client/index.php";
final body = {
'class': 'cart',
"appKey": appKey,
"action": "clearCart",
};
try {
final response = await http.post(
Uri.parse(url),
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization': 'Bearer $token'
},
body: body,
);
final data = json.decode(response.body);
int code = data['response']['code'];
String status = data['response']['status'];
if (code == 400) {
if (status == "session-expired" || status == "please-login") {
clearCart.onNotLoggedIn();
clearCart.onLoadfinished();
return;
}
if (status == "app-expired") {
clearCart.onAppNotActive(data['info']['appName']);
clearCart.onLoadfinished();
return;
}
clearCart.onError(status);
clearCart.onLoadfinished();
return;
}
clearCart.onSuccess(status);
clearCart.onLoadfinished();
} catch (e) {
clearCart.onError(e.toString());
clearCart.onLoadfinished();
}
}