Ejemplo n.º 1
0
        public void AutoPay()
        {
            var db = new GreenProDbEntities();
            DoReferenceTrasaction paypal = new DoReferenceTrasaction();
            //get customers whose subscription is valid and auto renewal is on
            //get customers whose subscription is valid and auto renewal is off
            var lastTransactionDate = DateTime.Now.AddDays(-7);
            var monthBackDate       = DateTime.Now.AddDays(-30);
            var list = (from a in db.PayPalLogs
                        where !string.IsNullOrEmpty(a.BillingAggrementID) && a.ServerDate <= lastTransactionDate
                        orderby a.ServerDate
                        select a).ToList();

            //pay pal logic
            foreach (var item in list)
            {
                var userPackage = db.UserPackages.FirstOrDefault(a => a.Id == item.SubscriptionID);
                var car         = db.CarUsers.FirstOrDefault(a => a.CarId == userPackage.CarId);
                var package     = db.Packages.FirstOrDefault(a => a.PackageId == userPackage.PackageId);


                if (userPackage != null && (car != null && (car.AutoRenewal || (userPackage.SubscribedDate.AddDays(30) >= DateTime.Now))))
                {
                    string message  = string.Empty;
                    var    response = paypal.DoTransaction(item.BillingAggrementID, package.Package_Description, package.Package_Name, (double)userPackage.TotalPrice, "Weekly Renewal", out message);
                }
            }
        }
Ejemplo n.º 2
0
        public string TestAutoPayment()
        {
            string OriResponsePaypal     = string.Empty;
            DoReferenceTrasaction paypal = new DoReferenceTrasaction();
            var    response       = paypal.DoTransaction("B-9MJ87472989329538", "Economy Description ", "Economy", (double)61M, "Economy Subscription Weekly Renewal", out OriResponsePaypal);
            string responseString = string.Empty;

            responseString = JsonConvert.SerializeObject(response);

            responseString = responseString + " : Paypal Response: " + OriResponsePaypal;

            return(responseString);
        }
Ejemplo n.º 3
0
        public string TakePaymentFromPaypal(int UserPackageId, string BillingAggrementID, DateTime CarServiceDate, int JobId)
        {
            string responseString = string.Empty;
            var    db             = new GreenProDbEntities();

            if (UserPackageId > 0)
            {
                var userPackage = db.UserPackages.FirstOrDefault(a => a.Id == UserPackageId);
                var car         = db.CarUsers.FirstOrDefault(a => a.CarId == userPackage.CarId);
                var package     = db.Packages.FirstOrDefault(a => a.PackageId == userPackage.PackageId);
                var JobDetail   = db.Garage_CarDaySetting.Where(i => i.Id == JobId).SingleOrDefault();
                //decimal finalPrice = userPackage.TotalPrice + userPackage.TaxAmount + userPackage.TipAmount; // Comment By Nitendra 28 SEP 2016

                decimal AddOnsPrice = 0M;
                AddOnsPrice = userPackage.UserPackagesAddons.Sum(s => s.ActualPrice);

                decimal finalPrice = userPackage.ActualPrice + AddOnsPrice + userPackage.TaxAmount;

                if (userPackage != null && (car != null && (car.AutoRenewal)))
                {
                    string message = string.Empty;

                    string OriResponsePaypal     = string.Empty;
                    DoReferenceTrasaction paypal = new DoReferenceTrasaction();
                    var response = paypal.DoTransaction(BillingAggrementID, package.Package_Description, package.Package_Name, (double)finalPrice, "Weekly Renewal", out OriResponsePaypal);

                    responseString = JsonConvert.SerializeObject(response);

                    responseString = responseString + " : Paypal Response: " + OriResponsePaypal;


                    PaypalAutoPayment paypalAutoPayment = new PaypalAutoPayment();
                    paypalAutoPayment.UserPackageID      = userPackage.Id;
                    paypalAutoPayment.UserID             = userPackage.UserId;
                    paypalAutoPayment.IsPaid             = response.PaymentStatus == "COMPLETED"? true:false;
                    paypalAutoPayment.GrossAmount        = String.Format("{0:0.00}", finalPrice); //Convert.ToString(finalPrice);
                    paypalAutoPayment.PaymentStatus      = response.PaymentStatus;
                    paypalAutoPayment.PaymentDate        = response.PaymentDate;
                    paypalAutoPayment.TrasactionID       = response.TransactionID;
                    paypalAutoPayment.BillingAggrementID = BillingAggrementID;
                    paypalAutoPayment.TransactionDate    = DateTime.Now;

                    paypalAutoPayment.ServiceDate = CarServiceDate;
                    paypalAutoPayment.CreatedOn   = DateTime.Now;

                    db.PaypalAutoPayments.Add(paypalAutoPayment);
                    db.SaveChanges();

                    if (paypalAutoPayment.IsPaid)
                    {
                        JobDetail.IsPaid = true;
                        db.SaveChanges();

                        UserTransaction _transaction = new UserTransaction()
                        {
                            Userid             = userPackage.UserId,
                            PaypalId           = "",
                            TransactionDate    = DateTime.Now,
                            Amount             = finalPrice,
                            PackageId          = userPackage.Id,
                            Details            = "No Details",
                            BillingAggrementID = BillingAggrementID,
                            TrasactionID       = paypalAutoPayment.TrasactionID,
                        };
                        db.UserTransactions.Add(_transaction);
                        db.SaveChanges();
                    }
                }
            }

            return(responseString);
        }
