Exemplo n.º 1
0
        public HttpResponseMessage BuyShare(CustomerPlanModel customerPlanModel)
        {
            string message = "";

            try
            {
                var customerguid = Request.Headers.GetValues("CustomerGUID").FirstOrDefault();
                if (customerguid != null)
                {
                    var cust = _customerService.GetCustomerByGuid(Guid.Parse(customerguid));
                    if (customerPlanModel.CustomerId != cust.Id)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized, new { code = 0, Message = "something went wrong" }));
                    }
                }
                var Customer = _customerService.GetCustomerById(customerPlanModel.CustomerId);
                if (ModelState.IsValid)
                {
                    PrepareCustomerPlanModel(customerPlanModel);
                    customerPlanModel.AvailableBalance = _customerService.GetAvailableBalance(Customer.Id);                    // _customerService.GetRepurchaseBalance(_workContext.CurrentCustomer.Id);

                    if (customerPlanModel.PlanId > 0)
                    {
                        var plan = _planService.GetPlanById(customerPlanModel.PlanId);
                        var repurchasebalance = _customerService.GetAvailableBalance(Customer.Id);
                        var amountreq         = Convert.ToInt64(plan.MinimumInvestment) * ((customerPlanModel.NoOfPosition == 0) ? 1 : customerPlanModel.NoOfPosition);

                        if (repurchasebalance < amountreq)
                        {
                            message = "You do not have enough balance, Please add funds";
                            return(Request.CreateResponse(HttpStatusCode.OK, new { code = 0, Message = message }));
                        }

                        TransactionModel transactionModel = new TransactionModel();
                        transactionModel.Amount            = amountreq;
                        transactionModel.CustomerId        = Customer.Id;
                        transactionModel.FinalAmount       = transactionModel.Amount;
                        transactionModel.NoOfPosition      = customerPlanModel.NoOfPosition;
                        transactionModel.TransactionDate   = DateTime.Now;
                        transactionModel.RefId             = plan.Id;
                        transactionModel.ProcessorId       = customerPlanModel.ProcessorId;
                        transactionModel.TranscationTypeId = (int)TransactionType.Purchase;
                        var transcation = transactionModel.ToEntity();

                        transcation.NoOfPosition      = customerPlanModel.NoOfPosition;
                        transcation.TranscationTypeId = (int)TransactionType.Purchase;
                        transcation.StatusId          = (int)Status.Completed;
                        _transactionService.InsertTransaction(transcation);

                        var customerplan = new CustomerPlan();
                        customerplan.CustomerId     = transcation.CustomerId;
                        customerplan.PurchaseDate   = DateTime.Now;
                        customerplan.CreatedOnUtc   = DateTime.Now;
                        customerplan.UpdatedOnUtc   = DateTime.Now;
                        customerplan.PlanId         = plan.Id;
                        customerplan.AmountInvested = plan.MinimumInvestment;
                        customerplan.ROIToPay       = 0;
                        customerplan.NoOfPayout     = 0;
                        customerplan.ExpiredDate    = DateTime.Today;
                        customerplan.IsActive       = true;
                        if (plan.StartROIAfterHours > 0)
                        {
                            customerplan.LastPaidDate = DateTime.Today.AddHours(plan.StartROIAfterHours);
                        }
                        else
                        {
                            customerplan.LastPaidDate = DateTime.Today;
                        }
                        _customerPlanService.InsertCustomerPlan(customerplan);

                        _customerService.SpPayNetworkIncome(customerplan.CustomerId, customerplan.PlanId);

                        message = "Your purchase was successfull";
                        ReleaseLevelCommission(plan.Id, Customer, transactionModel.Amount);
                        return(Request.CreateResponse(HttpStatusCode.OK, new { code = 0, Message = "success" }));
                    }
                    else
                    {
                        message = "Please select Package";
                    }
                }
            }
            catch (Exception ex)
            {
                message = T("Invesment.Deposit.FundingError").Text;
            }
            return(Request.CreateResponse(HttpStatusCode.OK, new { code = 0, Message = message }));
        }
