refund
This commit is contained in:
@@ -262,4 +262,27 @@ class OrderRemoteDataProvider {
|
||||
return DC.error(OrderFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<DC<OrderFailure, Unit>> refundPayment({
|
||||
required String id,
|
||||
required String reason,
|
||||
required int refundAmount,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _apiClient.post(
|
||||
'${ApiPath.orders}/$id/refund',
|
||||
data: {'refund_amount': refundAmount, 'reason': reason},
|
||||
headers: getAuthorizationHeader(),
|
||||
);
|
||||
|
||||
if (response.data['success'] == false) {
|
||||
return DC.error(OrderFailure.unexpectedError());
|
||||
}
|
||||
|
||||
return DC.data(unit);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('refundPaymnetError', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(OrderFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ class OrderDto with _$OrderDto {
|
||||
@JsonKey(name: "remaining_amount") int? remainingAmount,
|
||||
@JsonKey(name: "payment_status") String? paymentStatus,
|
||||
@JsonKey(name: "refund_amount") int? refundAmount,
|
||||
@JsonKey(name: "refund_reason") String? refundReason,
|
||||
@JsonKey(name: "is_void") bool? isVoid,
|
||||
@JsonKey(name: "is_refund") bool? isRefund,
|
||||
@JsonKey(name: "notes") String? notes,
|
||||
@@ -61,6 +62,7 @@ class OrderDto with _$OrderDto {
|
||||
_$OrderDtoFromJson(json);
|
||||
|
||||
// Optional: mapper ke domain entity
|
||||
|
||||
Order toDomain() => Order(
|
||||
id: id ?? '',
|
||||
orderNumber: orderNumber ?? '',
|
||||
@@ -88,6 +90,7 @@ class OrderDto with _$OrderDto {
|
||||
totalPaid: totalPaid ?? 0,
|
||||
paymentCount: paymentCount ?? 0,
|
||||
splitType: splitType ?? '',
|
||||
refundReason: refundReason ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -328,6 +328,8 @@ mixin _$OrderDto {
|
||||
String? get paymentStatus => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "refund_amount")
|
||||
int? get refundAmount => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "refund_reason")
|
||||
String? get refundReason => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "is_void")
|
||||
bool? get isVoid => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "is_refund")
|
||||
@@ -382,6 +384,7 @@ abstract class $OrderDtoCopyWith<$Res> {
|
||||
@JsonKey(name: "remaining_amount") int? remainingAmount,
|
||||
@JsonKey(name: "payment_status") String? paymentStatus,
|
||||
@JsonKey(name: "refund_amount") int? refundAmount,
|
||||
@JsonKey(name: "refund_reason") String? refundReason,
|
||||
@JsonKey(name: "is_void") bool? isVoid,
|
||||
@JsonKey(name: "is_refund") bool? isRefund,
|
||||
@JsonKey(name: "notes") String? notes,
|
||||
@@ -426,6 +429,7 @@ class _$OrderDtoCopyWithImpl<$Res, $Val extends OrderDto>
|
||||
Object? remainingAmount = freezed,
|
||||
Object? paymentStatus = freezed,
|
||||
Object? refundAmount = freezed,
|
||||
Object? refundReason = freezed,
|
||||
Object? isVoid = freezed,
|
||||
Object? isRefund = freezed,
|
||||
Object? notes = freezed,
|
||||
@@ -500,6 +504,10 @@ class _$OrderDtoCopyWithImpl<$Res, $Val extends OrderDto>
|
||||
? _value.refundAmount
|
||||
: refundAmount // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
refundReason: freezed == refundReason
|
||||
? _value.refundReason
|
||||
: refundReason // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
isVoid: freezed == isVoid
|
||||
? _value.isVoid
|
||||
: isVoid // ignore: cast_nullable_to_non_nullable
|
||||
@@ -575,6 +583,7 @@ abstract class _$$OrderDtoImplCopyWith<$Res>
|
||||
@JsonKey(name: "remaining_amount") int? remainingAmount,
|
||||
@JsonKey(name: "payment_status") String? paymentStatus,
|
||||
@JsonKey(name: "refund_amount") int? refundAmount,
|
||||
@JsonKey(name: "refund_reason") String? refundReason,
|
||||
@JsonKey(name: "is_void") bool? isVoid,
|
||||
@JsonKey(name: "is_refund") bool? isRefund,
|
||||
@JsonKey(name: "notes") String? notes,
|
||||
@@ -618,6 +627,7 @@ class __$$OrderDtoImplCopyWithImpl<$Res>
|
||||
Object? remainingAmount = freezed,
|
||||
Object? paymentStatus = freezed,
|
||||
Object? refundAmount = freezed,
|
||||
Object? refundReason = freezed,
|
||||
Object? isVoid = freezed,
|
||||
Object? isRefund = freezed,
|
||||
Object? notes = freezed,
|
||||
@@ -692,6 +702,10 @@ class __$$OrderDtoImplCopyWithImpl<$Res>
|
||||
? _value.refundAmount
|
||||
: refundAmount // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
refundReason: freezed == refundReason
|
||||
? _value.refundReason
|
||||
: refundReason // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
isVoid: freezed == isVoid
|
||||
? _value.isVoid
|
||||
: isVoid // ignore: cast_nullable_to_non_nullable
|
||||
@@ -760,6 +774,7 @@ class _$OrderDtoImpl extends _OrderDto {
|
||||
@JsonKey(name: "remaining_amount") this.remainingAmount,
|
||||
@JsonKey(name: "payment_status") this.paymentStatus,
|
||||
@JsonKey(name: "refund_amount") this.refundAmount,
|
||||
@JsonKey(name: "refund_reason") this.refundReason,
|
||||
@JsonKey(name: "is_void") this.isVoid,
|
||||
@JsonKey(name: "is_refund") this.isRefund,
|
||||
@JsonKey(name: "notes") this.notes,
|
||||
@@ -825,6 +840,9 @@ class _$OrderDtoImpl extends _OrderDto {
|
||||
@JsonKey(name: "refund_amount")
|
||||
final int? refundAmount;
|
||||
@override
|
||||
@JsonKey(name: "refund_reason")
|
||||
final String? refundReason;
|
||||
@override
|
||||
@JsonKey(name: "is_void")
|
||||
final bool? isVoid;
|
||||
@override
|
||||
@@ -884,7 +902,7 @@ class _$OrderDtoImpl extends _OrderDto {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'OrderDto(id: $id, orderNumber: $orderNumber, outletId: $outletId, userId: $userId, tableNumber: $tableNumber, orderType: $orderType, status: $status, subtotal: $subtotal, taxAmount: $taxAmount, discountAmount: $discountAmount, totalAmount: $totalAmount, totalCost: $totalCost, remainingAmount: $remainingAmount, paymentStatus: $paymentStatus, refundAmount: $refundAmount, isVoid: $isVoid, isRefund: $isRefund, notes: $notes, metadata: $metadata, createdAt: $createdAt, updatedAt: $updatedAt, orderItems: $orderItems, payments: $payments, totalPaid: $totalPaid, paymentCount: $paymentCount, splitType: $splitType)';
|
||||
return 'OrderDto(id: $id, orderNumber: $orderNumber, outletId: $outletId, userId: $userId, tableNumber: $tableNumber, orderType: $orderType, status: $status, subtotal: $subtotal, taxAmount: $taxAmount, discountAmount: $discountAmount, totalAmount: $totalAmount, totalCost: $totalCost, remainingAmount: $remainingAmount, paymentStatus: $paymentStatus, refundAmount: $refundAmount, refundReason: $refundReason, isVoid: $isVoid, isRefund: $isRefund, notes: $notes, metadata: $metadata, createdAt: $createdAt, updatedAt: $updatedAt, orderItems: $orderItems, payments: $payments, totalPaid: $totalPaid, paymentCount: $paymentCount, splitType: $splitType)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -919,6 +937,8 @@ class _$OrderDtoImpl extends _OrderDto {
|
||||
other.paymentStatus == paymentStatus) &&
|
||||
(identical(other.refundAmount, refundAmount) ||
|
||||
other.refundAmount == refundAmount) &&
|
||||
(identical(other.refundReason, refundReason) ||
|
||||
other.refundReason == refundReason) &&
|
||||
(identical(other.isVoid, isVoid) || other.isVoid == isVoid) &&
|
||||
(identical(other.isRefund, isRefund) ||
|
||||
other.isRefund == isRefund) &&
|
||||
@@ -960,6 +980,7 @@ class _$OrderDtoImpl extends _OrderDto {
|
||||
remainingAmount,
|
||||
paymentStatus,
|
||||
refundAmount,
|
||||
refundReason,
|
||||
isVoid,
|
||||
isRefund,
|
||||
notes,
|
||||
@@ -1004,6 +1025,7 @@ abstract class _OrderDto extends OrderDto {
|
||||
@JsonKey(name: "remaining_amount") final int? remainingAmount,
|
||||
@JsonKey(name: "payment_status") final String? paymentStatus,
|
||||
@JsonKey(name: "refund_amount") final int? refundAmount,
|
||||
@JsonKey(name: "refund_reason") final String? refundReason,
|
||||
@JsonKey(name: "is_void") final bool? isVoid,
|
||||
@JsonKey(name: "is_refund") final bool? isRefund,
|
||||
@JsonKey(name: "notes") final String? notes,
|
||||
@@ -1067,6 +1089,9 @@ abstract class _OrderDto extends OrderDto {
|
||||
@JsonKey(name: "refund_amount")
|
||||
int? get refundAmount;
|
||||
@override
|
||||
@JsonKey(name: "refund_reason")
|
||||
String? get refundReason;
|
||||
@override
|
||||
@JsonKey(name: "is_void")
|
||||
bool? get isVoid;
|
||||
@override
|
||||
|
||||
@@ -43,6 +43,7 @@ _$OrderDtoImpl _$$OrderDtoImplFromJson(Map<String, dynamic> json) =>
|
||||
remainingAmount: (json['remaining_amount'] as num?)?.toInt(),
|
||||
paymentStatus: json['payment_status'] as String?,
|
||||
refundAmount: (json['refund_amount'] as num?)?.toInt(),
|
||||
refundReason: json['refund_reason'] as String?,
|
||||
isVoid: json['is_void'] as bool?,
|
||||
isRefund: json['is_refund'] as bool?,
|
||||
notes: json['notes'] as String?,
|
||||
@@ -77,6 +78,7 @@ Map<String, dynamic> _$$OrderDtoImplToJson(_$OrderDtoImpl instance) =>
|
||||
'remaining_amount': instance.remainingAmount,
|
||||
'payment_status': instance.paymentStatus,
|
||||
'refund_amount': instance.refundAmount,
|
||||
'refund_reason': instance.refundReason,
|
||||
'is_void': instance.isVoid,
|
||||
'is_refund': instance.isRefund,
|
||||
'notes': instance.notes,
|
||||
|
||||
@@ -198,4 +198,26 @@ class OrderRepository implements IOrderRepository {
|
||||
return left(const OrderFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<OrderFailure, Unit>> refundOrder({
|
||||
required String id,
|
||||
required String reason,
|
||||
required int refundAmount,
|
||||
}) async {
|
||||
try {
|
||||
final result = await _dataProvider.refundPayment(
|
||||
id: id,
|
||||
reason: reason,
|
||||
refundAmount: refundAmount,
|
||||
);
|
||||
if (result.hasError) {
|
||||
return left(result.error!);
|
||||
}
|
||||
return right(unit);
|
||||
} catch (e) {
|
||||
log('refundOrderError', name: _logName, error: e);
|
||||
return left(const OrderFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user