payment method

This commit is contained in:
efrilm
2025-10-27 14:24:29 +07:00
parent 3135dde317
commit 9e5a6cc7ae
22 changed files with 3058 additions and 2 deletions
@@ -0,0 +1,45 @@
import 'dart:developer';
import 'package:data_channel/data_channel.dart';
import 'package:injectable/injectable.dart';
import '../../../common/api/api_client.dart';
import '../../../common/api/api_failure.dart';
import '../../../common/function/app_function.dart';
import '../../../common/url/api_path.dart';
import '../../../domain/payment_method/payment_method.dart';
import '../payment_method_dtos.dart';
@injectable
class PaymentMethodRemoteDataProvider {
final ApiClient _apiClient;
final _logName = 'PaymentMethodRemoteDataProvider';
PaymentMethodRemoteDataProvider(this._apiClient);
Future<DC<PaymentMethodFailure, ListPaymentMethodDto>> fetchPaymentMethods({
int page = 1,
int limit = 30,
}) async {
try {
final response = await _apiClient.get(
ApiPath.paymentMethods,
params: {'page': page, 'limit': limit},
headers: getAuthorizationHeader(),
);
if (response.data['success'] == false) {
return DC.error(PaymentMethodFailure.unexpectedError());
}
final paymentMethods = ListPaymentMethodDto.fromJson(
response.data['data'] as Map<String, dynamic>,
);
return DC.data(paymentMethods);
} on ApiFailure catch (e, s) {
log('fetchPaymentMethodsError', name: _logName, error: e, stackTrace: s);
return DC.error(PaymentMethodFailure.serverError(e));
}
}
}
@@ -0,0 +1,54 @@
part of '../payment_method_dtos.dart';
@freezed
class ListPaymentMethodDto with _$ListPaymentMethodDto {
const ListPaymentMethodDto._();
const factory ListPaymentMethodDto({
@JsonKey(name: "payment_methods") List<PaymentMethodDto>? paymentMethods,
@JsonKey(name: "total_count") int? totalCount,
@JsonKey(name: "page") int? page,
@JsonKey(name: "limit") int? limit,
@JsonKey(name: "total_pages") int? totalPages,
}) = _ListPaymentMethodDto;
factory ListPaymentMethodDto.fromJson(Map<String, dynamic> json) =>
_$ListPaymentMethodDtoFromJson(json);
ListPaymentMethod toDomain() => ListPaymentMethod(
paymentMethods: paymentMethods?.map((e) => e.toDomain()).toList() ?? [],
totalCount: totalCount ?? 0,
page: page ?? 0,
limit: limit ?? 0,
totalPages: totalPages ?? 0,
);
}
@freezed
class PaymentMethodDto with _$PaymentMethodDto {
const PaymentMethodDto._();
const factory PaymentMethodDto({
@JsonKey(name: "id") String? id,
@JsonKey(name: "organization_id") String? organizationId,
@JsonKey(name: "name") String? name,
@JsonKey(name: "type") String? type,
@JsonKey(name: "is_active") bool? isActive,
@JsonKey(name: "created_at") String? createdAt,
@JsonKey(name: "updated_at") String? updatedAt,
}) = _PaymentMethodDto;
factory PaymentMethodDto.fromJson(Map<String, dynamic> json) =>
_$PaymentMethodDtoFromJson(json);
/// Mapping ke domain
PaymentMethod toDomain() => PaymentMethod(
id: id ?? '',
organizationId: organizationId ?? '',
name: name ?? '',
type: type ?? '',
isActive: isActive ?? false,
createdAt: createdAt != null ? DateTime.parse(createdAt!) : DateTime(1970),
updatedAt: updatedAt != null ? DateTime.parse(updatedAt!) : DateTime(1970),
);
}
@@ -0,0 +1,8 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../domain/payment_method/payment_method.dart';
part 'payment_method_dtos.freezed.dart';
part 'payment_method_dtos.g.dart';
part 'dtos/payment_method_dto.dart';
@@ -0,0 +1,627 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'payment_method_dtos.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
ListPaymentMethodDto _$ListPaymentMethodDtoFromJson(Map<String, dynamic> json) {
return _ListPaymentMethodDto.fromJson(json);
}
/// @nodoc
mixin _$ListPaymentMethodDto {
@JsonKey(name: "payment_methods")
List<PaymentMethodDto>? get paymentMethods =>
throw _privateConstructorUsedError;
@JsonKey(name: "total_count")
int? get totalCount => throw _privateConstructorUsedError;
@JsonKey(name: "page")
int? get page => throw _privateConstructorUsedError;
@JsonKey(name: "limit")
int? get limit => throw _privateConstructorUsedError;
@JsonKey(name: "total_pages")
int? get totalPages => throw _privateConstructorUsedError;
/// Serializes this ListPaymentMethodDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of ListPaymentMethodDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ListPaymentMethodDtoCopyWith<ListPaymentMethodDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ListPaymentMethodDtoCopyWith<$Res> {
factory $ListPaymentMethodDtoCopyWith(
ListPaymentMethodDto value,
$Res Function(ListPaymentMethodDto) then,
) = _$ListPaymentMethodDtoCopyWithImpl<$Res, ListPaymentMethodDto>;
@useResult
$Res call({
@JsonKey(name: "payment_methods") List<PaymentMethodDto>? paymentMethods,
@JsonKey(name: "total_count") int? totalCount,
@JsonKey(name: "page") int? page,
@JsonKey(name: "limit") int? limit,
@JsonKey(name: "total_pages") int? totalPages,
});
}
/// @nodoc
class _$ListPaymentMethodDtoCopyWithImpl<
$Res,
$Val extends ListPaymentMethodDto
>
implements $ListPaymentMethodDtoCopyWith<$Res> {
_$ListPaymentMethodDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ListPaymentMethodDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? paymentMethods = freezed,
Object? totalCount = freezed,
Object? page = freezed,
Object? limit = freezed,
Object? totalPages = freezed,
}) {
return _then(
_value.copyWith(
paymentMethods: freezed == paymentMethods
? _value.paymentMethods
: paymentMethods // ignore: cast_nullable_to_non_nullable
as List<PaymentMethodDto>?,
totalCount: freezed == totalCount
? _value.totalCount
: totalCount // ignore: cast_nullable_to_non_nullable
as int?,
page: freezed == page
? _value.page
: page // ignore: cast_nullable_to_non_nullable
as int?,
limit: freezed == limit
? _value.limit
: limit // ignore: cast_nullable_to_non_nullable
as int?,
totalPages: freezed == totalPages
? _value.totalPages
: totalPages // ignore: cast_nullable_to_non_nullable
as int?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$ListPaymentMethodDtoImplCopyWith<$Res>
implements $ListPaymentMethodDtoCopyWith<$Res> {
factory _$$ListPaymentMethodDtoImplCopyWith(
_$ListPaymentMethodDtoImpl value,
$Res Function(_$ListPaymentMethodDtoImpl) then,
) = __$$ListPaymentMethodDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: "payment_methods") List<PaymentMethodDto>? paymentMethods,
@JsonKey(name: "total_count") int? totalCount,
@JsonKey(name: "page") int? page,
@JsonKey(name: "limit") int? limit,
@JsonKey(name: "total_pages") int? totalPages,
});
}
/// @nodoc
class __$$ListPaymentMethodDtoImplCopyWithImpl<$Res>
extends _$ListPaymentMethodDtoCopyWithImpl<$Res, _$ListPaymentMethodDtoImpl>
implements _$$ListPaymentMethodDtoImplCopyWith<$Res> {
__$$ListPaymentMethodDtoImplCopyWithImpl(
_$ListPaymentMethodDtoImpl _value,
$Res Function(_$ListPaymentMethodDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of ListPaymentMethodDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? paymentMethods = freezed,
Object? totalCount = freezed,
Object? page = freezed,
Object? limit = freezed,
Object? totalPages = freezed,
}) {
return _then(
_$ListPaymentMethodDtoImpl(
paymentMethods: freezed == paymentMethods
? _value._paymentMethods
: paymentMethods // ignore: cast_nullable_to_non_nullable
as List<PaymentMethodDto>?,
totalCount: freezed == totalCount
? _value.totalCount
: totalCount // ignore: cast_nullable_to_non_nullable
as int?,
page: freezed == page
? _value.page
: page // ignore: cast_nullable_to_non_nullable
as int?,
limit: freezed == limit
? _value.limit
: limit // ignore: cast_nullable_to_non_nullable
as int?,
totalPages: freezed == totalPages
? _value.totalPages
: totalPages // ignore: cast_nullable_to_non_nullable
as int?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$ListPaymentMethodDtoImpl extends _ListPaymentMethodDto {
const _$ListPaymentMethodDtoImpl({
@JsonKey(name: "payment_methods")
final List<PaymentMethodDto>? paymentMethods,
@JsonKey(name: "total_count") this.totalCount,
@JsonKey(name: "page") this.page,
@JsonKey(name: "limit") this.limit,
@JsonKey(name: "total_pages") this.totalPages,
}) : _paymentMethods = paymentMethods,
super._();
factory _$ListPaymentMethodDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$ListPaymentMethodDtoImplFromJson(json);
final List<PaymentMethodDto>? _paymentMethods;
@override
@JsonKey(name: "payment_methods")
List<PaymentMethodDto>? get paymentMethods {
final value = _paymentMethods;
if (value == null) return null;
if (_paymentMethods is EqualUnmodifiableListView) return _paymentMethods;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
@override
@JsonKey(name: "total_count")
final int? totalCount;
@override
@JsonKey(name: "page")
final int? page;
@override
@JsonKey(name: "limit")
final int? limit;
@override
@JsonKey(name: "total_pages")
final int? totalPages;
@override
String toString() {
return 'ListPaymentMethodDto(paymentMethods: $paymentMethods, totalCount: $totalCount, page: $page, limit: $limit, totalPages: $totalPages)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ListPaymentMethodDtoImpl &&
const DeepCollectionEquality().equals(
other._paymentMethods,
_paymentMethods,
) &&
(identical(other.totalCount, totalCount) ||
other.totalCount == totalCount) &&
(identical(other.page, page) || other.page == page) &&
(identical(other.limit, limit) || other.limit == limit) &&
(identical(other.totalPages, totalPages) ||
other.totalPages == totalPages));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(_paymentMethods),
totalCount,
page,
limit,
totalPages,
);
/// Create a copy of ListPaymentMethodDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ListPaymentMethodDtoImplCopyWith<_$ListPaymentMethodDtoImpl>
get copyWith =>
__$$ListPaymentMethodDtoImplCopyWithImpl<_$ListPaymentMethodDtoImpl>(
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$ListPaymentMethodDtoImplToJson(this);
}
}
abstract class _ListPaymentMethodDto extends ListPaymentMethodDto {
const factory _ListPaymentMethodDto({
@JsonKey(name: "payment_methods")
final List<PaymentMethodDto>? paymentMethods,
@JsonKey(name: "total_count") final int? totalCount,
@JsonKey(name: "page") final int? page,
@JsonKey(name: "limit") final int? limit,
@JsonKey(name: "total_pages") final int? totalPages,
}) = _$ListPaymentMethodDtoImpl;
const _ListPaymentMethodDto._() : super._();
factory _ListPaymentMethodDto.fromJson(Map<String, dynamic> json) =
_$ListPaymentMethodDtoImpl.fromJson;
@override
@JsonKey(name: "payment_methods")
List<PaymentMethodDto>? get paymentMethods;
@override
@JsonKey(name: "total_count")
int? get totalCount;
@override
@JsonKey(name: "page")
int? get page;
@override
@JsonKey(name: "limit")
int? get limit;
@override
@JsonKey(name: "total_pages")
int? get totalPages;
/// Create a copy of ListPaymentMethodDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ListPaymentMethodDtoImplCopyWith<_$ListPaymentMethodDtoImpl>
get copyWith => throw _privateConstructorUsedError;
}
PaymentMethodDto _$PaymentMethodDtoFromJson(Map<String, dynamic> json) {
return _PaymentMethodDto.fromJson(json);
}
/// @nodoc
mixin _$PaymentMethodDto {
@JsonKey(name: "id")
String? get id => throw _privateConstructorUsedError;
@JsonKey(name: "organization_id")
String? get organizationId => throw _privateConstructorUsedError;
@JsonKey(name: "name")
String? get name => throw _privateConstructorUsedError;
@JsonKey(name: "type")
String? get type => throw _privateConstructorUsedError;
@JsonKey(name: "is_active")
bool? get isActive => throw _privateConstructorUsedError;
@JsonKey(name: "created_at")
String? get createdAt => throw _privateConstructorUsedError;
@JsonKey(name: "updated_at")
String? get updatedAt => throw _privateConstructorUsedError;
/// Serializes this PaymentMethodDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of PaymentMethodDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$PaymentMethodDtoCopyWith<PaymentMethodDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $PaymentMethodDtoCopyWith<$Res> {
factory $PaymentMethodDtoCopyWith(
PaymentMethodDto value,
$Res Function(PaymentMethodDto) then,
) = _$PaymentMethodDtoCopyWithImpl<$Res, PaymentMethodDto>;
@useResult
$Res call({
@JsonKey(name: "id") String? id,
@JsonKey(name: "organization_id") String? organizationId,
@JsonKey(name: "name") String? name,
@JsonKey(name: "type") String? type,
@JsonKey(name: "is_active") bool? isActive,
@JsonKey(name: "created_at") String? createdAt,
@JsonKey(name: "updated_at") String? updatedAt,
});
}
/// @nodoc
class _$PaymentMethodDtoCopyWithImpl<$Res, $Val extends PaymentMethodDto>
implements $PaymentMethodDtoCopyWith<$Res> {
_$PaymentMethodDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of PaymentMethodDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? organizationId = freezed,
Object? name = freezed,
Object? type = freezed,
Object? isActive = freezed,
Object? createdAt = freezed,
Object? updatedAt = freezed,
}) {
return _then(
_value.copyWith(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
organizationId: freezed == organizationId
? _value.organizationId
: organizationId // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
type: freezed == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as String?,
isActive: freezed == isActive
? _value.isActive
: isActive // ignore: cast_nullable_to_non_nullable
as bool?,
createdAt: freezed == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as String?,
updatedAt: freezed == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as String?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$PaymentMethodDtoImplCopyWith<$Res>
implements $PaymentMethodDtoCopyWith<$Res> {
factory _$$PaymentMethodDtoImplCopyWith(
_$PaymentMethodDtoImpl value,
$Res Function(_$PaymentMethodDtoImpl) then,
) = __$$PaymentMethodDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: "id") String? id,
@JsonKey(name: "organization_id") String? organizationId,
@JsonKey(name: "name") String? name,
@JsonKey(name: "type") String? type,
@JsonKey(name: "is_active") bool? isActive,
@JsonKey(name: "created_at") String? createdAt,
@JsonKey(name: "updated_at") String? updatedAt,
});
}
/// @nodoc
class __$$PaymentMethodDtoImplCopyWithImpl<$Res>
extends _$PaymentMethodDtoCopyWithImpl<$Res, _$PaymentMethodDtoImpl>
implements _$$PaymentMethodDtoImplCopyWith<$Res> {
__$$PaymentMethodDtoImplCopyWithImpl(
_$PaymentMethodDtoImpl _value,
$Res Function(_$PaymentMethodDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of PaymentMethodDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? organizationId = freezed,
Object? name = freezed,
Object? type = freezed,
Object? isActive = freezed,
Object? createdAt = freezed,
Object? updatedAt = freezed,
}) {
return _then(
_$PaymentMethodDtoImpl(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
organizationId: freezed == organizationId
? _value.organizationId
: organizationId // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
type: freezed == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as String?,
isActive: freezed == isActive
? _value.isActive
: isActive // ignore: cast_nullable_to_non_nullable
as bool?,
createdAt: freezed == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as String?,
updatedAt: freezed == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as String?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$PaymentMethodDtoImpl extends _PaymentMethodDto {
const _$PaymentMethodDtoImpl({
@JsonKey(name: "id") this.id,
@JsonKey(name: "organization_id") this.organizationId,
@JsonKey(name: "name") this.name,
@JsonKey(name: "type") this.type,
@JsonKey(name: "is_active") this.isActive,
@JsonKey(name: "created_at") this.createdAt,
@JsonKey(name: "updated_at") this.updatedAt,
}) : super._();
factory _$PaymentMethodDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$PaymentMethodDtoImplFromJson(json);
@override
@JsonKey(name: "id")
final String? id;
@override
@JsonKey(name: "organization_id")
final String? organizationId;
@override
@JsonKey(name: "name")
final String? name;
@override
@JsonKey(name: "type")
final String? type;
@override
@JsonKey(name: "is_active")
final bool? isActive;
@override
@JsonKey(name: "created_at")
final String? createdAt;
@override
@JsonKey(name: "updated_at")
final String? updatedAt;
@override
String toString() {
return 'PaymentMethodDto(id: $id, organizationId: $organizationId, name: $name, type: $type, isActive: $isActive, createdAt: $createdAt, updatedAt: $updatedAt)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PaymentMethodDtoImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.organizationId, organizationId) ||
other.organizationId == organizationId) &&
(identical(other.name, name) || other.name == name) &&
(identical(other.type, type) || other.type == type) &&
(identical(other.isActive, isActive) ||
other.isActive == isActive) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt) &&
(identical(other.updatedAt, updatedAt) ||
other.updatedAt == updatedAt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
id,
organizationId,
name,
type,
isActive,
createdAt,
updatedAt,
);
/// Create a copy of PaymentMethodDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$PaymentMethodDtoImplCopyWith<_$PaymentMethodDtoImpl> get copyWith =>
__$$PaymentMethodDtoImplCopyWithImpl<_$PaymentMethodDtoImpl>(
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$PaymentMethodDtoImplToJson(this);
}
}
abstract class _PaymentMethodDto extends PaymentMethodDto {
const factory _PaymentMethodDto({
@JsonKey(name: "id") final String? id,
@JsonKey(name: "organization_id") final String? organizationId,
@JsonKey(name: "name") final String? name,
@JsonKey(name: "type") final String? type,
@JsonKey(name: "is_active") final bool? isActive,
@JsonKey(name: "created_at") final String? createdAt,
@JsonKey(name: "updated_at") final String? updatedAt,
}) = _$PaymentMethodDtoImpl;
const _PaymentMethodDto._() : super._();
factory _PaymentMethodDto.fromJson(Map<String, dynamic> json) =
_$PaymentMethodDtoImpl.fromJson;
@override
@JsonKey(name: "id")
String? get id;
@override
@JsonKey(name: "organization_id")
String? get organizationId;
@override
@JsonKey(name: "name")
String? get name;
@override
@JsonKey(name: "type")
String? get type;
@override
@JsonKey(name: "is_active")
bool? get isActive;
@override
@JsonKey(name: "created_at")
String? get createdAt;
@override
@JsonKey(name: "updated_at")
String? get updatedAt;
/// Create a copy of PaymentMethodDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$PaymentMethodDtoImplCopyWith<_$PaymentMethodDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,53 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'payment_method_dtos.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$ListPaymentMethodDtoImpl _$$ListPaymentMethodDtoImplFromJson(
Map<String, dynamic> json,
) => _$ListPaymentMethodDtoImpl(
paymentMethods: (json['payment_methods'] as List<dynamic>?)
?.map((e) => PaymentMethodDto.fromJson(e as Map<String, dynamic>))
.toList(),
totalCount: (json['total_count'] as num?)?.toInt(),
page: (json['page'] as num?)?.toInt(),
limit: (json['limit'] as num?)?.toInt(),
totalPages: (json['total_pages'] as num?)?.toInt(),
);
Map<String, dynamic> _$$ListPaymentMethodDtoImplToJson(
_$ListPaymentMethodDtoImpl instance,
) => <String, dynamic>{
'payment_methods': instance.paymentMethods,
'total_count': instance.totalCount,
'page': instance.page,
'limit': instance.limit,
'total_pages': instance.totalPages,
};
_$PaymentMethodDtoImpl _$$PaymentMethodDtoImplFromJson(
Map<String, dynamic> json,
) => _$PaymentMethodDtoImpl(
id: json['id'] as String?,
organizationId: json['organization_id'] as String?,
name: json['name'] as String?,
type: json['type'] as String?,
isActive: json['is_active'] as bool?,
createdAt: json['created_at'] as String?,
updatedAt: json['updated_at'] as String?,
);
Map<String, dynamic> _$$PaymentMethodDtoImplToJson(
_$PaymentMethodDtoImpl instance,
) => <String, dynamic>{
'id': instance.id,
'organization_id': instance.organizationId,
'name': instance.name,
'type': instance.type,
'is_active': instance.isActive,
'created_at': instance.createdAt,
'updated_at': instance.updatedAt,
};
@@ -0,0 +1,38 @@
import 'dart:developer';
import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/payment_method/payment_method.dart';
import '../datasources/remote_data_provider.dart';
@Injectable(as: IPaymentMethodRepository)
class PaymentMethodRepository implements IPaymentMethodRepository {
final PaymentMethodRemoteDataProvider _remoteDataProvider;
final _logName = 'PaymentMethodRepository';
PaymentMethodRepository(this._remoteDataProvider);
@override
Future<Either<PaymentMethodFailure, ListPaymentMethod>> getPaymentMethods({
int page = 1,
int limit = 30,
}) async {
try {
final result = await _remoteDataProvider.fetchPaymentMethods(
page: page,
limit: limit,
);
if (result.hasError) {
return left(result.error!);
}
final paymentMethods = result.data!.toDomain();
return right(paymentMethods);
} catch (e) {
log('getPaymentMethodError', name: _logName, error: e);
return left(const PaymentMethodFailure.unexpectedError());
}
}
}