Exemplo n.º 2
0
        public ActionResult Deposit(CustomerPlanModel customerPlanModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ViewBag.CurrencyCode = _workContext.WorkingCurrency.CurrencyCode;
                    PrepareCustomerPlanModel(customerPlanModel);
                    customerPlanModel.AvailableBalance = _customerService.GetAvailableBalance(_workContext.CurrentCustomer.Id);                    // _customerService.GetRepurchaseBalance(_workContext.CurrentCustomer.Id);

                    if (!CheckIfPositionExists(customerPlanModel.PlanId))
                    {
                        NotifyError("You require same level board position to buy this Ad Pack");
                        return(View(customerPlanModel));
                    }
                    if (customerPlanModel.PlanId != 30)
                    {
                        var noOfPack = _workContext.CurrentCustomer.Transaction.Where(x => x.RefId == customerPlanModel.PlanId - 1 && x.TranscationTypeId == 2 && x.StatusId == 2).Sum(x => x.NoOfPosition);
                        if (noOfPack < 10)
                        {
                            NotifyError("You require minimum 10 previous Ad Pack");
                            return(View(customerPlanModel));
                        }
                    }

                    if (customerPlanModel.PlanId > 0)
                    {
                        var plan = _planService.GetPlanById(customerPlanModel.PlanId);
                        var repurchasebalance = _customerService.GetAvailableBalance(_workContext.CurrentCustomer.Id);
                        var amountreq         = Convert.ToInt64(plan.MinimumInvestment) * ((customerPlanModel.NoOfPosition == 0) ? 1 : customerPlanModel.NoOfPosition);
                        if (customerPlanModel.ProcessorId == 5)
                        {
                            if (repurchasebalance < amountreq)
                            {
                                NotifyError("You do not have enough balance");
                                ViewBag.CurrencyCode = _workContext.WorkingCurrency.CurrencyCode;
                                PrepareCustomerPlanModel(customerPlanModel);
                                customerPlanModel.AvailableBalance = _customerService.GetAvailableBalance(_workContext.CurrentCustomer.Id);                                // _customerService.GetRepurchaseBalance(_workContext.CurrentCustomer.Id);
                                return(RedirectToAction("Deposit"));
                            }
                        }
                        TransactionModel transactionModel = new TransactionModel();
                        transactionModel.Amount            = amountreq;
                        transactionModel.CustomerId        = _workContext.CurrentCustomer.Id;
                        transactionModel.FinalAmount       = transactionModel.Amount;
                        transactionModel.NoOfPosition      = customerPlanModel.NoOfPosition;
                        transactionModel.TransactionDate   = DateTime.Now;
                        transactionModel.RefId             = plan.Id;
                        transactionModel.ProcessorId       = customerPlanModel.ProcessorId;
                        transactionModel.TranscationTypeId = (int)TransactionType.Purchase;
                        var transcation = transactionModel.ToEntity();

                        transcation.NoOfPosition = customerPlanModel.NoOfPosition;
                        if (customerPlanModel.ProcessorId == 5)
                        {
                            transcation.TranscationTypeId = (int)TransactionType.Purchase;
                            transcation.StatusId          = (int)Status.Completed;
                        }
                        else
                        {
                            transcation.StatusId          = (int)Status.Pending;
                            transcation.TranscationTypeId = (int)TransactionType.Purchase;
                        }
                        _transactionService.InsertTransaction(transcation);

                        for (int i = 0; i < transcation.NoOfPosition; i++)
                        {
                            var customerplan = new CustomerPlan();
                            customerplan.CustomerId     = transcation.CustomerId;
                            customerplan.PurchaseDate   = DateTime.Now;
                            customerplan.CreatedOnUtc   = DateTime.Now;
                            customerplan.UpdatedOnUtc   = DateTime.Now;
                            customerplan.PlanId         = plan.Id;
                            customerplan.AmountInvested = plan.MinimumInvestment;
                            customerplan.ROIToPay       = plan.MaximumInvestment;
                            customerplan.NoOfPayout     = 0;
                            customerplan.ExpiredDate    = DateTime.Today;
                            customerplan.IsActive       = true;
                            if (plan.StartROIAfterHours > 0)
                            {
                                customerplan.LastPaidDate = DateTime.Today.AddHours(plan.StartROIAfterHours);
                            }
                            else
                            {
                                customerplan.LastPaidDate = DateTime.Today;
                            }
                            _customerPlanService.InsertCustomerPlan(customerplan);
                        }
                        if (customerPlanModel.ProcessorId == 5)
                        {
                            NotifySuccess("Your purchase was successfull");
                            ReleaseLevelCommission(plan.Id, _workContext.CurrentCustomer.Id, transactionModel.Amount);
                        }
                        else
                        {
                            int           value         = customerPlanModel.ProcessorId;
                            PaymentMethod paymentmethod = (PaymentMethod)value;

                            ViewBag.SaveSuccess              = true;
                            customerPlanModel.Id             = plan.Id;
                            customerPlanModel.PlanName       = plan.Name;
                            customerPlanModel.ProcessorName  = paymentmethod.ToString();
                            customerPlanModel.PaymentMethod  = paymentmethod;
                            customerPlanModel.TransactionId  = transcation.Id;
                            customerPlanModel.AmountInvested = (decimal)transactionModel.Amount;
                            return(RedirectToAction("ConfirmPayment", customerPlanModel));
                        }
                    }
                    else
                    {
                        NotifyError("Please select Package");
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.SaveSuccess = false;
                NotifyError(T("Invesment.Deposit.FundingError"));
            }
            ViewBag.CurrencyCode = _workContext.WorkingCurrency.CurrencyCode;
            customerPlanModel.AvailableBalance = _customerService.GetAvailableBalance(_workContext.CurrentCustomer.Id);            // _customerService.GetRepurchaseBalance(_workContext.CurrentCustomer.Id);
            PrepareCustomerPlanModel(customerPlanModel);
            return(View(customerPlanModel));
        }