コード例 #1
0
        private PaymentStatusResponseViewModel ConstructPaymentResponseModel()
        {
            var paymentInfo = new CheckoutPaymentInfo
            {
                MerchantCode = Request["MerchantCode"] ?? "",
                PaymentId = Request["PaymentId"] ?? "",
                RefNo = Request["RefNo"] ?? "",
                Amount = Request["Amount"] ?? "",
                Currency = Request["Currency"] ?? "",
                Remark = Request["Remark"] ?? "",
                Signature = Request["Signature"] ?? ""
            };

            var viewModel = new PaymentStatusResponseViewModel
            {
                PaymentInfo = paymentInfo,
                TransID = Request["TransId"] ?? "",
                AuthCode = Request["AuthCode"] ?? "",
                Status = Request["Status"] ?? "",
                ErrDesc = Request["ErrDesc"] ?? ""
            };

            return viewModel;
        }
コード例 #2
0
        public virtual ActionResult Summary()
        {
            var access = Util.SessionAccess;
            var viewModel = new CheckoutSummaryViewModel();
            var openStatus = Status.Open.ToString();

            using (var context = new TTTEntities())
            {
                var salesOrder = context.trnsalesorders
                    .Include(a => a.refstatu)
                    .SingleOrDefault(a => a.Email == access.Email && a.refstatu.Name == openStatus);

                if (salesOrder == null)
                    throw new ApplicationException("No Order found.");

                viewModel.AllowPayment = salesOrder.refstatu.Name == openStatus;

                viewModel.SalesOrderID = salesOrder.ID;

                viewModel.BillingAddress = context.lnksoaddresses
                    .Include(a => a.refcountry)
                    .Single(a => a.IsBilling && a.Active && a.SalesOrderID == salesOrder.ID);

                viewModel.ShippingAddress = context.lnksoaddresses
                    .Include(a => a.refcountry)
                    .Single(a => a.IsShipping && a.Active && a.SalesOrderID == salesOrder.ID);

                var items =
                    (from a in context.lnksalesorders
                     join b in context.lnkmodelsizes on a.ModelSizeID equals b.ID into bTemp
                     from bb in bTemp.DefaultIfEmpty()
                     join c in context.lnkmodelcolourdescs on new { ColourDescID = bb.ColourDescID, ModelID = bb.ModelID }
                         equals new { ColourDescID = c.ColourDescID, ModelID = c.ModelID } into cTemp
                     from cc in cTemp.DefaultIfEmpty()
                     join d in context.refmodels on cc.ModelID equals d.ID into dTemp
                     from dd in dTemp.DefaultIfEmpty()
                     join e in context.refbrands on dd.BrandID equals e.ID into eTemp
                     from ee in eTemp.DefaultIfEmpty()
                     join f in context.refcategories on ee.CategoryID equals f.ID into fTemp
                     from ff in fTemp.DefaultIfEmpty()
                     join h in context.refcolourdescs on cc.ColourDescID equals h.ID into hTemp
                     from hh in hTemp.DefaultIfEmpty()
                     join i in context.refcolours on hh.ColourID equals i.ID into iTemp
                     from ii in iTemp.DefaultIfEmpty()
                     join g in context.lnkcustomizemodelimages on a.SKU equals g.SKU into gTemp
                     from gg in gTemp.DefaultIfEmpty()
                     join j in context.refcustomizemodels on gg.CustomizeModelID equals j.ID into jTemp
                     from jj in jTemp.DefaultIfEmpty()
                     where a.SalesOrderID == salesOrder.ID && a.Active
                     select new
                     {
                         Color = a.ModelSizeID.HasValue ? hh.Name : gg.Colour,
                         ImageUrl = a.ModelSizeID.HasValue ? "~/images/" + ff.Name + "/"
                            : "~/Images/Customize/ShoeColour/" + gg.MainImage,
                         Name = a.ModelSizeID.HasValue ? dd.Name : jj.Name,
                         Price = a.ModelSizeID.HasValue ? ((dd.DiscountPrice.HasValue && dd.DiscountPrice.Value > 0) ? dd.DiscountPrice.Value : dd.Price) : jj.Price,
                         Quantity = a.Quantity,
                         Size = a.ModelSizeID.HasValue ? bb.Size : a.Size,
                         ModelSizeID = a.ModelSizeID,
                         ModelColourDescID = a.ModelSizeID.HasValue ? cc.ID : 0
                     }).Distinct().ToList();

                viewModel.Items = new List<CheckoutSummaryItem>();

                foreach (var item in items)
                {
                    var summaryItem = new CheckoutSummaryItem
                    {
                        Color = item.Color,
                        ImageUrl = item.ImageUrl,
                        Name = item.Name,
                        Price = item.Price,
                        Quantity = item.Quantity,
                        Size = item.Size
                    };

                    if (item.ModelSizeID.HasValue)
                    {
                        var modelImage = 
                            context.lnkmodelimages.FirstOrDefault(a => a.ModelColourDescID == item.ModelColourDescID);

                        if (modelImage != null)
                            summaryItem.ImageUrl += modelImage.Image;
                    }

                    viewModel.Items.Add(summaryItem);
                }

                viewModel.Subtotal = viewModel.Items.Sum(a => a.Price * a.Quantity);
                viewModel.ShippingPrice = Properties.Settings.Default.ShippingFee;
                viewModel.OrderTotalPrice = viewModel.Subtotal + viewModel.ShippingPrice;

                if (salesOrder.VoucheID.HasValue)
                {
                    var currentVoucher = context.tblvouchers.Where(a => a.ID == salesOrder.VoucheID.Value).Single();

                    viewModel.VoucherCode = currentVoucher.Code;
                    viewModel.RebateCashValue = currentVoucher.Value;
                    viewModel.OrderTotalPrice -= currentVoucher.Value;
                }
            }

            //foreach (var item in viewModel.Items)
            //{
            //    item.Size = Util.GetSizeText(Convert.ToInt32(item.Size));
            //}

            var paymentAmount = 1.00; // Convert.ToDouble(viewModel.OrderTotalPrice)
            var paymentInfo = new CheckoutPaymentInfo
            {
                Amount = paymentAmount.ToString("N"),
                BackendUrl = Url.ActionAbsolute(MVC.Payment.BackendResponse()),
                Currency = Settings.Default.iPay88_Currency,
                EntryUrl = Settings.Default.iPay88_EntryUrl,
                Lang = Settings.Default.iPay88_Lang,
                MerchantCode = Settings.Default.iPay88_MerchantCode,
                PaymentId = "",
                ProdDesc = "Sales Order",
                RefNo = viewModel.SalesOrderID.ToString(),
                Remark = "",
                ResponseUrl = Url.ActionAbsolute(MVC.Payment.StatusResponse()),
                UserContact = access.Phone,
                UserEmail = access.Email,
                UserName = access.FirstName + access.LastName
            };

            paymentInfo.Signature = Util.ConstructIPay88Signature(paymentInfo.RefNo, paymentAmount);
            viewModel.PaymentInfo = paymentInfo;

            return View(viewModel);
        }