Exemple #1
0
    public static void TryBuyAdPackForTokens(int numberOfPacks, int advertId, Member user, AdPackType adPackType,
                                             int?userGroupIdNullable = null, int?groupIdNullable = null, bool forcePurchaseWithoutDeducingFunds = false, Member adPackOwner = null)
    {
        var TokenCryptocurrency = CryptocurrencyFactory.Get(CryptocurrencyType.ERC20Token);

        //Check all basic values
        Money   TotalPriceForAdPacks = AdPackManager.GetAdPacksPrice(adPackType, numberOfPacks);
        Money   TokenValue           = TokenCryptocurrency.GetValue();
        Decimal TokenNumberNeeded    = TotalPriceForAdPacks.ToDecimal() / TokenValue.ToDecimal();

        if (TokenValue <= Money.Zero)
        {
            throw new MsgException("Amount of tokens can not be <= 0");
        }

        if (TokenNumberNeeded > user.GetCryptocurrencyBalance(CryptocurrencyType.ERC20Token).ToDecimal())
        {
            throw new MsgException(String.Format(U6012.NOFUNDSINWALLET, TokenCryptocurrency.Code));
        }

        try
        {
            //Funds ok, lets proceed with tokens transfer
            user.SubtractFromCryptocurrencyBalance(CryptocurrencyType.ERC20Token, TokenNumberNeeded, "Purchase transfer", BalanceLogType.PurchaseTransfer);
            user.AddToPurchaseBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);

            AdPackManager.BuyPacks(numberOfPacks, advertId, user, adPackType, PurchaseBalances.Purchase, adPackOwner: adPackOwner);
        }
        catch (MsgException ex)
        {
            user.AddToCryptocurrencyBalance(CryptocurrencyType.ERC20Token, TokenNumberNeeded, "Reversed Purchase transfer", BalanceLogType.ReversedPurchaseTransfer);
            user.SubtractFromPurchaseBalance(TotalPriceForAdPacks, "Reversed Purchase transfer", BalanceLogType.ReversedPurchaseTransfer);
            throw new MsgException("<br />" + ex.Message);
        }
    }
Exemple #2
0
        private void DepositCryptocurrency(Member user, decimal amountInCryptocurrency)
        {
            Money   moneyAmount = ConvertToMoney(amountInCryptocurrency);
            LogType LogType     = ErrorLoggerHelper.GetTypeFromProcessor(DepositApiProcessor);

            user.Reload();

            if (DepositTarget == DepositTargetBalance.PurchaseBalance)
            {
                user.AddToPurchaseBalance(moneyAmount, Code + " deposit", BalanceLogType.Other);
                user.SaveBalances();
            }
            if (DepositTarget == DepositTargetBalance.CashBalance)
            {
                user.AddToCashBalance(moneyAmount, Code + " deposit", BalanceLogType.Other);
                user.SaveBalances();

                //Referral commission for sponsors when user does Cash Balance deposit
                CashBalanceCrediter Crediter = (CashBalanceCrediter)CrediterFactory.Acquire(user, CreditType.CashBalanceDeposit);
                Crediter.TryCreditReferer(moneyAmount);
            }
            if (DepositTarget == DepositTargetBalance.Wallet)
            {
                user.AddToCryptocurrencyBalance(Type, amountInCryptocurrency, Code + " Wallet deposit", BalanceLogType.WalletDeposit);
            }

            PaymentProportionsManager.MemberPaidIn(moneyAmount, CryptocurrencyTypeHelper.ConvertToPaymentProcessor(Type), user);
            History.AddTransfer(user.Name, moneyAmount, Code + " deposit", DepositTarget.ToString());

            ContestManager.IMadeAnAction(ContestType.Transfer, user.Name, moneyAmount, 0);
        }
    public void Reject()
    {
        this.Status = WithdrawRequestStatus.Rejected;
        this.Save();

        var user = new Member(UserId);

        if (WithdrawalSourceBalance == WithdrawalSourceBalance.MainBalance)
        {
            user.MoneyCashout -= AmountWithFee;
            user.AddToMainBalance(AmountWithFee, CryptocurrencyObject.Code + " withdrawal rejected");
        }
        else
        {
            user.MoneyCashout -= CryptocurrencyObject.ConvertToMoney(AmountWithFee.ToDecimal());
            user.AddToCryptocurrencyBalance(Cryptocurrency, AmountWithFee.ToDecimal(), CryptocurrencyObject.Code = " withdrawal rejected");
        }

        user.Save();
    }
