コード例 #1
0
        public int MTransferPayment(string json)
        {
            Session session = new Session(json);

            if (session.AutoCapture)
            {
                session.CaptureOn = DateTime.Now;
            }
            int Response = 0;

            if (TempData["TutorModel"] != null)
            {
                UserCache userCache = JsonConvert.DeserializeObject <UserCache>(TempData["TutorModel"].ToString());
                string    Learner   = String.Concat(userCache.FirstName, userCache.LastName);
                Operation Op        = new Operation {
                    UID             = userCache.UserId,
                    RelationId      = session.Id,
                    RelationEntity  = "Event",
                    Amount          = session.Amount,
                    Currency        = session.Currency,
                    CaptureOn       = getCaptureDate(LkpDetails["MoneyTransfer"], session.DateStamp, session.CancelationDate),
                    Captured        = 0,
                    RespDate        = DateTime.Now,
                    Auto            = 0,
                    Description     = session.Title,
                    OprTypeId       = LkpDetails["Payment"],
                    PaymentMethodId = LkpDetails["MoneyTransfer"],
                    SerialId        = Serials["PT"],
                    ObjEntityId     = 1,
                    RespAttch       = session.Photo,
                    CancelationDate = session.CancelationDate,
                    TutorId         = session.TutorId,
                    TutorName       = session.TutorName,
                    billingInfo     = new BillingInfo()
                };
                Response = PaymentDB.SubmitOperation(Op, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                if (Response != 0)
                {
                    Op.LinkedOprId = Response;
                    SendNotification(DateTime.Now, Learner, "OMT 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 OMT Fees

                    decimal fee = Convert.ToDecimal(Perc["OmtFees"]);
                    decimal Per = Convert.ToDecimal(Perc["OmtPercentage"]);
                    SubtractFees(Op, "OMT Fees", fee, Per, Serials["FT"]);
                    TempData.Keep("TutorModel");
                    return(Response);
                }
                return(0);
            }
            return(Response);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        //Cancel Chekout Fees when refund money
        private void CancelFees(Operation Op, string Method, decimal Fees, decimal percentage, int serial)
        {
            Op.UID       = 40108; //Nabih chkout id
            Op.Amount    = Op.Amount * (decimal)percentage + (decimal)Fees;
            Op.Auto      = 1;
            Op.Captured  = 0;
            Op.OprTypeId = LkpDetails["Refund"];
            Op.Canceled  = 1;

            int Response = PaymentDB.SubmitOperation(Op, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));

            SendNotification(DateTime.Now, Method, "Refund CHKT Fees", Op.Amount, Op.Captured);
        }
コード例 #4
0
        //Chekout Fees or OMT Fees
        private void SubtractFees(Operation Op, string Method, decimal Fees, decimal percentage, int serial)
        {
            Op.UID    = serial == 8 ? 40108 : 40109; //Nabih chkout id
            Op.Amount = Op.Amount * (decimal)percentage + (decimal)Fees;
            Op.Auto   = 1;
            //Op.Captured = 0;
            Op.OprTypeId   = LkpDetails["Fees"];
            Op.SerialId    = serial;
            Op.LinkedOprId = Op.Id;
            Console.WriteLine(Op);
            int Response = PaymentDB.SubmitOperation(Op, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));

            SendNotification(DateTime.Now, Method, "CHKT Fees", Op.Amount, Op.Captured);
        }
コード例 #5
0
        //Decrease tutor Balance when cash operation done
        private void SubtractTutorFees(Operation Op, long TutorId, string TutorName, decimal percentage)
        {
            Op.UID    = TutorId;
            Op.Amount = Op.Amount * (decimal)percentage;
            Op.Auto   = 1;
            //Op.Captured = 0;
            Op.OprTypeId   = LkpDetails["Fees"];
            Op.SerialId    = Serials["FI"];
            Op.LinkedOprId = Op.Id;

            int Response = PaymentDB.SubmitOperation(Op, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));

            SendNotification(DateTime.Now, TutorName, "INTO Fees", Op.Amount, Op.Captured);
        }
コード例 #6
0
        public int CashPayment(string json)
        {
            Session session = new Session(json);

            if (session.AutoCapture)
            {
                session.CaptureOn = DateTime.Now;
            }
            int Response = 0;

            if (TempData["TutorModel"] != null)
            {
                UserCache userCache = JsonConvert.DeserializeObject <UserCache>(TempData["TutorModel"].ToString());
                Operation Op        = new Operation {
                    UID             = userCache.UserId,
                    RelationId      = session.Id,
                    RelationEntity  = "Event",
                    Amount          = session.Amount,
                    Currency        = session.Currency,
                    CaptureOn       = getCaptureDate(LkpDetails["Cash"], session.DateStamp, session.CancelationDate),
                    Captured        = 0,
                    RespDate        = DateTime.Now,
                    Auto            = 0,
                    Description     = session.Title,
                    OprTypeId       = LkpDetails["Payment"],
                    PaymentMethodId = LkpDetails["Cash"],
                    SerialId        = Serials["PC"],
                    ObjEntityId     = 1,
                    CancelationDate = session.CancelationDate,
                    TutorId         = session.TutorId,
                    TutorName       = session.TutorName,
                    billingInfo     = new BillingInfo()
                };
                Response = PaymentDB.SubmitOperation(Op, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                if (Response != 0)
                {
                    Op.LinkedOprId = Response;
                    SendNotification(DateTime.Now, userCache.FirstName, "Cash Pymt", session.Amount, Op.Captured);
                    //Operation 2 : Subtract tutor Fees
                    decimal fee = 1 - Convert.ToDecimal(Perc["TutorPercentage"]);
                    SubtractTutorFees(Op, session.TutorId, session.TutorName, fee);
                    TempData.Keep("TutorModel");
                    return(Response);
                }
                return(0);
            }
            return(Response);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public int ApiRequestPayment(string json)
        {
            Session session = new Session(json);

            //if (session.AutoCapture == true) { session.CaptureOn = DateTime.Now; }
            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);
                //Build API Request
                object jsonParameters = new
                {
                    source = new
                    {
                        type  = "token",
                        token = session.Token
                    },
                    customer = new
                    {
                        email = userCache.Email,
                        name  = Learner
                    },
                    description = session.Title,
                    amount      = session.Amount * 100,
                    currency    = session.Currency,
                    approved    = true,
                    reference   = "Session-" + session.Id,
                    capture_on  = session.CaptureOn
                };
                string  responseString = ApiRequest(jsonParameters, "https://api.sandbox.checkout.com/payments");
                dynamic jObj           = (JObject)JsonConvert.DeserializeObject(responseString);

                //if the API request success add operations to DB
                if (jObj != null && jObj.status == "Authorized")
                {
                    //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,
                        billingInfo     = new BillingInfo()
                        {
                            UID          = userCache.UserId,
                            ObjEntityId  = 1,//Nabih get user Entity id
                            CardId       = jObj.source.id,
                            CardType     = jObj.source.scheme,
                            CardExpYear  = jObj.source.expiry_year,
                            CardLast4dig = jObj.source.last4,
                            CardExpMnth  = jObj.source.expiry_month
                        }
                    };
                    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);
                }
                else
                {
                    if (jObj.response_code == 20087)
                    {
                        Response = -1;                             // Invalid card cvv or exp date
                    }
                }
            }
            return(Response);
        }