public int ApiRefundPayment(long OprId = 0)
        {
            int Response = -1;

            if (TempData["TutorModel"] != null)
            {
                Operation op = PaymentDB.GetOprDetails(OprId, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                if (op.Captured == 0 || op.Auto == 1 || op.PaymentMethodId != LkpDetails["Card"] || DateTime.Compare(DateTime.Now, op.CancelationDate) > 0)
                {
                    return(0);
                }

                UserCache userCache = JsonConvert.DeserializeObject <UserCache>(TempData["TutorModel"].ToString());
                string    Learner   = String.Concat(userCache.FirstName, userCache.LastName);

                object jsonParameters = new
                {
                    reference = "REFUND-" + op.RelationId
                };
                Console.WriteLine(op.ApiReference);
                var     requestUrl     = "https://api.sandbox.checkout.com/payments/" + op.ApiReference + "/refunds";
                string  responseString = ApiRequest(jsonParameters, requestUrl);
                dynamic jObj           = (JObject)JsonConvert.DeserializeObject(responseString);
                if (jObj != null)
                {
                    op.RespDate    = DateTime.Now;
                    op.RespDetails = responseString.Replace("\"", string.Empty);
                    op.RespId      = jObj.id;
                    op.Auto        = 0;
                    op.Captured    = 1;
                    op.OprTypeId   = LkpDetails["Refund"];
                    op.SerialId    = Serials["RF"];
                    op.LinkedOprId = OprId;
                    op.UID         = userCache.UserId;
                    op.ObjEntityId = 1;//Nabih get user Entity id
                    Response       = PaymentDB.CancelOperation(OprId, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    Response       = PaymentDB.SubmitOperation(op, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    if (Response != 0)
                    {
                        op.LinkedOprId = Response;
                        SendNotification(DateTime.Now, Learner, "Refund Pymt", op.Amount, op.Captured);

                        //Operation 2 : Substract tutor Revenue

                        decimal revenue = 1 - Convert.ToDecimal(Perc["TutorPercentage"]);
                        SubtractTutorFees(op, op.TutorId, op.TutorName, revenue);
                        //Operation 3 : Cancel Checkout Fees
                        decimal fee = Convert.ToDecimal(Perc["CheckoutFees"]);
                        decimal Per = Convert.ToDecimal(Perc["CheckoutPercentage"]);
                        CancelFees(op, "Refund Checkout Fees", fee, Per, Serials["FC"]);
                    }
                }
            }
            return(Response);
        }
        public int ApiVoidPayment(long OprId = 0)
        {
            int Response = -1;

            if (TempData["TutorModel"] != null)
            {
                Operation op = PaymentDB.GetOprDetails(OprId, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));

                if (op.Captured == 0 || op.Auto == 1 || op.PaymentMethodId != LkpDetails["Card"])
                {
                    return(0);
                }

                UserCache userCache = JsonConvert.DeserializeObject <UserCache>(TempData["TutorModel"].ToString());
                string    Learner   = String.Concat(userCache.FirstName, userCache.LastName);

                object jsonParameters = new
                {
                    reference = "VOID-" + op.RelationId
                };
                Console.WriteLine(op.ApiReference);
                var     requestUrl     = "https://api.sandbox.checkout.com/payments/" + op.ApiReference + "/captures";
                string  responseString = ApiRequest(jsonParameters, requestUrl);
                dynamic jObj           = (JObject)JsonConvert.DeserializeObject(responseString);
                if (jObj != null)
                {
                    op.RespDate    = (DateTime)jObj.processed_on;
                    op.RespDetails = responseString.Replace("\"", string.Empty);
                    op.RespId      = jObj.id;
                    op.Auto        = 0;
                    op.Captured    = 1;
                    op.OprTypeId   = LkpDetails["Void"];
                    op.SerialId    = Serials["PB"];
                    op.LinkedOprId = OprId;
                    op.UID         = userCache.UserId;
                    op.ObjEntityId = 1;//Nabih get user Entity id

                    Response = PaymentDB.CancelOperation(OprId, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    Response = PaymentDB.SubmitOperation(op, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    if (Response != 0)
                    {
                        SendNotification(DateTime.Now, Learner, "Void Pymt", op.Amount, op.Captured);
                    }
                }
            }
            return(Response);
        }