initial commit (migrated)
This commit is contained in:
commit
b594facb51
143 changed files with 11057 additions and 0 deletions
|
|
@ -0,0 +1,48 @@
|
|||
import 'package:in_app_purchase/in_app_purchase.dart';
|
||||
|
||||
const _consumableProductIds = <String>{
|
||||
'donate_consumable_low',
|
||||
'donate_consumable_mid',
|
||||
'donate_consumable_high',
|
||||
};
|
||||
|
||||
abstract class InAppPurchaseRemoteDataSource {
|
||||
Stream<List<PurchaseDetails>> get purchaseStream;
|
||||
|
||||
Future<List<ProductDetails>> getConsumableProducts();
|
||||
|
||||
Future<bool> purchaseConsumableProduct(ProductDetails product);
|
||||
|
||||
Future<void> completePurchase(PurchaseDetails purchaseDetails);
|
||||
}
|
||||
|
||||
class InAppPurchaseRemoteDataSourceImpl
|
||||
implements InAppPurchaseRemoteDataSource {
|
||||
InAppPurchaseRemoteDataSourceImpl({required this.iap});
|
||||
|
||||
final InAppPurchase iap;
|
||||
|
||||
@override
|
||||
Stream<List<PurchaseDetails>> get purchaseStream => iap.purchaseStream;
|
||||
|
||||
@override
|
||||
Future<List<ProductDetails>> getConsumableProducts() async {
|
||||
final response = await iap.queryProductDetails(_consumableProductIds);
|
||||
final productDetails = response.productDetails;
|
||||
productDetails.sort((a, b) => a.price.compareTo(b.price));
|
||||
return productDetails;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> purchaseConsumableProduct(ProductDetails product) async {
|
||||
final response = await iap.buyConsumable(
|
||||
purchaseParam: PurchaseParam(productDetails: product),
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> completePurchase(PurchaseDetails purchaseDetails) {
|
||||
return iap.completePurchase(purchaseDetails);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:in_app_purchase/in_app_purchase.dart';
|
||||
import 'package:kuwot/core/error/failure.dart';
|
||||
import 'package:kuwot/features/in_app_purchase/data/data_sources/remote/in_app_purchase_remote_data_source.dart';
|
||||
import 'package:kuwot/features/in_app_purchase/domain/repositories/in_app_purchase_repository.dart';
|
||||
|
||||
class InAppPurchaseRepositoryImpl implements InAppPurchaseRepository {
|
||||
InAppPurchaseRepositoryImpl({required this.inAppPurchaseDataSource});
|
||||
|
||||
final InAppPurchaseRemoteDataSource inAppPurchaseDataSource;
|
||||
|
||||
@override
|
||||
Stream<List<PurchaseDetails>> get purchaseStream =>
|
||||
inAppPurchaseDataSource.purchaseStream;
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<ProductDetails>>> getConsumableProducts() async {
|
||||
try {
|
||||
final response = await inAppPurchaseDataSource.getConsumableProducts();
|
||||
return right(response);
|
||||
} catch (e) {
|
||||
return left(UnknownFailure(message: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, bool>> purchaseConsumableProduct(
|
||||
ProductDetails product,
|
||||
) async {
|
||||
try {
|
||||
final response = await inAppPurchaseDataSource.purchaseConsumableProduct(
|
||||
product,
|
||||
);
|
||||
return right(response);
|
||||
} catch (e) {
|
||||
return left(UnknownFailure(message: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, void>> completePurchase(
|
||||
PurchaseDetails purchaseDetails,
|
||||
) async {
|
||||
try {
|
||||
await inAppPurchaseDataSource.completePurchase(purchaseDetails);
|
||||
return right(null);
|
||||
} on Exception catch (e) {
|
||||
return left(UnknownFailure(message: e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue