import 'package:flutter_rustore_billing/flutter_rustore_billing.dart'; import 'package:mnemo_cards/flags.dart'; import 'package:mnemo_cards_common/mnemo_cards_common.dart'; import '../../../di/locator.dart'; class RustorePurchaseService { Future init() async { return RustoreBillingClient.initialize( "2063563896", "mnemocards://iamback", true, ).then((value) { print("initialize success: $value"); return true; }, onError: (err) { print("initialize err: $err"); return false; }); } Future buyPack(CardPackBuyDto dto) async { if (dto.rustoreId == null) { return false; } if (!await init()) { return false; } final product = (await RustoreBillingClient.products([dto.rustoreId])) .products .firstOrNull; if (product == null) { return false; } final result = await RustoreBillingClient.purchase(dto.rustoreId!, null); if (result.successPurchase == null && result.successInvoice == null) { return false; } if (result.successPurchase != null) { final purchase = result.successPurchase!; final success = await locator.repository.checkPayment( purchase.productId, purchase.subscriptionToken ?? '', androidPaymentSystem, ); return success; } return true; } }