Exemple #4
0
    protected void CurrentUserTransactionsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        var commands = new[] { "ConfirmReceived" };

        if (commands.Contains(e.CommandName))
        {
            var index             = e.GetSelectedRowIndex() % CurrentUserTransactionsGridView.PageSize;
            var row               = CurrentUserTransactionsGridView.Rows[index];
            var TransactionId     = (row.Cells[0].Text.Trim());
            var Transaction       = new CryptocurrencyTradeTransaction(Convert.ToInt32(TransactionId));
            var CurrentTradeOffer = new CryptocurrencyTradeOffer(Transaction.OfferId);

            switch (e.CommandName)
            {
            case "ConfirmReceived":
                int ClientWithCash = -1;
                if (Transaction.ClientId != Member.CurrentId)
                {
                    ClientWithCash = Transaction.ClientId;
                }
                else
                {
                    ClientWithCash = CurrentTradeOffer.CreatorId;
                }

                var BuyerWithCash = new Member(ClientWithCash);
                BuyerWithCash.AddToCryptocurrencyBalance(CryptocurrencyType.BTC, Transaction.CCAmount.ToDecimal(), "Cryptocurrency trade", BalanceLogType.CryptocurrencyTrade);

                Transaction.PaymentStatus = CryptocurrencyTransactionStatus.Finished;
                Transaction.Save();

                CryptocurrencyFinishedTradeOffer.CreateNewTemplate(Transaction.OfferId, ClientWithCash, Member.CurrentId, Transaction.CCAmount);
                break;
            }

            CurrentUserTransactionsGridView.DataBind();
        }
    }
