Example #1
0
 public void AddPurchase(PurchaseServiceTransaction transaction, PurchaseInfo purchase)
 {
     lock (this)
     {
         var purchaseType = purchase.PurchaseType;
         if (purchaseType == PurchaseTypes.Feature)
         {
             if (_accountFeatures.TryGetValue(purchase.PurchaseGroupId, out var accountPurchase))
             {
                 accountPurchase.AddPurchaseData(transaction, purchase);
             }
             else
             {
                 accountPurchase = new FeatureAccountPurchase(transaction, purchase);
                 _accountFeatures[purchase.PurchaseGroupId] = accountPurchase;
             }
         }
         else if (purchaseType == PurchaseTypes.Subscription)
         {
             if (_accountSubscriptions.TryGetValue(purchase.PurchaseGroupId, out var accountSubscription))
             {
                 accountSubscription.AddPurchaseData(transaction, purchase);
             }
             else
             {
                 accountSubscription = new SubscriptionAccountPurchase(transaction, purchase);
                 _accountSubscriptions[purchase.PurchaseGroupId] = accountSubscription;
             }
         }
     }
 }
Example #2
0
        public virtual bool CanPurchase(PurchaseServiceTransaction transaction, PurchaseInfo purchase)
        {
            CheckPurchaseType(PurchaseType, transaction.PurchaseGroupId);
            CheckPurchaseType(purchase.PurchaseType, purchase.PurchaseGroupId);

            return(false);
        }
Example #3
0
 public override void AddPurchaseData(PurchaseServiceTransaction transaction, PurchaseInfo purchase)
 {
     if (transaction.Timestamp > SubscriptionEnd)
     {
         SubscriptionEnd = transaction.Timestamp + purchase.Duration;
     }
     else
     {
         SubscriptionEnd += purchase.Duration;
     }
 }
            public bool AddPurchase(PurchaseServiceTransaction purchaseTransaction, ServiceAccount serviceAccount, ServiceChain serviceChain)
            {
                var accountId = purchaseTransaction.AccountId;

                if (!Purchases.ContainsKey(accountId))
                {
                    Purchases[accountId] = purchaseTransaction;
                    Transactions.Add(purchaseTransaction);
                    FeatureGenerator.AddTransaction(BlockTransactionGeneratorMode.Preprocess, serviceChain, purchaseTransaction, serviceAccount);

                    return(true);
                }
                return(false);
            }
Example #5
0
        public bool CanPurchaseItem(PurchaseServiceTransaction transaction, ChainInfo chainInfo)
        {
            var purchase = chainInfo.GetPurchase(transaction.PurchaseGroupId, transaction.PurchaseItemId);

            if (purchase == null)
            {
                return(false);
            }

            lock (this)
            {
                if (_accountFeatures.TryGetValue(transaction.PurchaseGroupId, out var featurePurchase))
                {
                    return(featurePurchase.CanPurchase(transaction, purchase));
                }

                if (_accountSubscriptions.TryGetValue(transaction.PurchaseGroupId, out var subscriptionPurchase))
                {
                    return(subscriptionPurchase.CanPurchase(transaction, purchase));
                }
            }

            return(true);
        }
Example #6
0
 public override bool CanPurchase(PurchaseServiceTransaction transaction, PurchaseInfo purchase)
 {
     base.CanPurchase(transaction, purchase);
     return(false);
 }
Example #7
0
 public FeatureAccountPurchase(PurchaseServiceTransaction transaction, PurchaseInfo purchase) : base(PurchaseTypes.Feature, purchase)
 {
     AddPurchaseData(transaction, purchase);
 }
Example #8
0
 public virtual void AddPurchaseData(PurchaseServiceTransaction transaction, PurchaseInfo purchase)
 {
     CheckPurchaseType(PurchaseType, transaction.PurchaseGroupId);
     CheckPurchaseType(purchase.PurchaseType, purchase.PurchaseGroupId);
 }
Example #9
0
        public override bool CanPurchase(PurchaseServiceTransaction transaction, PurchaseInfo purchase)
        {
            base.CanPurchase(transaction, purchase);

            return((SubscriptionEnd + purchase.Duration) > transaction.Timestamp + Time.Days(365)); // can't buy more than one year of a subscription
        }
Example #10
0
 public SubscriptionAccountPurchase(PurchaseServiceTransaction transaction, PurchaseInfo purchase) : base(PurchaseTypes.Subscription, purchase)
 {
     AddPurchaseData(transaction, purchase);
 }
        public static TransactionResultTypes IsPurchaseValid(CoreAccount payer, ServiceAccount receiver, ChainInfo chainInfo, PurchaseServiceTransaction transaction)
        {
            if (chainInfo == null)
            {
                return(TransactionResultTypes.ChainNotFound);
            }

            if (payer == null || !payer.CanPurchase(transaction.Price))
            {
                return(TransactionResultTypes.InsuficientBalance);
            }

            if (receiver == null)
            {
                return(TransactionResultTypes.InvalidServiceAccount);
            }

            if (!chainInfo.IsPurchaseValid(transaction.PurchaseGroupId, transaction.PurchaseItemId, transaction.Price))
            {
                return(TransactionResultTypes.PurchaseNotFound);
            }

            if (!receiver.CanPurchaseItem(transaction, chainInfo))
            {
                return(TransactionResultTypes.CannotPurchase);
            }

            return(TransactionResultTypes.Ok);
        }