public IActionResult PayNow1(int SessionId)
 {
     if (TempData["TutorModel"] != null)
     {
         UserCache    userCache    = JsonConvert.DeserializeObject <UserCache>(TempData["TutorModel"].ToString());
         PaymentModel paymentModel = new PaymentModel
         {
             User = userCache.Extract()
         };
         paymentModel.session     = PaymentDB.GetSessionDetails(SessionId, paymentModel.User.UserId, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
         paymentModel.wallet      = PaymentDB.GetWallet(paymentModel.User.UserId, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
         paymentModel.billingInfo = PaymentDB.GetBillingInfo(userCache.UserId, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
         TempData.Keep("TutorModel");
         return(PartialView(paymentModel));
     }
     return(PartialView(new PaymentModel()));
 }
        public int ApiCardDetails(string json)
        {
            Session session = new Session(json);

            session.CaptureOn = getCaptureDate(LkpDetails["Card"], session.DateStamp, session.CancelationDate);
            int Response = 0;

            if (TempData["TutorModel"] != null)
            {
                UserCache   userCache = JsonConvert.DeserializeObject <UserCache>(TempData["TutorModel"].ToString());
                string      Learner   = String.Concat(userCache.FirstName, userCache.LastName);
                BillingInfo bl        = PaymentDB.GetBillingInfo(userCache.UserId, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                //Build API Request
                object jsonParameters = new
                {
                    source = new
                    {
                        type = "id",
                        id   = bl.CardId
                    },
                    amount     = session.Amount * 100,
                    reference  = "Session-" + session.Id,
                    currency   = session.Currency,
                    capture_on = session.CaptureOn
                };
                Console.WriteLine(jsonParameters);
                var     requestUrl     = "https://api.sandbox.checkout.com/payments/";
                string  responseString = ApiRequest(jsonParameters, requestUrl);
                dynamic jObj           = (JObject)JsonConvert.DeserializeObject(responseString);
                //if the API request success add operations to DB
                if (jObj != null)
                {
                    //Operation 1 : Record Learner Payment
                    Operation Op = new Operation
                    {
                        UID             = userCache.UserId,
                        RelationId      = session.Id,
                        RelationEntity  = "Event",
                        Amount          = session.Amount,
                        Currency        = session.Currency,
                        RespDate        = (DateTime)jObj.processed_on,
                        RespDetails     = responseString.Replace("\"", string.Empty),
                        CaptureOn       = getCaptureDate(LkpDetails["Card"], session.DateStamp, session.CancelationDate),
                        Auto            = 0,
                        Description     = session.Title,
                        ServiceId       = session.Service == "F2F" ? LkpDetails["F2F"] : LkpDetails["Online"],
                        RespId          = jObj.id,
                        OprTypeId       = LkpDetails["Payment"],
                        PaymentMethodId = LkpDetails["Card"],
                        SerialId        = Serials["PB"],
                        ObjEntityId     = 1,//Nabih get user Entity id
                        CancelationDate = session.CancelationDate,
                        TutorId         = session.TutorId,
                        TutorName       = session.TutorName
                    };
                    if (Op.CaptureOn != session.DateStamp)
                    {
                        Op.Captured = 1;
                    }
                    Response = PaymentDB.SubmitOperation(Op, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));

                    if (Response != 0)
                    {
                        Op.LinkedOprId = Response;
                        SendNotification(DateTime.Now, Learner, "Card Pymt", session.Amount, Op.Captured);
                        //Operation 2 : Add tutor Revenue

                        decimal revenue = Convert.ToDecimal(Perc["TutorPercentage"]);
                        AddTutorRevenue(Op, session.TutorId, session.TutorName, revenue);
                        //Operation 3 : Subtract Checkout Fees
                        decimal fee = Convert.ToDecimal(Perc["CheckoutFees"]);
                        decimal Per = Convert.ToDecimal(Perc["CheckoutPercentage"]);
                        SubtractFees(Op, "Checkout Fees", fee, Per, Serials["FC"]);
                    }
                    TempData.Keep("TutorModel");
                    return(Response);
                }
            }
            return(Response);
        }