feat: payment split
This commit is contained in:
@@ -587,4 +587,39 @@ class OrderRemoteDatasource {
|
||||
return const Left('Terjadi kesalahan tak terduga');
|
||||
}
|
||||
}
|
||||
|
||||
Future<Either<String, PaymentSuccessResponseModel>> createPaymentSplitBill(
|
||||
PaymentSplitBillRequest request) async {
|
||||
final authData = await AuthLocalDataSource().getAuthData();
|
||||
final url = '${Variables.baseUrl}/api/v1/orders/split-bill';
|
||||
|
||||
try {
|
||||
final response = await dio.post(
|
||||
url,
|
||||
data: request.toMap(),
|
||||
options: Options(
|
||||
headers: {
|
||||
'Authorization': 'Bearer ${authData.token}',
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return Right(PaymentSuccessResponseModel.fromMap(response.data));
|
||||
} else {
|
||||
return const Left('Gagal membuat pembayaran');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
final errorMessage =
|
||||
e.response?.data['message'] ?? 'Terjadi kesalahan, coba lagi nanti.';
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,3 +78,57 @@ class PaymentOrderItemModel {
|
||||
"amount": amount,
|
||||
};
|
||||
}
|
||||
|
||||
class PaymentSplitBillRequest {
|
||||
final String orderId;
|
||||
final String paymentMethodId;
|
||||
final String customerId;
|
||||
final String type; // e.g., "AMOUNT" or "ITEM"
|
||||
final int amount;
|
||||
final List<SplitItem> items;
|
||||
|
||||
PaymentSplitBillRequest({
|
||||
required this.orderId,
|
||||
required this.paymentMethodId,
|
||||
required this.customerId,
|
||||
required this.type,
|
||||
required this.amount,
|
||||
required this.items,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
Map<String, dynamic> data = {
|
||||
'order_id': orderId,
|
||||
'payment_method_id': paymentMethodId,
|
||||
'customer_id': customerId,
|
||||
'type': type,
|
||||
};
|
||||
|
||||
if (type == "AMOUNT") {
|
||||
data['amount'] = amount;
|
||||
}
|
||||
|
||||
if (type == "ITEM") {
|
||||
data['items'] = items.map((e) => e.toJson()).toList();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class SplitItem {
|
||||
final String orderItemId;
|
||||
final int quantity;
|
||||
|
||||
SplitItem({
|
||||
required this.orderItemId,
|
||||
required this.quantity,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'order_item_id': orderItemId,
|
||||
'quantity': quantity,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user