예제 #1
0
        public TransactionBdo StartTransaction(string posUserUid, ProductBdo product)
        {
            var t = new TransactionBdo();

            t.IsTestPayment = _configurationBll.Get().UseTestPayment;
            t.PosUserUid    = posUserUid;
            t.PaySystemUid  = product.PaySystemUid;

            t.PaymentStatus      = PaymentStatusIds.NotProcessed;
            t.IsPaymentProcessed = false;

            t.PosId     = product.PosId;
            t.CreatedAt = DateTime.UtcNow;

            t.ProductUid            = product.ProductUid;
            t.RequestedAmount       = product.ProductPrice;
            t.RequestedCurrencyCode = product.CurrencyCode;

            // TODO: add project ID
            t.ProjectId = 0;

            t.OrderNr = BllFactory.Current.GiftsBll.GetUniqueOrderId(t.PosId);
            Logger.DebugFormat("  generate unique order nr for new transaction: `{0}`", t.OrderNr);

            _transactionDal.StartTransaction(t);

            return(t);
        }
예제 #2
0
        // GET: /Gift/Get/UniqueGiftId
        public ActionResult Get(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                return(new RedirectResult(Url.Action("Index", "Home")));
            }

            var model = new ProductInformationModel();

            try
            {
                TransactionBdo transaction = null;

                // Could be old UID or new OrderNr
                if (id.Length < this.MySettings.LengthOfPosUid)
                {
                    Logger.Info("Trying to get coupon by its order nr: " + id);
                    transaction = Factory.TransactionsBll.GetTransactionByOrderNr(id);
                }
                else
                {
                    // Try to get using UID
                    Logger.Info("Trying to get coupon by payment system UID: " + id);
                    transaction = Factory.TransactionsBll.GetTransactionByPaySystemUid(id);
                }

                model.Product = Factory.GiftsBll.GetProductByPaySystemUid(transaction.PaySystemUid);
                model.Product.PosLatLng.LatLngString = Factory.HelperBll.GetLatLngString(model.Product.PosLatLng, MapTypes.YandexMap);
                model.Pos = Factory.PosBll.GetById(model.Product.PosId);

                model.PaymentStatus = transaction.PaymentStatus;
                model.IsPaidOk      = transaction.PaymentStatus == PaymentStatusIds.PaidOk;
                model.PaymentDate   = transaction.PaySystemResponseAt;
            }
            catch (InvalidOperationException ioex)
            {
                Logger.Error(ioex);
                return(NotFound());
            }
            catch (System.Data.Entity.Core.EntityException eex)
            {
                Logger.Fatal("Database exception, getting gift", eex);
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error("Error getting gift coupon by payment system UID: " + id, ex);
                throw;
            }


            return(View("Get", GetLayoutForPos(model.Pos.Id), model));
        }
예제 #3
0
        private TransactionBdo MapTo(transaction t)
        {
            TransactionBdo transaction = null;

            if (t != null)
            {
                PaymentStatusIds paymentStatus = PaymentStatusIds.NotProcessed;
                PaymentSystems   paymentSystem = PaymentSystems.None;
                int projectId = 0;

                int.TryParse(t.project_id, out projectId);
                Enum.TryParse(t.pay_system_id.ToString(), out paymentSystem);
                Enum.TryParse(t.payment_status_id.ToString(), out paymentStatus);

                transaction = new TransactionBdo
                {
                    Id = t.id,
                    IsPaymentProcessed = t.is_payment_processed,
                    IsTestPayment      = t.is_test_payment,

                    RequestedAmount       = t.requested_amount,
                    RequestedCurrencyCode = t.requested_currency_code,
                    PaidAmount            = t.paid_amount,
                    PaidCurrencyCode      = t.paid_currency_code,
                    PaidThrough           = t.paid_through,

                    PayerName     = t.p_name,
                    PayerLastName = t.p_lastname,
                    PayerEmail    = t.p_email,
                    PayerPhone    = t.p_phone,
                    Remarks       = t.remarks,

                    ProjectId    = projectId,
                    PosId        = t.pos_id,
                    PosUserUid   = t.pos_user_uid,
                    PaySystemUid = t.pay_system_uid,
                    ProductId    = t.product_id,
                    ProductUid   = t.product_uid,
                    OrderNr      = t.order_nr,

                    PaymentStatus = paymentStatus,
                    PaymentSystem = paymentSystem,

                    CreatedAt                 = t.created_at,
                    PaySystemResponseAt       = t.pay_system_response_at.HasValue ? t.pay_system_response_at.Value : DateTime.MinValue,
                    ResponseFromPaymentSystem = t.response_from_payment
                };
            }

            return(transaction);
        }
