41 lines
1.2 KiB
Dart
41 lines
1.2 KiB
Dart
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
|
|
await _dio.post('/api/payment/transfer', data: transfer.toJson());
|
|
|
|
return PaymentResponse(
|
|
isSuccess: true,
|
|
date: DateTime.now(),
|
|
creditedAccount: transfer.toAccount,
|
|
amount: transfer.amount,
|
|
currency: "INR",
|
|
);
|
|
} 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()}');
|
|
}
|
|
}
|
|
}
|