Beispiel #1
0
        void ChangeStatus(PaymentStatusLevel changeToStatus, IList lstTransPaym)
        {
            ExpandCollapseAllGroups();

            List <DebtorTransDirectDebit> ListDebTransPaymStop = new List <DebtorTransDirectDebit>();

            if (changeToStatus == PaymentStatusLevel.StopPayment)
            {
                foreach (var rec in (IEnumerable <DebtorTransDirectDebit>)dgDebtorTranOpenGrid.ItemsSource)
                {
                    if (rec._PaymentStatus == PaymentStatusLevel.StopPayment || rec._PaymentStatus == PaymentStatusLevel.OnHold || rec._PaymentStatus == PaymentStatusLevel.None || rec._PaymentStatus == PaymentStatusLevel.PaymentReceived || rec._PaymentStatus == PaymentStatusLevel.PaymentReceivedDiff)
                    {
                        continue;
                    }
                    else
                    {
                        ListDebTransPaymStop.Add(rec);
                    }
                }
            }
            IEnumerable <DebtorTransDirectDebit> queryPaymentTransStop = ListDebTransPaymStop.AsEnumerable();



            Common.ChangeStatus(api, lstTransPaym, changeToStatus, PaymentFormatCache, queryPaymentTransStop);
        }
Beispiel #2
0
        public static void ChangeStatus(Company comp, DebtorTransDirectDebit rec, PaymentStatusLevel changeToStatus)
        {
            var statusInfoTxt = rec._StatusInfo;

            if (changeToStatus == PaymentStatusLevel.None)
            {
                if (rec._PaymentStatus != PaymentStatusLevel.Sent && rec._PaymentStatus != PaymentStatusLevel.Processed && rec._PaymentStatus != PaymentStatusLevel.PaymentReceived && rec._PaymentStatus != changeToStatus)
                {
                    statusInfoTxt      = string.Format("({0}) Status changed '{1}'->{2}\n{3}", DateTime.Now.ToString("dd.MM.yy HH:mm"), rec._PaymentStatus, changeToStatus, statusInfoTxt);
                    rec._PaymentStatus = changeToStatus;
                    rec._SendTime      = DateTime.MinValue;
                }
                else
                {
                    rec._ErrorInfo = string.Format("Change status from '{0}'->'{1}' not possible", rec._PaymentStatus, changeToStatus);
                }
            }
            else if (changeToStatus == PaymentStatusLevel.Resend)
            {
                if (rec._PaymentStatus != PaymentStatusLevel.Sent && rec._PaymentStatus != PaymentStatusLevel.Processed && rec._PaymentStatus != PaymentStatusLevel.PaymentReceived && rec._PaymentStatus != changeToStatus)
                {
                    statusInfoTxt      = string.Format("({0}) Status changed '{1}'->{2}\n{3}", DateTime.Now.ToString("dd.MM.yy HH:mm"), rec._PaymentStatus, changeToStatus, statusInfoTxt);
                    rec._PaymentStatus = changeToStatus;
                    rec._SendTime      = DateTime.MinValue;
                }
                else
                {
                    rec._ErrorInfo = string.Format("Change status from '{0}'->'{1}' not possible", rec._PaymentStatus, changeToStatus);
                }
            }
            else if (changeToStatus == PaymentStatusLevel.StopPayment)
            {
                if (rec._PaymentStatus == PaymentStatusLevel.Sent)
                {
                    var      today    = BasePage.GetSystemDefaultDate();
                    DateTime deadline = new DateTime(rec._PaymentDate.Year, rec._PaymentDate.Month, rec._PaymentDate.Day - 1, DirectDebitPaymentHelper.DEADLINE_TIMEOFDAY, 0, 0);
                    deadline = DirectDebitBankHolidays.AdjustBankDay(comp._CountryId, deadline, false);

                    if (today >= deadline)
                    {
                        rec._ErrorInfo = string.Format("'Stop Payment' not possible (Deadline {0}", deadline.ToString("dd-MM-yyyy kl. HH:mm"));
                        rec.NotifyErrorSet();
                    }
                    else
                    {
                        statusInfoTxt      = string.Format("({0}) Status changed '{1}'->{2}\n{3}", DateTime.Now.ToString("dd.MM.yy HH:mm"), rec._PaymentStatus, changeToStatus, statusInfoTxt);
                        rec._PaymentStatus = changeToStatus;
                        rec._SendTime      = DateTime.MinValue;
                    }
                }
                else
                {
                    rec._ErrorInfo = string.Format("Change status from '{0}'->'{1}' not possible", rec._PaymentStatus, changeToStatus);
                }
            }
            else if (changeToStatus == PaymentStatusLevel.OnHold)
            {
                if (rec._PaymentStatus != PaymentStatusLevel.Sent && rec._PaymentStatus != PaymentStatusLevel.Processed && rec._PaymentStatus != PaymentStatusLevel.PaymentReceived && rec._PaymentStatus != changeToStatus)
                {
                    statusInfoTxt      = string.Format("({0}) Status changed '{1}'->{2}\n{3}", DateTime.Now.ToString("dd.MM.yy HH:mm"), rec._PaymentStatus, changeToStatus, statusInfoTxt);
                    rec._PaymentStatus = changeToStatus;
                    rec._SendTime      = DateTime.MinValue;
                }
                else
                {
                    rec._ErrorInfo = string.Format("Change status from '{0}'->'{1}' not possible", rec._PaymentStatus, changeToStatus);
                }
            }

            while (statusInfoTxt != null && statusInfoTxt.Length > 1000)
            {
                statusInfoTxt = statusInfoTxt.Remove(statusInfoTxt.TrimEnd().LastIndexOf("\n"));
            }

            rec._StatusInfo = statusInfoTxt;
            rec.NotifyErrorSet();
        }
        public void OnPaymentComplete( PaymentType paymentType, PaymentStatusLevel paymentStatus, BillingInfo billingInfo, DeliveryInfo deliveryInfo, Order order)
        {
            if ( paymentType == PaymentType.CreditCard && paymentStatus == PaymentStatusLevel.WaitingForPayment)
            {
                // payment failed, we won't record it in db
                order.PaymentStatus = paymentStatus.ToString();

            }
            else
            {
                var cart = ShoppingCartHelper.GetCart(HttpContext);
                order.PaymentStatus = paymentStatus.ToString();
                order.TxnId = order.TxnId;
                order.OrderStatusId = (int)OrderStatusLevel.Processing;
                order.PaymentNote = paymentType.ToString() ;
                order.OrderReceivedAt = DateTime.Now;
                db.Orders.AddObject(order);
                db.SaveChanges();
                foreach (var cartItem in cart.ShoppingCartItems)
                {
                    order.OrderItems.Add(new OrderItem()
                    {
                        OrderId = order.OrderId,
                        ItemId = cartItem.ItemId,
                        ItemTypeId = cartItem.ItemTypeId,
                        LineItemCost = cartItem.LineItemCost,
                        Quantity = cartItem.Quantity
                    });
                }
                db.SaveChanges();

                // save payer details
                var payer = (MyLunchBoxMembershipUser)(new MyLunchBoxMembershipProvider().GetUser(User.Identity.Name, true));
                var userDetails = db.UserDetails.Single(i => i.UserId == order.UserId);
                userDetails.FirstName = order.ReceiverFirstName;
                userDetails.LastName = order.ReceiverLastName;
                userDetails.UniversityId = LocationHelper.GetSelectedUniversityId(HttpContext);
                userDetails.UniversityDeliveryId = LocationHelper.GetDeliveryLocationId(HttpContext);
                if (billingInfo != null)
                {
                    if (userDetails.Location == null)
                    {
                        var location = new Location()
                        {
                            LocationName = billingInfo.BillingAddress1,
                            FirstName = billingInfo.BillingFirstName,
                            LastName = billingInfo.BillingLastName,
                            Address1 = billingInfo.BillingAddress1,
                            Address2 = billingInfo.BillingAddress2,
                            City = billingInfo.City,
                            StateOrProvince = billingInfo.State,
                            ZipCode = billingInfo.ZipCode,
                            CountryCode = billingInfo.CountryCode.ToString(),
                            Country = "United States"
                        };
                        db.Locations.AddObject(location);
                        db.SaveChanges();
                        userDetails.LocationId = location.LocationId;
                    }
                    else
                    {
                        userDetails.Location.FirstName = billingInfo.BillingFirstName;
                        userDetails.Location.LastName = billingInfo.BillingLastName;
                        userDetails.Location.Address1 = billingInfo.BillingAddress1;
                        userDetails.Location.Address2 = billingInfo.BillingAddress2;
                        userDetails.Location.City = billingInfo.City;
                        userDetails.Location.StateOrProvince = billingInfo.State;
                        userDetails.Location.ZipCode = billingInfo.ZipCode;
                    }

                }
                db.UserDetails.ApplyCurrentValues(userDetails);
                db.SaveChanges();
                //process reward
                if (order.rewardPoints > 0)
                {
                    var reward = new Reward()
                    {
                        Amount = -order.rewardPoints,
                        RewardTypeId = (int)RewardType.Order,
                        OrderId = order.OrderId,
                        RewardCreatedAt = DateTime.Now,
                        UserId = MembershipHelper.GetUserIdByEmail(payer.UserName),
                        RewardDescription = "Consume reward points"
                    };
                    db.Rewards.AddObject(reward);
                }
                if(order.OrderItems.Count(i=>i.ItemTypeId == (int)ItemType.MembershipCard) > 0) {
                    var rewardCards = order.OrderItems.Where(i=>i.ItemTypeId == (int)ItemType.MembershipCard);
                    var totalPoints = 0.0m;
                    foreach( var rewardCard in rewardCards) {
                        var card = db.RewardCards.Single(i=>i.RewardCardId == rewardCard.ItemId);
                        totalPoints += card.RewardPoints * rewardCard.Quantity;
                    }
                    var reward = new Reward()
                    {
                        Amount = totalPoints,
                        RewardTypeId = (int)RewardType.RewardCard,
                        OrderId = order.OrderId,
                        Txn = order.TxnId,
                        RewardCreatedAt = DateTime.Now,
                        UserId = MembershipHelper.GetUserIdByEmail(payer.UserName),
                        RewardDescription = "Reward Card Redeemed"
                    };
                    db.Rewards.AddObject(reward);
                }
                db.SaveChanges();

                var oss = new OrderStatusService();
                oss.SendOrderConfirmationMail(order.OrderId);
                // empty shopping cart
                ShoppingCartHelper.EmptyCart(HttpContext);
            }
        }