예제 #4
0
        private void SetTransactionStatusToCancelled(TransactionBdo t)
        {
            // Allow to cancel not processed and waiting for payment
            if (t.PaymentStatus != PaymentStatusIds.NotProcessed && t.PaymentStatus != PaymentStatusIds.WaitingForPayment)
            {
                throw new TransactionStatusException("User could not cancel transaction with status: " + t.PaymentStatus + " (" + (int)t.PaymentStatus + ")");
            }

            t.PaymentStatus       = PaymentStatusIds.UserCancelled;
            t.PaySystemResponseAt = DateTime.UtcNow;

            Logger.InfoFormat("  updating status of transaction #{0} to {1}", t.Id, t.PaymentStatus);
            _transactionDal.Update(t);
        }
예제 #5
0
        public void Update(TransactionBdo transactionBdo)
        {
            try
            {
                using (var db = new GiftServiceEntities())
                {
                    var t = db.transactions.First(x => x.id == transactionBdo.Id);

                    t.is_payment_processed   = transactionBdo.IsPaymentProcessed;
                    t.is_test_payment        = transactionBdo.IsTestPayment;
                    t.paid_amount            = transactionBdo.PaidAmount;
                    t.paid_currency_code     = transactionBdo.PaidCurrencyCode;
                    t.paid_through           = transactionBdo.PaidThrough;
                    t.payment_status_id      = (int)transactionBdo.PaymentStatus;
                    t.pay_system_id          = (int)transactionBdo.PaymentSystem;
                    t.pay_system_response_at = transactionBdo.PaySystemResponseAt;
                    t.pay_system_uid         = transactionBdo.PaySystemUid;
                    t.pos_id                  = transactionBdo.PosId;
                    t.pos_user_uid            = transactionBdo.PosUserUid;
                    t.product_id              = transactionBdo.ProductId;
                    t.product_uid             = transactionBdo.ProductUid;
                    t.project_id              = transactionBdo.ProjectId.ToString();
                    t.p_email                 = transactionBdo.PayerEmail;
                    t.p_lastname              = transactionBdo.PayerLastName;
                    t.p_name                  = transactionBdo.PayerName;
                    t.p_phone                 = transactionBdo.PayerPhone;
                    t.remarks                 = transactionBdo.Remarks;
                    t.requested_amount        = transactionBdo.RequestedAmount;
                    t.requested_currency_code = transactionBdo.RequestedCurrencyCode;
                    t.response_from_payment   = transactionBdo.ResponseFromPaymentSystem;

                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbvex)
            {
                Logger.Error("Validation error updating transaction", dbvex);
                foreach (var e in dbvex.EntityValidationErrors)
                {
                    foreach (var sub in e.ValidationErrors)
                    {
                        Logger.ErrorFormat("  {0,-16}: {1}", sub.PropertyName, sub.ErrorMessage);
                    }
                }
                throw;
            }
        }
예제 #6
0
 public void StartTransaction(TransactionBdo t)
 {
     throw new NotImplementedException();
 }
예제 #7
0
 public void Update(TransactionBdo t)
 {
     throw new NotImplementedException();
 }
예제 #8
0
        public void StartTransaction(TransactionBdo t)
        {
            //Mapper.CreateMap<TransactionBdo, transaction>()
            //    .ForMember(dest => dest.payment_status_id,
            //        orig => orig.MapFrom(x => (int)x.PaymentStatus));
            //AutoMapperConfigDal.SetMappingTypeFromBdoToDao();
            //var transaction = Mapper.Map<transaction>(t);
            try
            {
                var transaction = new transaction();
                transaction.is_test_payment         = t.IsTestPayment;
                transaction.payment_status_id       = (int)t.PaymentStatus;
                transaction.is_payment_processed    = t.IsPaymentProcessed;
                transaction.pos_user_uid            = t.PosUserUid;
                transaction.pay_system_uid          = t.PaySystemUid;
                transaction.order_nr                = t.OrderNr;
                transaction.requested_amount        = t.RequestedAmount;
                transaction.requested_currency_code = t.RequestedCurrencyCode;
                transaction.paid_amount             = t.PaidAmount;
                transaction.paid_currency_code      = t.PaidCurrencyCode;
                transaction.paid_through            = t.PaidThrough;
                transaction.p_name      = t.PayerName;
                transaction.p_lastname  = t.PayerLastName;
                transaction.p_email     = t.PayerEmail;
                transaction.p_phone     = t.PayerPhone;
                transaction.remarks     = t.Remarks;
                transaction.pos_id      = t.PosId;
                transaction.product_id  = t.ProductId;
                transaction.product_uid = t.ProductUid;
                transaction.project_id  = t.ProjectId.ToString();
                transaction.created_at  = DateTime.UtcNow;

                Logger.Info("Saving transaction in DB:");
                Logger.DebugFormat("  setting is_test_payment:              `{0}`", transaction.is_test_payment);
                Logger.DebugFormat("  setting payment_status_id:            `{0}`", transaction.payment_status_id);
                Logger.DebugFormat("  setting is_payment_processed:         `{0}`", transaction.is_payment_processed);
                Logger.DebugFormat("  setting pos_user_uid:                 `{0}`", transaction.pos_user_uid);
                Logger.DebugFormat("  setting pay_system_uid:               `{0}`", transaction.pay_system_uid);
                Logger.DebugFormat("  setting order_nr:                     `{0}`", transaction.order_nr);

                Logger.DebugFormat("  setting requested_amount:             `{0}`", transaction.requested_amount);
                Logger.DebugFormat("  setting requested_currency_code:      `{0}`", transaction.requested_currency_code);
                Logger.DebugFormat("  setting paid_amount:                  `{0}`", transaction.paid_amount);
                Logger.DebugFormat("  setting paid_currency_code:           `{0}`", transaction.paid_currency_code);
                Logger.DebugFormat("  setting paid_through:                 `{0}`", transaction.paid_through);

                Logger.DebugFormat("  setting p_name:                       `{0}`", transaction.p_name);
                Logger.DebugFormat("  setting p_lastname:                   `{0}`", transaction.p_lastname);
                Logger.DebugFormat("  setting p_email:                      `{0}`", transaction.p_email);
                Logger.DebugFormat("  setting p_phone:                      `{0}`", transaction.p_phone);
                Logger.DebugFormat("  setting remarks:                      `{0}`", transaction.remarks);

                Logger.DebugFormat("  setting pos_id:                       `{0}`", transaction.pos_id);
                Logger.DebugFormat("  setting product_id:                   `{0}`", transaction.product_id);
                Logger.DebugFormat("  setting product_uid:                  `{0}`", transaction.product_uid);

                Logger.DebugFormat("  setting response_from_payment:        `{0}`", transaction.response_from_payment);
                Logger.DebugFormat("  setting pay_system_response_at:       `{0}`", transaction.pay_system_response_at);
                Logger.DebugFormat("  setting created_at:                   `{0}`", transaction.created_at);

                using (var db = new GiftServiceEntities())
                {
                    db.transactions.Add(transaction);
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbvex)
            {
                Logger.Error("Validation error saving transaction", dbvex);
                foreach (var e in dbvex.EntityValidationErrors)
                {
                    foreach (var sub in e.ValidationErrors)
                    {
                        Logger.ErrorFormat("  {0,-16}: {1}", sub.PropertyName, sub.ErrorMessage);
                    }
                }
                throw;
            }
        }
예제 #9
0
        private void FillContent(Document doc, ProductBdo product, TransactionBdo transaction, bool asGift)
        {
            if (asGift)
            {
                var pMessage = doc.LastSection.AddParagraph();
                pMessage.Format.SpaceBefore = "8cm";
                pMessage.Format.SpaceAfter  = "1cm";
                pMessage.Format.Font.Size   = 14;
                pMessage.Format.Font.Bold   = false;
                pMessage.Format.Font.Italic = true;
                pMessage.Format.Alignment   = ParagraphAlignment.Center;
                pMessage.AddText(product.TextForGift);
                //pMessage.AddText("Kazkos ilgas tekstas su sveikinimu ir t.t.t.t.t.t. Kazkos ilgas tekstas su sveikinimu ir t.t.t.t.t.t. Kazkos ilgas tekstas su sveikinimu ir t.t.t.t.t.t. ");
            }


            var p = doc.LastSection.AddParagraph();

            if (asGift)
            {
                p.Format.SpaceBefore = "1cm";
                p.Format.SpaceAfter  = "0cm";
            }
            else
            {
                p.Format.SpaceBefore = "8cm";
                p.Format.SpaceAfter  = "1cm";
            }
            //p.Format.SpaceBefore = asGift ? "1cm" : "8cm";
            //p.Format.SpaceAfter = "1cm";
            p.Format.Font.Size = 14;
            p.Format.Font.Bold = true;
            p.Format.Alignment = ParagraphAlignment.Center;
            p.AddText(product.ProductName);

            var t = doc.LastSection.AddTable();

            t.BottomPadding            = "0.5cm";
            t.Format.Alignment         = ParagraphAlignment.Center;
            t.Borders.DistanceFromLeft = "2cm";

            // Before you can add a row, you must define the columns
            Column column = t.AddColumn("10cm");

            column.Format.Alignment = ParagraphAlignment.Left;

            column = t.AddColumn("7cm");
            column.Format.Alignment = ParagraphAlignment.Left;

            Row r = t.AddRow();

            if (asGift == false)
            {
                //r.Cells[0].AddParagraph(product.CustomerName);
                //r.Cells[0].AddParagraph("Jus gavote dovana");
                r.Cells[0].AddParagraph("Pirkėjas:")
                .Format.Font.Bold = true;
                // TODO: Extract info from payment or make custome name mandatory field
                if (String.IsNullOrEmpty(product.CustomerName))
                {
                    r.Cells[0].AddParagraph("-");
                }
                else
                {
                    r.Cells[0].AddParagraph(product.CustomerName);
                }

                r.Cells[1].AddParagraph("Kaina:")
                .Format.Font.Bold = true;
                r.Cells[1].AddParagraph(String.Concat(product.ProductPrice.ToString("### ##0.00"), " ", product.CurrencyCode));
            }

            //r = t.AddRow();
            //r.Cells[0].AddParagraph("Privalote užsiregistruoti:")
            //    .Format.Font.Bold = true;
            //r.Cells[0].AddParagraph(product.PhoneForReservation);

            //if (String.IsNullOrEmpty(product.ProductDuration) == false)
            //{
            //    r.Cells[1].AddParagraph("Trukme:")
            //            .Format.Font.Bold = true;
            //    r.Cells[1].AddParagraph(product.ProductDuration);
            //}

            r = t.AddRow();
            r.Cells[0].AddParagraph("Aptarnavimo vieta:")
            .Format.Font.Bold = true;
            r.Cells[0].AddParagraph(product.PosName);
            r.Cells[0].AddParagraph(product.PosAddress);
            r.Cells[0].AddParagraph(product.PosCity);

            r.Cells[1].AddParagraph("Privalote užsiregistruoti:")
            .Format.Font.Bold = true;
            r.Cells[1].AddParagraph(product.PhoneForReservation);

            if (String.IsNullOrEmpty(product.ProductDuration) == false)
            {
                r.Cells[1].AddParagraph("Trukme:")
                .Format = new ParagraphFormat {
                    SpaceBefore = "0.5cm",
                    Font        = new Font {
                        Bold = true
                    }
                };
                r.Cells[1].AddParagraph(product.ProductDuration);
            }


            //r.Cells[1].AddParagraph("Kuponas galioja:")
            //    .Format.Font.Bold = true;
            //r.Cells[1].AddParagraph(product.ValidTill.ToShortDateString())
            //    .Format.Font.Color = Colors.Red;

            var orderTable = doc.LastSection.AddTable();

            orderTable.Borders.DistanceFromLeft = "2cm";

            column = orderTable.AddColumn("10cm");
            column.Format.Alignment = ParagraphAlignment.Left;

            //column = orderTable.AddColumn("3cm");
            //column.Format.Alignment = ParagraphAlignment.Left;
            column = orderTable.AddColumn("7cm");
            column.Format.Alignment = ParagraphAlignment.Left;

            r = orderTable.AddRow();
            r.Cells[0].AddParagraph("Kupono numeris:")
            .Format.Font.Bold = true;
            r.Cells[0].AddParagraph(transaction.OrderNr.ToUpper())
            .Format.Font = new Font {
                Size = 13, Color = Colors.Red
            };

            r.Cells[1].AddParagraph("Kuponas galioja:")
            .Format.Font.Bold = true;
            r.Cells[1].AddParagraph(product.ValidTill.ToShortDateString())
            .Format.Font = new Font {
                Size = 13, Color = Colors.Red
            };

            //r.Cells[1].AddImage("c:\\temp\\qr1.png");

            var desription = doc.LastSection.AddParagraph();

            desription.Format.SpaceBefore = "1cm";
            desription.Format.Alignment   = ParagraphAlignment.Justify;
            desription.Format.Font.Size   = 10;
            desription.AddText(product.ProductDescription);
        }
예제 #10
0
        public ActionResult Validate(string id)
        {
            Logger.Info("Got request to validate transaction: " + id);
            bool   isOk = false;
            string msg  = "Nothing";

            try
            {
                TransactionBdo t = null;
                if (id.Length == MySettings.LengthOfPosUid)
                {
                    Factory.SecurityBll.ValidateUid(id);
                    t = Factory.TransactionsBll.GetTransactionByPaySystemUid(id);
                }
                else
                {
                    Factory.SecurityBll.ValidateOrderNr(id);
                    t = Factory.TransactionsBll.GetTransactionByOrderNr(id);
                }

                if (t == null)
                {
                    throw new Exception("Transaction is not found");
                }

                isOk = true;
                switch (t.PaymentStatus)
                {
                case PaymentStatusIds.NotProcessed:
                    msg = String.Concat("Payment is not processed. Transaction created at: ", t.CreatedAt.ToString());
                    break;

                case PaymentStatusIds.WaitingForPayment:
                    msg = String.Concat("Payment is not paid. Transaction created at: ", t.CreatedAt.ToString());
                    break;

                case PaymentStatusIds.UserCancelled:
                    msg = String.Concat("Payment is cancelled by user. Transaction created at: ", t.CreatedAt.ToString());
                    break;

                case PaymentStatusIds.PaidOk:
                    msg = String.Concat("Payment is paid. Paid at: ", t.PaySystemResponseAt.ToString(), ". Paid amount is: ", t.PaidAmount.ToString("### ##0.00"), t.PaidCurrencyCode);
                    break;

                case PaymentStatusIds.AcceptedButNotExecuted:
                    msg = String.Concat("Payment is paid, but bank is processing it. Paid at: ", t.PaySystemResponseAt.ToString(), ". Paid amount is: ", t.PaidAmount.ToString("### ##0.00"), t.PaidCurrencyCode);
                    break;

                default:
                    break;
                }
            }
            catch (InvalidOperationException ioex)
            {
                Logger.Error("No transaction was found", ioex);
                msg = "No transaction was found";
            }
            catch (Exception ex)
            {
                Logger.Error("Error validating transaction", ex);
                isOk = false;
                msg  = ex.Message;
            }

            return(Json(new { Status = isOk, Message = msg }));
        }