feat: void order

This commit is contained in:
efrilm
2025-08-04 11:39:47 +07:00
parent cbfa1689ba
commit ee38b6218f
9 changed files with 824 additions and 114 deletions
@@ -418,7 +418,7 @@ class OrderRemoteDatasource {
'order_item_id': item.id,
"refund_quantity": item.quantity,
"refund_amount": item.totalPrice,
"reason": "Item was cold"
"reason": ""
})
.toList(),
'reason': reason,
@@ -447,4 +447,52 @@ class OrderRemoteDatasource {
return const Left('Terjadi kesalahan tak terduga');
}
}
Future<Either<String, bool>> voidOrder({
required String orderId,
required String reason,
String type = "ITEM", // TYPE: ALL, ITEM
required List<OrderItem> orderItems,
}) async {
final authData = await AuthLocalDataSource().getAuthData();
final url = '${Variables.baseUrl}/api/v1/orders/void';
try {
final response = await dio.post(
url,
data: {
'order_id': orderId,
'type': orderItems.isEmpty ? "ALL" : type,
'reason': reason,
"items": orderItems
.map((item) => {
'order_item_id': item.id,
"quantity": item.quantity,
})
.toList(),
},
options: Options(
headers: {
'Authorization': 'Bearer ${authData.token}',
'Accept': 'application/json',
'Content-Type': 'application/json',
},
),
);
if (response.statusCode == 200) {
return Right(true);
} else {
return const Left('Gagal refund');
}
} on DioException catch (e) {
final errorMessage = e.response?.data['message'] ?? 'Kesalahan jaringan';
log("💥 Dio error: ${e.message}");
log("💥 Dio response: ${e.response?.data}");
return Left(errorMessage);
} catch (e) {
log("💥 Unexpected error: $e");
return const Left('Terjadi kesalahan tak terduga');
}
}
}