fix: refund
This commit is contained in:
parent
37ed6686f8
commit
ae4f7b06ce
@ -535,12 +535,12 @@ class OrderRemoteDatasource {
|
||||
}
|
||||
|
||||
Future<Either<String, bool>> refundPayment({
|
||||
required String paymentId,
|
||||
required String orderId,
|
||||
required String reason,
|
||||
required int refundAmount,
|
||||
}) async {
|
||||
final authData = await AuthLocalDataSource().getAuthData();
|
||||
final url = '${Variables.baseUrl}/api/v1/payments/$paymentId/refund';
|
||||
final url = '${Variables.baseUrl}/api/v1/orders/$orderId/refund';
|
||||
|
||||
try {
|
||||
final response = await dio.post(
|
||||
@ -564,7 +564,7 @@ class OrderRemoteDatasource {
|
||||
return const Left('Gagal refund');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
final errorMessage = e.response?.data['message'] ?? 'Kesalahan jaringan';
|
||||
final errorMessage = 'Terjadi kesalahan coba lagi nanti';
|
||||
log("💥 Dio error: ${e.message}");
|
||||
log("💥 Dio response: ${e.response?.data}");
|
||||
return Left(errorMessage);
|
||||
|
||||
@ -19,7 +19,7 @@ class RefundBloc extends Bloc<RefundEvent, RefundState> {
|
||||
}
|
||||
|
||||
Future<void> _onRefundPayment(
|
||||
String paymentId,
|
||||
String orderId,
|
||||
String reason,
|
||||
int refundAmount,
|
||||
Emitter<RefundState> emit,
|
||||
@ -27,7 +27,7 @@ class RefundBloc extends Bloc<RefundEvent, RefundState> {
|
||||
emit(const RefundState.loading());
|
||||
|
||||
final result = await _orderRemoteDatasource.refundPayment(
|
||||
paymentId: paymentId,
|
||||
orderId: orderId,
|
||||
reason: reason,
|
||||
refundAmount: refundAmount,
|
||||
);
|
||||
|
||||
@ -16,24 +16,24 @@ final _privateConstructorUsedError = UnsupportedError(
|
||||
|
||||
/// @nodoc
|
||||
mixin _$RefundEvent {
|
||||
String get paymentId => throw _privateConstructorUsedError;
|
||||
String get orderId => throw _privateConstructorUsedError;
|
||||
String get reason => throw _privateConstructorUsedError;
|
||||
int get refundAmount => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(String paymentId, String reason, int refundAmount)
|
||||
required TResult Function(String orderId, String reason, int refundAmount)
|
||||
refundPayment,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(String paymentId, String reason, int refundAmount)?
|
||||
TResult? Function(String orderId, String reason, int refundAmount)?
|
||||
refundPayment,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(String paymentId, String reason, int refundAmount)?
|
||||
TResult Function(String orderId, String reason, int refundAmount)?
|
||||
refundPayment,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
@ -68,7 +68,7 @@ abstract class $RefundEventCopyWith<$Res> {
|
||||
RefundEvent value, $Res Function(RefundEvent) then) =
|
||||
_$RefundEventCopyWithImpl<$Res, RefundEvent>;
|
||||
@useResult
|
||||
$Res call({String paymentId, String reason, int refundAmount});
|
||||
$Res call({String orderId, String reason, int refundAmount});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@ -86,14 +86,14 @@ class _$RefundEventCopyWithImpl<$Res, $Val extends RefundEvent>
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? paymentId = null,
|
||||
Object? orderId = null,
|
||||
Object? reason = null,
|
||||
Object? refundAmount = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
paymentId: null == paymentId
|
||||
? _value.paymentId
|
||||
: paymentId // ignore: cast_nullable_to_non_nullable
|
||||
orderId: null == orderId
|
||||
? _value.orderId
|
||||
: orderId // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
reason: null == reason
|
||||
? _value.reason
|
||||
@ -115,7 +115,7 @@ abstract class _$$RefundPaymentImplCopyWith<$Res>
|
||||
__$$RefundPaymentImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({String paymentId, String reason, int refundAmount});
|
||||
$Res call({String orderId, String reason, int refundAmount});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@ -131,14 +131,14 @@ class __$$RefundPaymentImplCopyWithImpl<$Res>
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? paymentId = null,
|
||||
Object? orderId = null,
|
||||
Object? reason = null,
|
||||
Object? refundAmount = null,
|
||||
}) {
|
||||
return _then(_$RefundPaymentImpl(
|
||||
paymentId: null == paymentId
|
||||
? _value.paymentId
|
||||
: paymentId // ignore: cast_nullable_to_non_nullable
|
||||
orderId: null == orderId
|
||||
? _value.orderId
|
||||
: orderId // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
reason: null == reason
|
||||
? _value.reason
|
||||
@ -156,12 +156,12 @@ class __$$RefundPaymentImplCopyWithImpl<$Res>
|
||||
|
||||
class _$RefundPaymentImpl implements _RefundPayment {
|
||||
const _$RefundPaymentImpl(
|
||||
{required this.paymentId,
|
||||
{required this.orderId,
|
||||
required this.reason,
|
||||
required this.refundAmount});
|
||||
|
||||
@override
|
||||
final String paymentId;
|
||||
final String orderId;
|
||||
@override
|
||||
final String reason;
|
||||
@override
|
||||
@ -169,7 +169,7 @@ class _$RefundPaymentImpl implements _RefundPayment {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'RefundEvent.refundPayment(paymentId: $paymentId, reason: $reason, refundAmount: $refundAmount)';
|
||||
return 'RefundEvent.refundPayment(orderId: $orderId, reason: $reason, refundAmount: $refundAmount)';
|
||||
}
|
||||
|
||||
@override
|
||||
@ -177,15 +177,14 @@ class _$RefundPaymentImpl implements _RefundPayment {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$RefundPaymentImpl &&
|
||||
(identical(other.paymentId, paymentId) ||
|
||||
other.paymentId == paymentId) &&
|
||||
(identical(other.orderId, orderId) || other.orderId == orderId) &&
|
||||
(identical(other.reason, reason) || other.reason == reason) &&
|
||||
(identical(other.refundAmount, refundAmount) ||
|
||||
other.refundAmount == refundAmount));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, paymentId, reason, refundAmount);
|
||||
int get hashCode => Object.hash(runtimeType, orderId, reason, refundAmount);
|
||||
|
||||
/// Create a copy of RefundEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@ -198,30 +197,30 @@ class _$RefundPaymentImpl implements _RefundPayment {
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(String paymentId, String reason, int refundAmount)
|
||||
required TResult Function(String orderId, String reason, int refundAmount)
|
||||
refundPayment,
|
||||
}) {
|
||||
return refundPayment(paymentId, reason, refundAmount);
|
||||
return refundPayment(orderId, reason, refundAmount);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(String paymentId, String reason, int refundAmount)?
|
||||
TResult? Function(String orderId, String reason, int refundAmount)?
|
||||
refundPayment,
|
||||
}) {
|
||||
return refundPayment?.call(paymentId, reason, refundAmount);
|
||||
return refundPayment?.call(orderId, reason, refundAmount);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(String paymentId, String reason, int refundAmount)?
|
||||
TResult Function(String orderId, String reason, int refundAmount)?
|
||||
refundPayment,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (refundPayment != null) {
|
||||
return refundPayment(paymentId, reason, refundAmount);
|
||||
return refundPayment(orderId, reason, refundAmount);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
@ -257,12 +256,12 @@ class _$RefundPaymentImpl implements _RefundPayment {
|
||||
|
||||
abstract class _RefundPayment implements RefundEvent {
|
||||
const factory _RefundPayment(
|
||||
{required final String paymentId,
|
||||
{required final String orderId,
|
||||
required final String reason,
|
||||
required final int refundAmount}) = _$RefundPaymentImpl;
|
||||
|
||||
@override
|
||||
String get paymentId;
|
||||
String get orderId;
|
||||
@override
|
||||
String get reason;
|
||||
@override
|
||||
|
||||
@ -3,7 +3,7 @@ part of 'refund_bloc.dart';
|
||||
@freezed
|
||||
class RefundEvent with _$RefundEvent {
|
||||
const factory RefundEvent.refundPayment({
|
||||
required String paymentId,
|
||||
required String orderId,
|
||||
required String reason,
|
||||
required int refundAmount,
|
||||
}) = _RefundPayment;
|
||||
|
||||
@ -788,7 +788,7 @@ class _RefundPageState extends State<RefundPage> with TickerProviderStateMixin {
|
||||
// Trigger refund event
|
||||
context.read<RefundBloc>().add(
|
||||
RefundEvent.refundPayment(
|
||||
paymentId: widget.selectedOrder.id ??
|
||||
orderId: widget.selectedOrder.id ??
|
||||
'', // Assuming order ID is payment ID
|
||||
reason: reason,
|
||||
refundAmount: refundAmount,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user