Exemple #5
0
    public static void TryBuyAdPackFromAnotherBalance(int numberOfPacks, int advertId, Member user, AdPackType adPackType, BalanceType targetType,
                                                      int?userGroupIdNullable = null, int?groupIdNullable = null, bool forcePurchaseWithoutDeducingFunds = false, Member adPackOwner = null)
    {
        Money TotalPriceForAdPacks = AdPackManager.GetAdPacksPrice(adPackType, numberOfPacks);

        if (TotalPriceForAdPacks <= Money.Zero)
        {
            throw new MsgException("Value can not be <= 0");
        }


        if (targetType == BalanceType.CommissionBalance)
        {
            if (TotalPriceForAdPacks > user.CommissionBalance)
            {
                throw new MsgException(L1.NOTENOUGHFUNDS);
            }

            try
            {
                //Funds ok, lets proceed with tokens transfer
                user.SubtractFromCommissionBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                user.AddToPurchaseBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                AdPackManager.BuyPacks(numberOfPacks, advertId, user, adPackType, PurchaseBalances.Purchase, adPackOwner: adPackOwner);
            }
            catch (MsgException ex)
            {
                user.SubtractFromPurchaseBalance(TotalPriceForAdPacks, "Reversed Purchase transfer", BalanceLogType.ReversedPurchaseTransfer);
                user.AddToPurchaseBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                throw new MsgException("<br />" + ex.Message);
            }
        }
        else if (targetType == BalanceType.MainBalance)
        {
            if (TotalPriceForAdPacks > user.MainBalance)
            {
                throw new MsgException(L1.NOTENOUGHFUNDS);
            }

            try
            {
                //Funds ok, lets proceed with tokens transfer
                user.SubtractFromMainBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                user.AddToPurchaseBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                AdPackManager.BuyPacks(numberOfPacks, advertId, user, adPackType, PurchaseBalances.Purchase, adPackOwner: adPackOwner);
            }
            catch (MsgException ex)
            {
                user.SubtractFromPurchaseBalance(TotalPriceForAdPacks, "Reversed Purchase transfer", BalanceLogType.ReversedPurchaseTransfer);
                user.AddToMainBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                throw new MsgException("<br />" + ex.Message);
            }
        }
        else if (targetType == BalanceType.BTC)
        {
            Money   BTCValue        = CryptocurrencyFactory.Get(CryptocurrencyType.BTC).GetValue();
            Decimal BTCAmountNeeded = TotalPriceForAdPacks.ToDecimal() / BTCValue.ToDecimal();

            if (BTCAmountNeeded > user.GetCryptocurrencyBalance(CryptocurrencyType.BTC).ToDecimal())
            {
                throw new MsgException(String.Format(U6012.NOFUNDSINWALLET, "BTC"));
            }

            try
            {
                //Funds ok, lets proceed with tokens transfer
                user.SubtractFromCryptocurrencyBalance(CryptocurrencyType.BTC, BTCAmountNeeded, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                user.AddToPurchaseBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                AdPackManager.BuyPacks(numberOfPacks, advertId, user, adPackType, PurchaseBalances.Purchase, adPackOwner: adPackOwner);
            }
            catch (MsgException ex)
            {
                user.SubtractFromPurchaseBalance(TotalPriceForAdPacks, "Reversed Purchase transfer", BalanceLogType.ReversedPurchaseTransfer);
                user.AddToCryptocurrencyBalance(CryptocurrencyType.BTC, BTCAmountNeeded, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                throw new MsgException("<br />" + ex.Message);
            }
        }
        else
        {
            throw new MsgException("Not implemented transaction");
        }
    }
Exemple #6
0
        public static void TryPurchaseTokens(Member user, ICOStage stage, int numberOfTokens, BalanceType targetBalance)
        {
            var TokenCryprocurrency = CryptocurrencyFactory.Get(CryptocurrencyType.ERC20Token);

            if (numberOfTokens <= 0)
            {
                throw new MsgException(U5006.AMOUNTEQUALZERO);
            }

            if (numberOfTokens > stage.GetAvailableTokens())
            {
                throw new MsgException(U6012.NOTOKENSLEFT);
            }

            int userPurchasesInLast15min = ICOPurchase.GetUserPurchasesInLast15Min(stage.Id, user.Id);

            if (userPurchasesInLast15min + numberOfTokens > AppSettings.ICO.ICOPurchaseLimitPerUserPer15mins)
            {
                throw new MsgException(String.Format(U6012.COINSEXCEED15MIN, "<b>" + userPurchasesInLast15min + "</b>", TokenCryprocurrency.Code));
            }

            //All OK, let's charge the balance
            //If freeze system is enabled, purchased tokens are freezed
            CryptocurrencyType TypeOfPurchasedCoins = AppSettings.Ethereum.ERC20TokensFreezeSystemEnabled ? CryptocurrencyType.ERCFreezed : CryptocurrencyType.ERC20Token;
            Money totalAmount = numberOfTokens * stage.TokenPrice;

            if (targetBalance == BalanceType.PurchaseBalance)
            {
                if (totalAmount > user.PurchaseBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                user.SubtractFromPurchaseBalance(totalAmount, TokenCryprocurrency.Code + " purchase", BalanceLogType.CoinPurchase);
                user.SaveBalances();
            }
            else if (targetBalance == BalanceType.BTC)
            {
                decimal amountInBTC = (totalAmount.ToDecimal() /
                                       CryptocurrencyFactory.Get(CryptocurrencyType.BTC).GetValue().ToDecimal()).TruncateDecimals(8);

                if (amountInBTC > user.GetCryptocurrencyBalance(CryptocurrencyType.BTC).ToDecimal())
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                user.SubtractFromCryptocurrencyBalance(CryptocurrencyType.BTC, amountInBTC,
                                                       TokenCryprocurrency.Code + " purchase", BalanceLogType.CoinPurchase);
            }
            else
            {
                throw new ArgumentException("Invalid argument: " + targetBalance.ToString(), "targetBalance");
            }

            //Add history entry
            History.AddPurchase(user.Name, totalAmount, TokenCryprocurrency.Code);

            //Credit coins to Referrer
            decimal tokensCreditedToReferrer = 0;

            if (user.HasReferer)
            {
                var Referer = new Member(user.ReferrerId);
                tokensCreditedToReferrer = (Referer.Membership.ICOPurchasePercent / 100) * numberOfTokens;

                if (tokensCreditedToReferrer > 0)
                {
                    Referer.AddToCryptocurrencyBalance(TypeOfPurchasedCoins, tokensCreditedToReferrer, TokenCryprocurrency.Code + " purchase /ref/"
                                                       + user.Name, BalanceLogType.CoinPurchase);

                    if (TypeOfPurchasedCoins == CryptocurrencyType.ERCFreezed)
                    {
                        UserFreezedToken.Add(Referer.Id, tokensCreditedToReferrer);
                    }

                    user.IncreaseERC20TokensEarningsForDRef(tokensCreditedToReferrer);
                    user.SaveStatistics();
                }
            }

            //Add purchase entry
            ICOPurchase.Add(user.Id, numberOfTokens, tokensCreditedToReferrer + (decimal)numberOfTokens, stage.Id);

            //Add coins to balance
            user.AddToCryptocurrencyBalance(TypeOfPurchasedCoins, numberOfTokens, TokenCryprocurrency.Code + " purchase", BalanceLogType.CoinPurchase);
            if (TypeOfPurchasedCoins == CryptocurrencyType.ERCFreezed)
            {
                UserFreezedToken.Add(user.Id, Decimal.Parse(numberOfTokens.ToString()));
            }
        }
Exemple #7
0
    public static string TryInvokeTransfer(string transferFrom, string transferTo, Money amount, Member user, ref bool htmlResponse)
    {
        var TokenCryptocurrency = CryptocurrencyFactory.Get(CryptocurrencyType.ERC20Token);

        //Anti-Injection Fix
        if (amount <= new Money(0))
        {
            throw new MsgException(L1.ERROR);
        }

        if (!TransferHelper.IsAllowed(transferFrom, transferTo))
        {
            throw new MsgException("This transfer is not allowed.");
        }

        if (transferFrom == "MPesa" && String.IsNullOrWhiteSpace(user.GetPaymentAddress(PaymentProcessor.MPesa)))
        {
            throw new MsgException(U6010.ACCOUNTIDREQUIRED);
        }

        AppSettings.DemoCheck();
        htmlResponse = false;

        if (transferFrom == "Main balance")
        {
            // Option 1: From Main Balance (always available)

            if (amount > user.MainBalance)
            {
                throw new MsgException(L1.NOTENOUGHFUNDS);
            }

            user.SubtractFromMainBalance(amount, "Transfer from Main Balance");
            user.MoneyTransferredFromMainBalance += amount;

            if (transferTo == "Traffic balance")
            {
                user.AddToTrafficBalance(amount, "Transfer from Main Balance");
            }

            else if (transferTo == "Purchase balance" && AppSettings.Payments.TransferMainInAdBalanceEnabled)
            {
                user.AddToPurchaseBalance(amount, "Transfer from Main Balance");
            }

            else if (transferTo == "Cash balance")
            {
                user.AddToCashBalance(amount, "Transfer from Main Balance");
            }

            else if (transferTo == TokenCryptocurrency.Code + " Wallet" && AppSettings.Payments.TransferFromMainBalanceToTokenWalletEnabled)
            {
                //Let's calculate transfer amount using current token rate
                decimal tokenValue = CryptocurrencyFactory.Get(CryptocurrencyType.ERC20Token).ConvertFromMoney(amount);
                user.AddToCryptocurrencyBalance(CryptocurrencyType.ERC20Token, tokenValue, "Transfer from Main Balance");
            }

            else
            {
                throw new MsgException("You must select your target account / this transfer is not available.");
            }

            user.Save();
            AddHistoryAndTryAchievement(amount, user, "Main balance", transferTo);
            return(U3501.TRANSFEROK);
        }
        else if (transferFrom == "Cash balance")
        {
            if (AppSettings.Payments.CashBalanceEnabled && AppSettings.Payments.CashToAdBalanceEnabled)
            {
                if (amount > user.CashBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                user.SubtractFromCashBalance(amount, "Transfer from Cash Balance");

                if (transferTo == "Purchase balance")
                {
                    user.AddToPurchaseBalance(amount, "Transfer from Cash Balance");
                }

                user.SaveBalances();
                return(U3501.TRANSFEROK);
            }
            else
            {
                throw new MsgException("You cannot transfer from Cash Balance");
            }
        }
        else if (transferFrom == "Commission Balance")
        {
            if (((AppSettings.Payments.CommissionToMainBalanceEnabled) ||
                 (TitanFeatures.UserCommissionToMainBalanceEnabled && user.CommissionToMainBalanceEnabled) ||
                 (AppSettings.Payments.CommissionToAdBalanceEnabled) || TitanFeatures.isAri) && user.CheckAccessCustomizeTradeOwnSystem)
            {
                if (amount > user.CommissionBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                user.SubtractFromCommissionBalance(amount, "Transfer from Commission Balance");

                if (transferTo == "Main balance")
                {
                    Money amountWithFee = TransferManager.GetAmountWithFee(amount, TransferFeeType.SameUserCommissionToMain, user);
                    user.AddToMainBalance(amountWithFee, "Transfer from Commission Balance");

                    //Pools
                    Money moneyLeft = amount - amountWithFee;
                    PoolDistributionManager.AddProfit(ProfitSource.TransferFees, moneyLeft);
                }
                else if (transferTo == "Purchase balance")
                {
                    user.AddToPurchaseBalance(amount, "Transfer from Commission Balance");
                }
                else if (transferTo == "Cash balance")
                {
                    user.AddToCashBalance(amount, "Transfer from Purchase Balance");
                }

                user.SaveBalances();
                return(U3501.TRANSFEROK);
            }
            else
            {
                throw new MsgException("You cannot transfer from Commission Balance");
            }
        }
        else if (transferFrom == "Purchase balance")
        {
            if (!TitanFeatures.IsRevolca)
            {
                throw new MsgException("You cannot transfer from Purchase Balance");
            }

            if (amount > user.MainBalance)
            {
                throw new MsgException(L1.NOTENOUGHFUNDS);
            }

            user.SubtractFromPurchaseBalance(amount, "Transfer from Purchase Balance");
            user.AddToMainBalance(amount, "Transfer from Purchase Balance");
            user.SaveBalances();
            return(U3501.TRANSFEROK);
        }
        else
        {
            htmlResponse = true;
            return(TryInvokeProcessorTransfer(transferFrom, transferTo, amount, user));
        }
    }