Esempio n. 1
0
        public async Task <ActionResult> PayNow(List <CMS_DepositTransactionsModel> model)
        {
            var     Customer = Session["UserC"] as UserSession;
            var     Payment  = facP.GetDetail(model.FirstOrDefault().PaymentMethodId);
            var     Config   = facC.GetList().Where(x => x.ValueType == (int)Commons.ConfigType.USD).FirstOrDefault();
            decimal?Coin     = 0;

            if (!string.IsNullOrEmpty(Payment.URLApi))
            {
                var Priceobj = new PriceObjects();
                Priceobj = await GetLastPrice(Payment.URLApi);

                if (Priceobj.last.HasValue)
                {
                    Coin = model[0].Price / Priceobj.last.Value;
                }
                else
                {
                    Coin = model[0].Price / Priceobj.lastPrice.Value;
                }
            }
            model.ForEach(x =>
            {
                x.PaymentMethodName = Payment.PaymentName;
                x.WalletMoney       = Payment.WalletMoney;
                x.ExchangeRate      = Config != null ? Config.Value : 0;
                x.PayCoin           = Coin == 0 ? x.PayCoin : Coin.Value;
                x.CustomerId        = Customer.UserId;
                x.CustomerName      = Customer.UserName;
                x.DepositNo         = CommonHelper.RandomDepositNo();
            });
            var msg    = "";
            var result = facT.CreateDepositTransaction(model, ref msg, null);
            var obj    = new
            {
                msg    = msg,
                status = result
            };

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
        // GET: PerfectMoney
        public ActionResult Index(decimal?price)
        {
            PerfectMoneyModel model = new PerfectMoneyModel();

            if (TempData["ErrorMessage"] != null)
            {
                ViewData["ErrorMessage"] = TempData["ErrorMessage"].ToString();
            }
            if (TempData["SuccessMessage"] != null)
            {
                ViewData["SuccessMessage"] = TempData["SuccessMessage"].ToString();
            }
            if (TempData["DataReturnError"] != null)
            {
                model = (PerfectMoneyModel)TempData["DataReturnError"];
                return(View(model));
            }
            try
            {
                List <CMS_DepositTransactionsModel> models = new List <CMS_DepositTransactionsModel>();
                var Config   = fac_C.GetList().Where(x => x.ValueType == (int)Commons.ConfigType.USD).FirstOrDefault();
                var customer = Session["UserC"] as UserSession;
                CMS_DepositTransactionsModel _data = new CMS_DepositTransactionsModel();
                _data.PaymentMethodName = "Perfect money";
                _data.WalletMoney       = Commons.APIType.APIPerfectMonney.ToString();
                _data.ExchangeRate      = Config != null ? Config.Value : 0;
                _data.PayCoin           = price == 0 ? price.Value : price.Value;
                _data.CustomerId        = customer.UserId;
                _data.CustomerName      = customer.UserName;
                _data.DepositNo         = CommonHelper.RandomDepositNo();
                models.Add(_data);
                //Set account information of admin to perfect payment
                var payPerfect = facP.GetList().Where(o => o.ReferenceExchange.Equals((int)Commons.ExchangeType.None)).FirstOrDefault();
                var adminInfo  = fac_Co.GetList().Select(o => o.Name).FirstOrDefault();;
                model.PAYEE_ACCOUNT  = payPerfect.WalletMoney;
                model.PAYEE_NAME     = adminInfo;
                model.PAYMENT_AMOUNT = price == 0 ? price.Value : price.Value;
                model.PAYMENT_AMOUNT = Math.Round(model.PAYMENT_AMOUNT.Value, 2);
                model.PAYMENT_UNITS  = "USD";
                var req = Request.Params.AllKeys;
                var msg = "";
                if (req != null && req.Count() > 0)
                {
                    var Paymnet_Batch_Num = Request.Params["PAYMENT_BATCH_NUM"];
                    if (Paymnet_Batch_Num == "0" && Paymnet_Batch_Num != null)
                    {
                        models[0].Status = (int)Commons.DepositStatus.Cancel;
                        var result = facT.CreateDepositTransaction(models, ref msg, null);
                        NSLog.Logger.Info("Perface_Payment", "Perfect payment Cancel");
                        // cancel
                    }
                    else if (Paymnet_Batch_Num != "0" && Paymnet_Batch_Num != null)
                    {
                        models[0].Status      = (int)Commons.DepositStatus.Completed;
                        models[0].CustomerId  = customer.UserId;
                        models[0].CreatedDate = DateTime.Now;
                        models[0].UpdatedDate = DateTime.Now;;
                        models[0].CreatedBy   = customer.UserName;
                        models[0].PackageSMS  = price.Value;
                        List <string> lstID = new List <string>();
                        lstID.Add(models[0].CustomerId);
                        var result = facT.CreateDepositTransaction(models, ref msg, lstID);
                        //Success change status
                        CMS_DepositTransactionsModel inputModel = new CMS_DepositTransactionsModel();
                        inputModel.UpdatedBy  = CurrentUser.UserId;
                        inputModel.Status     = (int)Commons.DepositStatus.Completed;
                        inputModel.Id         = lstID[0];
                        inputModel.CustomerId = customer.UserId;
                        var outPut = facT.ChangeStatus(inputModel, CurrentUser.UserId);
                    }
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Info("Perface_Payment", "Perfect payment no successfully");
            }
            return(View(model));
        }