import 'package:mnemo_cards/features/analytics/analytics.dart'; import 'package:mnemo_cards/features/purchase/yookassa_purchase_handler.dart'; import 'package:mnemo_cards_common/mnemo_cards_common.dart'; import 'google_purchase_handler.dart'; class PurchaseManager { final GooglePurchaseHandler _googlePurchaseHandler; final YookassaPurchaseHandler _yookassaPurchaseHandler; PurchaseManager( this._googlePurchaseHandler, this._yookassaPurchaseHandler, ); Future initPurchaseFromDto({ required CardPackBuyDto dto, required PaymentSystem paymentSystem, String? source = 'dto', }) async { String? paymentId; switch (paymentSystem) { case PaymentSystem.google: paymentId = dto.googlePlayId; break; case PaymentSystem.apple: paymentId = dto.appStoreId; break; case PaymentSystem.rustore: paymentId = dto.rustoreId; break; case PaymentSystem.yookassa: paymentId = dto.id; break; case PaymentSystem.unknown: break; } if (paymentId == null) { Analytics.buyError( dto, paymentSystem, message: 'Cant find payment id', ); return; } return initPurchase( id: dto.id, productType: MnemoCardsProductType.pack, paymentId: paymentId, paymentSystem: paymentSystem, ); } Future initPurchase({ required String id, required MnemoCardsProductType productType, required String paymentId, required PaymentSystem paymentSystem, String? source, }) async { switch (paymentSystem) { case PaymentSystem.google: return _googlePurchaseHandler.initPurchase( id: id, productType: productType, paymentId: paymentId, source: source, ); case PaymentSystem.apple: return; case PaymentSystem.rustore: return; case PaymentSystem.yookassa: return _yookassaPurchaseHandler.initPurchase( id: id, productType: productType, paymentId: paymentId, ); case PaymentSystem.unknown: return; } } Future checkPurchase({ required MnemoCardsProduct product, required String token, required PaymentSystem paymentSystem, }) async { switch (paymentSystem) { case PaymentSystem.google: return _googlePurchaseHandler.checkPurchase( product: product, paymentToken: token, ); case PaymentSystem.apple: return false; case PaymentSystem.rustore: return false; case PaymentSystem.yookassa: return _yookassaPurchaseHandler.checkPurchase( product: product, paymentToken: token, ); case PaymentSystem.unknown: return false; } } }