Exemplo n.º 1
0
    protected void BuyOrUpgradePlan(PurchaseBalances balance)
    {
        try
        {
            var plan        = new InvestmentPlatformPlan(int.Parse(PlansDropDownList.SelectedValue));
            var activePlans = CurrentMode == InvestmentPlatformMode.Levels ? 0 : userActivePlans.Count;

            if (AppSettings.InvestmentPlatform.LevelsEnabled)
            {
                InvestmentLevelsManager.CanUserDepositOnLevel(plan, User);
            }

            if (plan.MaxPrice > Money.Zero)
            {
                if (AppSettings.InvestmentPlatform.InvestmentPlatformPlansPolicy == PlansPolicy.OneUpgradedPlan)
                {
                    throw new MsgException(U6012.CANTUPGRADERANGEPLAN);
                }

                var targetPrice = Money.Parse(RangePriceTextBox.Text);
                if (plan.CheckPlanPrice(targetPrice))
                {
                    InvestmentPlatformManager.BuyOrUpgradePlan(Member.Current, balance, plan, targetPrice);
                }
                else
                {
                    throw new MsgException(U6012.TYPECORRECTPRICE);
                }
            }
            else
            {
                InvestmentPlatformManager.BuyOrUpgradePlan(Member.Current, balance, plan);
            }

            //IF activePlans = 1, MEANS THAT WE UPGRADE PLAN (ON PlansPolicy.OneUpgradedPlan)
            if (AppSettings.InvestmentPlatform.InvestmentPlatformPlansPolicy == PlansPolicy.OneUpgradedPlan && activePlans == 1)
            {
                SuccessTextLiteral.Text = string.Format(U6011.SUCCESSUPGRADEPLAN, plan.Name);
            }
            else
            {
                SuccessTextLiteral.Text = string.Format(U6006.SUCCESBOUGHTPLAN, plan.Name);
            }

            SuccessPanel.Visible = true;

            availablePlans = InvestmentPlatformManager.GetAllAvailablePlansForUser(User.Id);
            InitBuyViewControls();
            InitPlans();
        }
        catch (Exception ex)
        {
            ErrorPanel.Visible    = true;
            ErrorTextLiteral.Text = ex.Message;
            if (!(ex is MsgException))
            {
                ErrorLogger.Log(ex);
            }
        }
    }
Exemplo n.º 2
0
    protected void BuyViaPaymentProcessorButton_Click(object sender, EventArgs e)
    {
        try
        {
            var selectedPlan = new InvestmentPlatformPlan(int.Parse(PlansDropDownList.SelectedValue));
            var targetPrice  = selectedPlan.Price;

            if (AppSettings.InvestmentPlatform.LevelsEnabled)
            {
                InvestmentLevelsManager.CanUserDepositOnLevel(selectedPlan, User);
            }

            if (selectedPlan.MaxPrice > Money.Zero)
            {
                if (AppSettings.InvestmentPlatform.InvestmentPlatformPlansPolicy == PlansPolicy.OneUpgradedPlan)
                {
                    throw new MsgException(U6012.CANTUPGRADERANGEPLAN);
                }

                targetPrice = Money.Parse(RangePriceTextBox.Text);
                if (!selectedPlan.CheckPlanPrice(targetPrice))
                {
                    throw new MsgException(U6012.TYPECORRECTPRICE);
                }
            }

            var bg          = new BuyInvestmentPlanButtonGenerator(User, selectedPlan, targetPrice);
            var buttonsText = string.Empty;

            if (CurrentMode == InvestmentPlatformMode.Levels)
            {
                if (selectedPlan.PaymentProcessor == PaymentProcessor.Null)
                {
                    throw new MsgException(U6013.NOPAYMENTPROCESSORSCONNECTEDWITHLEVEL);
                }

                /* TODO - Add options to pay with cryptocurrency(?)
                 * if(selectedPlan.PaymentProcessor == PaymentProcessor.Coinbase || selectedPlan.PaymentProcessor == PaymentProcessor.CoinPayments)
                 *  buttonsText = GenerateHTMLButtons.GetPaymentButton(bg, CryptocurrencyType);
                 */

                var type = PaymentAccountDetails.GetGatewayType(selectedPlan.PaymentProcessor.ToString());
                buttonsText = GenerateHTMLButtons.GetPaymentButton(bg, type);
            }
            else
            {
                buttonsText = GenerateHTMLButtons.GetPaymentButtons(bg);
            }

            PaymentButtons.Text = buttonsText;

            PaymentProcessorsButtonPlaceHolder.Visible = true;
            BuyControlsPlaceHolder.Visible             = false;
        }
        catch (Exception ex)
        {
            ErrorPanel.Visible    = true;
            ErrorTextLiteral.Text = ex.Message;
            if (ex is MsgException == false)
            {
                ErrorLogger.Log(ex);
            }
        }
    }