EnakPoint & EnakCoin wallet, PIN, outlet, order, community, reward
- Wallet EnakPoint & EnakCoin: beranda, riwayat, saldo kedaluwarsa, kode bayar, tukar EnakCoin, transfer - PIN (buat, ganti, lupa), outlet, riwayat order, game spin - Halaman community, webview, coming soon, dan ikon menu beranda baru - Redesign Reward Saya: kartu tiket, filter chip, detail kode + QR - Hapus customer point loader, menu, dan checkout lama - Base URL ke enaklo-pos-api.altru.id Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5954510b93
commit
f5e3075205
@@ -0,0 +1,94 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:data_channel/data_channel.dart';
|
||||
import 'package:dio/dio.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/wallet/wallet.dart';
|
||||
import '../wallet_dtos.dart';
|
||||
import '../wallet_response.dart';
|
||||
|
||||
/// Outlet (§4.4) dan riwayat order (§4.5).
|
||||
@injectable
|
||||
class CustomerRemoteDataProvider {
|
||||
final ApiClient _apiClient;
|
||||
final String _logName = 'CustomerRemoteDataProvider';
|
||||
|
||||
CustomerRemoteDataProvider(this._apiClient);
|
||||
|
||||
Future<DC<WalletFailure, List<OutletDto>>> fetchOutlets() => _request(
|
||||
'fetchOutlets',
|
||||
() => _apiClient.get(ApiPath.outlets, headers: getAuthorizationHeader()),
|
||||
(response) => ((response.data as Map)['data'] as List? ?? [])
|
||||
.map((e) => OutletDto.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, CustomerOrderPageDto>> fetchOrders({
|
||||
required int page,
|
||||
required int limit,
|
||||
}) => _request(
|
||||
'fetchOrders',
|
||||
() => _apiClient.get(
|
||||
ApiPath.orders,
|
||||
headers: getAuthorizationHeader(),
|
||||
params: {'page': page, 'limit': limit},
|
||||
),
|
||||
_parseOrderPage,
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, CustomerOrderDto>> fetchOrderDetail(String id) =>
|
||||
_request(
|
||||
'fetchOrderDetail',
|
||||
() => _apiClient.get(
|
||||
'${ApiPath.orders}/$id',
|
||||
headers: getAuthorizationHeader(),
|
||||
),
|
||||
(response) => CustomerOrderDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
/// `data` bisa berupa list langsung dengan `pagination` di envelope, atau
|
||||
/// objek `{ data, pagination }`.
|
||||
CustomerOrderPageDto _parseOrderPage(Response response) {
|
||||
final body = response.data as Map;
|
||||
final payload = body['data'];
|
||||
final rawItems = payload is Map ? payload['data'] : payload;
|
||||
final rawPagination = payload is Map
|
||||
? payload['pagination']
|
||||
: body['pagination'];
|
||||
|
||||
return CustomerOrderPageDto(
|
||||
items: (rawItems as List? ?? [])
|
||||
.map(
|
||||
(e) =>
|
||||
CustomerOrderDto.fromJson(Map<String, dynamic>.from(e as Map)),
|
||||
)
|
||||
.toList(),
|
||||
pagination: rawPagination is Map
|
||||
? WalletPaginationDto.fromJson(
|
||||
Map<String, dynamic>.from(rawPagination),
|
||||
)
|
||||
: const WalletPaginationDto(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<DC<WalletFailure, T>> _request<T>(
|
||||
String name,
|
||||
Future<Response> Function() call,
|
||||
T Function(Response response) parse,
|
||||
) async {
|
||||
try {
|
||||
final response = await call();
|
||||
final failure = parseWalletFailure(response);
|
||||
if (failure != null) return DC.error(failure);
|
||||
return DC.data(parse(response));
|
||||
} on ApiFailure catch (e, s) {
|
||||
log(name, name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(WalletFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:data_channel/data_channel.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.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/wallet/wallet.dart';
|
||||
import '../wallet_response.dart';
|
||||
|
||||
@injectable
|
||||
class DeviceLocalDataProvider {
|
||||
final FlutterSecureStorage _storage;
|
||||
|
||||
static const _deviceIdKey = 'device_id';
|
||||
static const _registeredKey = 'device_registered';
|
||||
|
||||
DeviceLocalDataProvider(this._storage);
|
||||
|
||||
/// ID unik & stabil per instalasi; dibuat sekali lalu disimpan.
|
||||
Future<String> deviceId() async {
|
||||
final saved = await _storage.read(key: _deviceIdKey);
|
||||
if (saved != null && saved.isNotEmpty) return saved;
|
||||
|
||||
final created = generateUuidV4();
|
||||
await _storage.write(key: _deviceIdKey, value: created);
|
||||
return created;
|
||||
}
|
||||
|
||||
Future<bool> isRegistered() async =>
|
||||
await _storage.read(key: _registeredKey) == 'true';
|
||||
|
||||
Future<void> setRegistered(bool value) =>
|
||||
_storage.write(key: _registeredKey, value: value.toString());
|
||||
}
|
||||
|
||||
@injectable
|
||||
class DeviceRemoteDataProvider {
|
||||
final ApiClient _apiClient;
|
||||
final String _logName = 'DeviceRemoteDataProvider';
|
||||
|
||||
DeviceRemoteDataProvider(this._apiClient);
|
||||
|
||||
Future<DC<WalletFailure, Unit>> register({
|
||||
required String deviceId,
|
||||
required String fcmToken,
|
||||
required String platform,
|
||||
required String appVersion,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _apiClient.put(
|
||||
ApiPath.devices,
|
||||
headers: getAuthorizationHeader(),
|
||||
data: {
|
||||
'device_id': deviceId,
|
||||
'fcm_token': fcmToken,
|
||||
'platform': platform,
|
||||
'app_version': appVersion,
|
||||
},
|
||||
);
|
||||
final failure = parseWalletFailure(response);
|
||||
if (failure != null) return DC.error(failure);
|
||||
return DC.data(unit);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('register', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(WalletFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<DC<WalletFailure, Unit>> unregister({required String deviceId}) async {
|
||||
try {
|
||||
final response = await _apiClient.delete(
|
||||
'${ApiPath.devices}/$deviceId',
|
||||
headers: getAuthorizationHeader(),
|
||||
);
|
||||
final failure = parseWalletFailure(response);
|
||||
if (failure != null) return DC.error(failure);
|
||||
return DC.data(unit);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('unregister', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(WalletFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:data_channel/data_channel.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../common/api/api_client.dart';
|
||||
import '../../../common/api/api_failure.dart';
|
||||
import '../../../common/api/interceptors/sensitive_aware_log_interceptor.dart';
|
||||
import '../../../common/function/app_function.dart';
|
||||
import '../../../common/url/api_path.dart';
|
||||
import '../../../domain/wallet/wallet.dart';
|
||||
import '../wallet_dtos.dart';
|
||||
import '../wallet_response.dart';
|
||||
|
||||
@injectable
|
||||
class PinRemoteDataProvider {
|
||||
final ApiClient _apiClient;
|
||||
final String _logName = 'PinRemoteDataProvider';
|
||||
|
||||
PinRemoteDataProvider(this._apiClient);
|
||||
|
||||
Future<DC<WalletFailure, PinStatusDto>> fetchStatus() => _request(
|
||||
'fetchStatus',
|
||||
() => _apiClient.get(ApiPath.pinStatus, headers: getAuthorizationHeader()),
|
||||
(response) => PinStatusDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, PinOtpDto>> requestOtp(PinOtpPurpose purpose) =>
|
||||
_request(
|
||||
'requestOtp',
|
||||
() => _apiClient.post(
|
||||
ApiPath.pinOtp,
|
||||
headers: getAuthorizationHeader(),
|
||||
data: {'purpose': purpose.apiValue},
|
||||
),
|
||||
(response) => PinOtpDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, PinStatusDto>> setup({
|
||||
required String otpToken,
|
||||
required String otpCode,
|
||||
required String pin,
|
||||
required String confirmPin,
|
||||
}) => _request(
|
||||
'setup',
|
||||
() => _apiClient.post(
|
||||
ApiPath.pin,
|
||||
headers: getAuthorizationHeader(),
|
||||
data: {
|
||||
'otp_token': otpToken,
|
||||
'otp_code': otpCode,
|
||||
'pin': pin,
|
||||
'confirm_pin': confirmPin,
|
||||
},
|
||||
extra: {kSensitiveRequest: true},
|
||||
),
|
||||
(response) => PinStatusDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, Unit>> change({
|
||||
required String oldPin,
|
||||
required String pin,
|
||||
required String confirmPin,
|
||||
}) => _request(
|
||||
'change',
|
||||
() => _apiClient.put(
|
||||
ApiPath.pin,
|
||||
headers: getAuthorizationHeader(),
|
||||
data: {'old_pin': oldPin, 'pin': pin, 'confirm_pin': confirmPin},
|
||||
extra: {kSensitiveRequest: true},
|
||||
),
|
||||
(_) => unit,
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, Unit>> reset({
|
||||
required String otpToken,
|
||||
required String otpCode,
|
||||
required String pin,
|
||||
required String confirmPin,
|
||||
}) => _request(
|
||||
'reset',
|
||||
() => _apiClient.post(
|
||||
ApiPath.pinReset,
|
||||
headers: getAuthorizationHeader(),
|
||||
data: {
|
||||
'otp_token': otpToken,
|
||||
'otp_code': otpCode,
|
||||
'pin': pin,
|
||||
'confirm_pin': confirmPin,
|
||||
},
|
||||
extra: {kSensitiveRequest: true},
|
||||
),
|
||||
(_) => unit,
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, T>> _request<T>(
|
||||
String name,
|
||||
Future<Response> Function() call,
|
||||
T Function(Response response) parse,
|
||||
) async {
|
||||
try {
|
||||
final response = await call();
|
||||
final failure = parseWalletFailure(response);
|
||||
if (failure != null) return DC.error(failure);
|
||||
return DC.data(parse(response));
|
||||
} on ApiFailure catch (e, s) {
|
||||
log(name, name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(WalletFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:data_channel/data_channel.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../common/api/api_client.dart';
|
||||
import '../../../common/api/api_failure.dart';
|
||||
import '../../../common/api/interceptors/sensitive_aware_log_interceptor.dart';
|
||||
import '../../../common/extension/extension.dart';
|
||||
import '../../../common/function/app_function.dart';
|
||||
import '../../../common/url/api_path.dart';
|
||||
import '../../../domain/wallet/wallet.dart';
|
||||
import '../wallet_dtos.dart';
|
||||
import '../wallet_response.dart';
|
||||
|
||||
@injectable
|
||||
class WalletRemoteDataProvider {
|
||||
final ApiClient _apiClient;
|
||||
final String _logName = 'WalletRemoteDataProvider';
|
||||
|
||||
WalletRemoteDataProvider(this._apiClient);
|
||||
|
||||
Future<DC<WalletFailure, WalletSummaryDto>> fetchWallet() => _request(
|
||||
'fetchWallet',
|
||||
() => _apiClient.get(ApiPath.wallet, headers: getAuthorizationHeader()),
|
||||
(response) => WalletSummaryDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, WalletTransactionPageDto>> fetchTransactions({
|
||||
required int page,
|
||||
required int limit,
|
||||
WalletCurrency? currency,
|
||||
List<WalletTransactionType> types = const [],
|
||||
DateTime? from,
|
||||
DateTime? to,
|
||||
}) => _request(
|
||||
'fetchTransactions',
|
||||
() => _apiClient.get(
|
||||
ApiPath.walletTransactions,
|
||||
headers: getAuthorizationHeader(),
|
||||
params: {
|
||||
'page': page,
|
||||
'limit': limit,
|
||||
if (currency != null) 'currency': currency.apiValue,
|
||||
if (types.isNotEmpty) 'type': types.map((e) => e.apiValue).join(','),
|
||||
if (from != null) 'from': from.toServerDate,
|
||||
if (to != null) 'to': to.toServerDate,
|
||||
},
|
||||
),
|
||||
_parseTransactionPage,
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, WalletExpiringDto>> fetchExpiring() => _request(
|
||||
'fetchExpiring',
|
||||
() => _apiClient.get(
|
||||
ApiPath.walletExpiring,
|
||||
headers: getAuthorizationHeader(),
|
||||
),
|
||||
(response) => WalletExpiringDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, PaymentCodeDto>> createPaymentCode({
|
||||
required String pin,
|
||||
}) => _request(
|
||||
'createPaymentCode',
|
||||
() => _apiClient.post(
|
||||
ApiPath.walletPaymentCode,
|
||||
headers: getAuthorizationHeader(),
|
||||
data: {'pin': pin},
|
||||
extra: {kSensitiveRequest: true},
|
||||
),
|
||||
(response) => PaymentCodeDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, ExchangePreviewDto>> previewExchange({
|
||||
required int coins,
|
||||
}) => _request(
|
||||
'previewExchange',
|
||||
() => _apiClient.get(
|
||||
ApiPath.walletExchangePreview,
|
||||
headers: getAuthorizationHeader(),
|
||||
params: {'coins': coins},
|
||||
),
|
||||
(response) => ExchangePreviewDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, ExchangeResultDto>> exchange({
|
||||
required int coins,
|
||||
required String pin,
|
||||
required String idempotencyKey,
|
||||
}) => _request(
|
||||
'exchange',
|
||||
() => _apiClient.post(
|
||||
ApiPath.walletExchange,
|
||||
headers: {...getAuthorizationHeader(), 'Idempotency-Key': idempotencyKey},
|
||||
data: {'coins': coins, 'pin': pin},
|
||||
extra: {kSensitiveRequest: true},
|
||||
),
|
||||
(response) => ExchangeResultDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, TransferRecipientDto>> checkRecipient({
|
||||
required String phone,
|
||||
}) => _request(
|
||||
'checkRecipient',
|
||||
() => _apiClient.get(
|
||||
ApiPath.walletTransferRecipient,
|
||||
headers: getAuthorizationHeader(),
|
||||
params: {'phone': phone},
|
||||
),
|
||||
(response) => TransferRecipientDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
Future<DC<WalletFailure, TransferResultDto>> transfer({
|
||||
required WalletCurrency currency,
|
||||
required int amount,
|
||||
required String recipientPhone,
|
||||
required String pin,
|
||||
required String idempotencyKey,
|
||||
}) => _request(
|
||||
'transfer',
|
||||
() => _apiClient.post(
|
||||
ApiPath.walletTransfer,
|
||||
headers: {...getAuthorizationHeader(), 'Idempotency-Key': idempotencyKey},
|
||||
data: {
|
||||
'currency': currency.apiValue,
|
||||
'amount': amount,
|
||||
'recipient_phone': recipientPhone,
|
||||
'pin': pin,
|
||||
},
|
||||
extra: {kSensitiveRequest: true},
|
||||
),
|
||||
(response) => TransferResultDto.fromJson(walletDataOf(response)),
|
||||
);
|
||||
|
||||
/// `data` bisa berupa list langsung dengan `pagination` di envelope, atau
|
||||
/// objek `{ data, pagination }`.
|
||||
WalletTransactionPageDto _parseTransactionPage(Response response) {
|
||||
final body = response.data as Map;
|
||||
final payload = body['data'];
|
||||
final rawItems = payload is Map ? payload['data'] : payload;
|
||||
final rawPagination = payload is Map
|
||||
? payload['pagination']
|
||||
: body['pagination'];
|
||||
|
||||
return WalletTransactionPageDto(
|
||||
items: (rawItems as List? ?? [])
|
||||
.map(
|
||||
(e) => WalletTransactionDto.fromJson(
|
||||
Map<String, dynamic>.from(e as Map),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
pagination: rawPagination is Map
|
||||
? WalletPaginationDto.fromJson(
|
||||
Map<String, dynamic>.from(rawPagination),
|
||||
)
|
||||
: const WalletPaginationDto(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<DC<WalletFailure, T>> _request<T>(
|
||||
String name,
|
||||
Future<Response> Function() call,
|
||||
T Function(Response response) parse,
|
||||
) async {
|
||||
try {
|
||||
final response = await call();
|
||||
final failure = parseWalletFailure(response);
|
||||
if (failure != null) return DC.error(failure);
|
||||
return DC.data(parse(response));
|
||||
} on ApiFailure catch (e, s) {
|
||||
log(name, name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(WalletFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user