Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Mobile App CI / test (push) Waiting to run
Mobile App CI / build-android (push) Blocked by required conditions
Mobile App CI / build-ios (push) Blocked by required conditions
Web App CI / test (push) Waiting to run
Web App CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
Deploy Telegram Bot / Deploy Telegram Bot (push) Waiting to run
60 lines
1.9 KiB
Dart
60 lines
1.9 KiB
Dart
import 'package:injectable/injectable.dart';
|
||
import 'package:mnemo_cards_backend/api/purchase/payment_manager.dart';
|
||
import 'package:mnemo_cards_backend/database/database.dart';
|
||
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
||
import 'task.dart' as task;
|
||
|
||
@LazySingleton()
|
||
class CheckPaymentTask with task.Task {
|
||
final PaymentManager _paymentManager;
|
||
final AppDatabase _db;
|
||
|
||
CheckPaymentTask(this._paymentManager, this._db);
|
||
|
||
Future<void> task() => check();
|
||
|
||
Future<void> check() async {
|
||
print('Checking payments...');
|
||
|
||
// Получаем платежи, которые не обработаны и не unknown
|
||
final allPayments = await _db.paymentDao.getAllPayments();
|
||
|
||
final unprocessedPayments = allPayments.where((payment) {
|
||
final status = PaymentStatus.values.firstWhere(
|
||
(s) => s.name == payment.status,
|
||
orElse: () => PaymentStatus.unknown,
|
||
);
|
||
|
||
if (status == PaymentStatus.processed ||
|
||
status == PaymentStatus.unknown) {
|
||
return false;
|
||
}
|
||
|
||
final system = PaymentSystem.values.firstWhere(
|
||
(s) => s.name == payment.paymentSystem,
|
||
orElse: () => PaymentSystem.yookassa,
|
||
);
|
||
|
||
return system == PaymentSystem.yookassa ||
|
||
system == PaymentSystem.rustore;
|
||
}).toList();
|
||
|
||
print('Found ${unprocessedPayments.length} unprocessed payments');
|
||
for (final payment in unprocessedPayments) {
|
||
try {
|
||
// PaymentManager должен работать с Payment (Drift)
|
||
// TODO: Возможно нужна конвертация в PaymentModel если PaymentManager еще не мигрирован
|
||
await _paymentManager.checkAndProcessPayment(payment);
|
||
} catch (e, s) {
|
||
print(e);
|
||
print(s);
|
||
}
|
||
}
|
||
}
|
||
|
||
@override
|
||
String get name => 'check_payment';
|
||
|
||
@override
|
||
int get intervalSeconds => 300;
|
||
}
|