Ejemplo n.º 4
0
        public ActionResult Success()
        {
            SetExpressCheckOut express = new SetExpressCheckOut();

            PayPalSystem.Models.PaypalResponse response = new PayPalSystem.Models.PaypalResponse();
            response.ECToken = Request.QueryString["token"];
            var token = response.ECToken;
            var user  = db.PayPalLogs.Where(a => a.ECToken == token).FirstOrDefault();

            response = express.CreateBillingAgreement(response);


            PayPalLog log = new PayPalLog()
            {
                ACK                 = "BillingAgreement",
                ApiSatus            = response.ApiStatus,
                BillingAggrementID  = (response.BillingAgreementID == null) ? string.Empty : response.BillingAgreementID,
                CorrelationID       = response.CorrelationID,
                ECToken             = token,
                ResponseError       = (response.ResponseError == null) ? string.Empty : response.ResponseError.ToString(),
                ResponseRedirectURL = (response.ResponseRedirectURL == null) ? string.Empty : response.ResponseRedirectURL,
                ServerDate          = DateTime.Now,
                TimeStamp           = response.Timestamp,
                UserId              = user.UserId,
                SubscriptionID      = user.SubscriptionID
            };

            db.PayPalLogs.Add(log);
            db.SaveChanges();

            //Save USer Logs
            var             finalPrice   = user.UserPackage.TotalPrice + user.UserPackage.TaxAmount + user.UserPackage.TipAmount;
            UserTransaction _transaction = new UserTransaction()
            {
                Userid             = user.UserId,
                PaypalId           = user.ECToken,
                TransactionDate    = DateTime.Now,
                Amount             = finalPrice,
                PackageId          = user.SubscriptionID,
                Details            = "No Details",
                BillingAggrementID = log.BillingAggrementID
            };

            db.UserTransactions.Add(_transaction);
            db.SaveChanges();
            //Logic to disable autorenew if Billingagreement is null



            //Logic to update Transaction status
            var userPackages = db.UserPackages.Find(user.SubscriptionID);

            if (userPackages != null)
            {
                string message               = string.Empty;
                string responseString        = string.Empty;
                var    package               = db.Packages.FirstOrDefault(a => a.PackageId == userPackages.PackageId);
                string OriResponsePaypal     = string.Empty;
                DoReferenceTrasaction paypal = new DoReferenceTrasaction();
                var doResponse               = paypal.DoTransaction(log.BillingAggrementID, package.Package_Description, package.Package_Name, (double)finalPrice, "Weekly Renewal", out OriResponsePaypal);

                ///Write paypal response in txt file.
                responseString = JsonConvert.SerializeObject(response);
                responseString = responseString + " : Paypal Response: " + OriResponsePaypal;
                string fileName = userPackages.Id + "-" + log.BillingAggrementID + "__" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm", CultureInfo.InvariantCulture) + ".txt";
                System.IO.File.WriteAllText(Server.MapPath("~/App_Data/" + fileName), responseString);


                PaypalAutoPayment paypalAutoPayment = new PaypalAutoPayment();
                paypalAutoPayment.UserPackageID      = userPackages.Id;
                paypalAutoPayment.UserID             = userPackages.UserId;
                paypalAutoPayment.IsPaid             = doResponse.PaymentStatus == "COMPLETED" ? true : false;
                paypalAutoPayment.GrossAmount        = String.Format("{0:0.00}", finalPrice); //Convert.ToString(finalPrice);
                paypalAutoPayment.PaymentStatus      = doResponse.PaymentStatus;
                paypalAutoPayment.PaymentDate        = doResponse.PaymentDate;
                paypalAutoPayment.TrasactionID       = doResponse.TransactionID;
                paypalAutoPayment.BillingAggrementID = log.BillingAggrementID;
                paypalAutoPayment.TransactionDate    = DateTime.Now;

                DateTime currentDate = DateTime.Now;
                DateTime serviceDate = currentDate;
                if (userPackages.ServiceDay == currentDate.DayOfWeek.ToString())
                {
                    serviceDate = currentDate.AddDays(7);
                }
                else
                {
                    DateTime nextServiceDate;
                    for (int i = 1; i <= 6; i++)
                    {
                        if (i == 1)
                        {
                            nextServiceDate = currentDate.AddDays(i);
                            if (userPackages.ServiceDay == nextServiceDate.DayOfWeek.ToString())
                            {
                                if (userPackages.SubscriptionTypeId == 1)
                                {
                                    serviceDate = nextServiceDate.AddDays(7);
                                }
                                else if (userPackages.SubscriptionTypeId == 2)
                                {
                                    serviceDate = nextServiceDate.AddDays(14);
                                }
                                else if (userPackages.SubscriptionTypeId == 3)
                                {
                                    serviceDate = nextServiceDate.AddDays(28);
                                }
                                else
                                {
                                    serviceDate = nextServiceDate.AddDays(7);
                                }

                                break;
                            }
                        }
                        else
                        {
                            nextServiceDate = currentDate.AddDays(i);
                            if (userPackages.ServiceDay == nextServiceDate.DayOfWeek.ToString())
                            {
                                serviceDate = currentDate.AddDays(i);
                                break;
                            }
                        }
                    }
                }

                paypalAutoPayment.ServiceDate = serviceDate;
                paypalAutoPayment.CreatedOn   = DateTime.Now;
                db.PaypalAutoPayments.Add(paypalAutoPayment);
                db.SaveChanges();

                if (paypalAutoPayment.IsPaid)
                {
                    userPackages.PaymentRecieved   = true;
                    userPackages.IsActive          = true;
                    userPackages.NextServiceDate   = serviceDate;
                    userPackages.PaymentMethodName = "paypal";
                    db.Entry(userPackages).State   = EntityState.Modified;
                    db.SaveChanges();

                    ///Added By Sachin 29 SEP 2016
                    var addOnsServices = userPackages.UserPackagesAddons.ToList();
                    foreach (var addOns in addOnsServices)
                    {
                        if (!addOns.NextServiceDate.HasValue)
                        {
                            addOns.NextServiceDate = serviceDate;
                            db.SaveChanges();
                        }
                    }
                }
            }


            Session["NewServiceCarTypeId"] = null;
            Session["SelectedCar"]         = null;
            Session["NewServiceGarageId"]  = null;

            var userInfo = userPackages.AspNetUser;

            // Send Notification Mail Admin for buy new subscrition.
            _workflowMessageService.SendNewSubscriptionNotificationToAdmin(userInfo.FirstName + " " + userInfo.LastName, userInfo.UserName, userPackages.Package.Package_Name, userPackages.SubscribedDate.ToString(), userPackages.CarUser.Garage.Garage_Name);

            return(View());
        }