45 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Dart
		
	
	
		
		
			
		
	
	
			45 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Dart
		
	
	
| 
								 | 
							
								import 'package:guru_app/financial/asset/assets_model.dart';
							 | 
						||
| 
								 | 
							
								import 'package:guru_app/financial/data/db/order_database.dart';
							 | 
						||
| 
								 | 
							
								import 'package:guru_app/financial/manifest/manifest.dart';
							 | 
						||
| 
								 | 
							
								import 'package:guru_app/financial/product/product_model.dart';
							 | 
						||
| 
								 | 
							
								import 'package:guru_utils/datetime/datetime_utils.dart';
							 | 
						||
| 
								 | 
							
								import 'package:guru_utils/id/id_utils.dart';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/// Created by Haoyi on 2023/2/13
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class RewardProduct implements Product {
							 | 
						||
| 
								 | 
							
								  @override
							 | 
						||
| 
								 | 
							
								  final ProductId productId;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  @override
							 | 
						||
| 
								 | 
							
								  final Manifest manifest;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  String get sku => productId.sku;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  RewardProduct(this.productId, this.manifest);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  bool isConsumable() {
							 | 
						||
| 
								 | 
							
								    return productId.isConsumable;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  @override
							 | 
						||
| 
								 | 
							
								  String toString() {
							 | 
						||
| 
								 | 
							
								    return 'IapProduct{productId: $productId}';
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  @override
							 | 
						||
| 
								 | 
							
								  OrderEntity createOrder() {
							 | 
						||
| 
								 | 
							
								    return OrderEntity(
							 | 
						||
| 
								 | 
							
								        orderId: IdUtils.uuidV4(),
							 | 
						||
| 
								 | 
							
								        sku: productId.sku,
							 | 
						||
| 
								 | 
							
								        state: TransactionState.success,
							 | 
						||
| 
								 | 
							
								        attr: productId.attr,
							 | 
						||
| 
								 | 
							
								        method: TransactionMethod.reward.index,
							 | 
						||
| 
								 | 
							
								        currency: TransactionCurrency.reward,
							 | 
						||
| 
								 | 
							
								        cost: 0,
							 | 
						||
| 
								 | 
							
								        category: manifest.category,
							 | 
						||
| 
								 | 
							
								        timestamp: DateTimeUtils.currentTimeInMillis(),
							 | 
						||
| 
								 | 
							
								        manifest: manifest);
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 |