コード例 #1
0
ファイル: AirtimeController.cs プロジェクト: Paelyt/Payorboro
        public ActionResult Checkout(Classes.Paytv.PaytvObj _pv)
        {
            try
            {
                int PayMethod = PaymentMethod(_pv.paymethod);

                string user = LoggedInuser.LoggedInUser();
                if (user != null && PayMethod == 0)
                {
                    Classes.Paytv.PaytvObj paytv  = new Paytv.PaytvObj();
                    Classes.Paytv.PaytvObj paytvs = new Paytv.PaytvObj();
                    paytv  = (Classes.Paytv.PaytvObj)ViewBag.PaytvObj;
                    paytvs = (Classes.Paytv.PaytvObj)TempData["PaytvObj"];

                    string Firstname   = _pv.CustomerID;
                    string Email       = _pv.CustomerID;
                    string PhoneNumber = _pv.CustomerID;
                    string Amount      = _pv.Amount;
                    string ConvFee     = _pv.ConvFee;

                    //string ConvFee = ConfigurationManager.AppSettings["ConvFee"];
                    var    TotalAmt  = Convert.ToDecimal(Amount) + Convert.ToDecimal(ConvFee);
                    string TotalAmts = TotalAmt.ToString();
                    var    TranNum   = _pv.transactionlNo;
                    // i have to uncomment out this Line
                    int paymenttype = _dr.GetCustomerpaytype(TranNum);
                    // int paymenttype = 1;
                    int  paymentplanId = _dr.GetPaymentPlanID(_pv.Bouquet);
                    bool isNum         = Decimal.TryParse(TotalAmts, out TotalAmt);

                    if (isNum)
                    {
                        PaymentManager.Payment PayObj = new PaymentManager.Payment();
                        PayObj.PaymentType  = paymenttype;
                        PayObj.RefNumber    = TranNum; //System.DateTime.Now.ToString("yyyyMMddHmmss");
                        PayObj.amount       = TotalAmt.ToString();
                        PayObj.customerid   = "2";
                        PayObj.customerName = Firstname;
                        PayObj.emailaddress = Email;
                        PayObj.narration    = $"{Firstname.Trim()} Payment of NGN {decimal.Parse(PayObj.amount)}";
                        PayObj.phoneNo      = PhoneNumber;

                        PayObj.returnUrl     = ConfigurationManager.AppSettings["PavicePaymentReturnUrl"];
                        PayObj.PaymentPlanID = paymentplanId;
                        //PayObj.returnUrl = GetReturnUrl(PayObj.returnUrl);
                        string formObject = PaymentManager.GetPaymentPageDatails(PayObj);
                        if (formObject != "")
                        {
                            Response.Clear();
                            Response.ContentEncoding = Encoding.GetEncoding("ISO-8859-1"); Response.HeaderEncoding = Encoding.GetEncoding("ISO-8859-1");
                            Response.Charset         = "ISO-8859-1";
                            Response.Write(formObject);
                            Response.End();
                        }
                        else
                        {
                            TempData["Message"] = "Error Calling Payment Page - Code P002";
                        }
                    }
                    else
                    {
                        TempData["Message"] = "Error Calling Payment Page - Code P002";
                    }
                }
                else
                {
                    if (user != null && PayMethod == 1)
                    {
                        var    userid        = _dr.getUserID(user);
                        var    WalletBalance = _dr.WalletBalance(userid.id);
                        double Amount        = Convert.ToDouble(_pv.Amount);
                        if (WalletBalance >= Amount)
                        {
                            dynamic response = paySubscribtion(_pv.transactionlNo);
                            TempData["ErrMsg"] = "Transaction Successful!";
                            Receipt(response, _pv.transactionlNo);
                            _tL.ReferenceNumber = _pv.transactionlNo;
                            var id = _dc.InsertCustomerWallet(_tL);
                        }
                        else if (WalletBalance < Amount)
                        {
                            Classes.Internetserviceprovider.InternetServiceObj _ptv = new Classes.Internetserviceprovider.InternetServiceObj();
                            _ptv.Amount          = _pv.Amount;
                            _ptv.CustomerID      = _pv.CustomerID;
                            _ptv.transactionlNo  = _pv.transactionlNo;
                            _ptv.Service         = _pv.Service;
                            _pv.ConvFee          = "0";
                            TempData["TotalAmt"] = _pv.Amount;
                            TempData["PaytvObj"] = _ptv;
                            TempData["Msg"]      = "Low Balance In Wallet !";
                            return(Redirect("/Airtime/Checkout/"));
                        }
                        return(RedirectToAction("WalletReceipt", new { @RefNum = _tL.ReferenceNumber }));
                    }
                }
                return(View());
            }
            catch (Exception ex)
            {
                WebLog.Log(ex.Message.ToString());
                return(null);
            }
        }