implemented TPIN and quick pay within bank
This commit is contained in:
@@ -51,4 +51,43 @@ class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> checkTpin() async {
|
||||
try {
|
||||
final response = await _dio.get('/api/auth/tpin');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.data['tpinSet'] as bool;
|
||||
} else {
|
||||
throw AuthException('Failed to check TPIN status');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e.toString());
|
||||
}
|
||||
throw NetworkException('Network error during TPIN check');
|
||||
} catch (e) {
|
||||
throw UnexpectedException('Unexpected error during TPIN check: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setTpin(String tpin) async {
|
||||
try {
|
||||
final response = await _dio.post(
|
||||
'/api/auth/tpin',
|
||||
data: {'tpin': tpin},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw AuthException('Failed to set TPIN');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e.toString());
|
||||
}
|
||||
throw NetworkException('Network error during TPIN setup');
|
||||
} catch (e) {
|
||||
throw UnexpectedException('Unexpected error during TPIN setup: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
43
lib/api/services/payment_service.dart
Normal file
43
lib/api/services/payment_service.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:kmobile/data/models/payment_response.dart';
|
||||
import 'package:kmobile/data/models/transfer.dart';
|
||||
|
||||
class PaymentService {
|
||||
final Dio _dio;
|
||||
PaymentService(this._dio);
|
||||
|
||||
Future<PaymentResponse> processQuickPayWithinBank(Transfer transfer) async {
|
||||
try {
|
||||
await Future.delayed(const Duration(seconds: 3)); // Simulate delay
|
||||
final response =
|
||||
await _dio.post('/api/payment/transfer', data: transfer.toJson());
|
||||
|
||||
return PaymentResponse(
|
||||
isSuccess: true,
|
||||
date: DateTime.now(),
|
||||
creditedAccount: transfer.toAccount,
|
||||
amount: transfer.amount,
|
||||
currency: "INR",
|
||||
errorMessage: response.data['errorMessage'],
|
||||
errorCode: response.data['errorCode'],
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
log('DioException: ${e.toString()}');
|
||||
if (e.response?.data != null) {
|
||||
return PaymentResponse(
|
||||
isSuccess: false,
|
||||
errorMessage: e.response?.data['error'] ?? 'Unknown error',
|
||||
errorCode: e.response?.data['status'] ?? 'UNKNOWN_ERROR',
|
||||
);
|
||||
}
|
||||
throw Exception(
|
||||
'Failed to process quick pay within bank: ${e.toString()}');
|
||||
} catch (e) {
|
||||
log('Unexpected error: ${e.toString()}');
|
||||
throw Exception(
|
||||
'Failed to process quick pay within bank: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user