Exemplo n.º 1
0
        public ActionResult Transaction(FormCollection frm)
        {
            var paymentWorker = new PaymentWorker();
            var orderWorker   = new OrderWorker();
            var orderLayer    = new OrderLayer();

            orderLayer.Order.PaymentTypeId = int.Parse(frm["paymentType"]);
            var paymentDetail = paymentWorker.GetSitePaymentType(orderLayer.Order.PaymentTypeId);

            //payment commission calculation
            decimal currentPaymentFee = paymentDetail.ProcessFee + (orderLayer.Order.GrandTotal * (decimal)(paymentDetail.CommissionRate / 100));
            decimal currentPaymentTax = orderLayer.Order.PaymentFee * 0.18M;

            currentPaymentFee -= currentPaymentTax;

            //installment commision calculation
            decimal currentInstallmentFee = 0M;
            decimal currentInstallmentTax = 0M;

            if (paymentDetail.Method == 2)
            {
                orderLayer.Order.InstallmentId = int.Parse(frm["installment"]);
                currentInstallmentFee          = orderLayer.Order.GrandTotal * (decimal)(paymentDetail.Installments.FirstOrDefault(f => f.Id == orderLayer.Order.InstallmentId).Rate / 100);
                currentInstallmentTax          = currentInstallmentFee * 0.18M;
                currentInstallmentFee         -= currentInstallmentTax;
            }

            //join payment and installment to order
            orderLayer.Order.PaymentFee     = currentPaymentFee;
            orderLayer.Order.InstallmentFee = currentInstallmentFee;

            //add tax and grand total
            orderLayer.Order.TaxTotal   += currentPaymentTax + currentInstallmentTax;
            orderLayer.Order.GrandTotal += orderLayer.Order.PaymentFee + orderLayer.Order.InstallmentFee;
            orderLayer.Sync();

            orderLayer.Order.Id = orderWorker.InsertSiteOrder(orderLayer.Order);
            orderLayer.Sync();

            if (paymentDetail.Method == 1)
            {
                var paymentEntityModel = Mapper.Map <PaymentEntityViewModel>(orderLayer.Order);
                paymentEntityModel.PaymentDate   = DateTime.Now;
                paymentEntityModel.Status        = 0;
                paymentEntityModel.Log           = "Peşin ödeme";
                paymentEntityModel.InstallmentId = null;
                paymentWorker.InsertSitePaymentEntity(paymentEntityModel);
                return(RedirectToAction("Commit", new { id = paymentDetail.Method }));
            }
            else
            {
                return(RedirectToAction("Payment"));
            }
        }
Exemplo n.º 2
0
        public ActionResult Checkout(FormCollection frm)
        {
            var shipmentWorker = new ShipmentWorker();
            var paymentWorker  = new PaymentWorker();
            var customerWorker = new CustomerWorker();
            var orderLayer     = new OrderLayer();

            if (frm["AddressId"] != null)
            {
                orderLayer.Order.ShipAddressId = int.Parse(frm["AddressId"]);
                if (frm["InvoiceSendPartial"] == "yes")
                {
                    orderLayer.Order.InvoiceAddressId = int.Parse(frm["InvoiceAddressId"]);
                }
                else
                {
                    orderLayer.Order.InvoiceAddressId = int.Parse(frm["AddressId"]);
                }
            }

            orderLayer.Order.ShipmentTypeId = int.Parse(frm["ShipmentType"]);
            orderLayer.Order.Note           = frm["Note"];

            if (orderLayer.Order.ShipCost == 0)
            {
                decimal shipCost = ShippingHelper.ShippingPrice(shipmentWorker.GetSiteShipmentType(orderLayer.Order.ShipmentTypeId));
                orderLayer.Order.TaxTotal   += shipCost * 18 / 118;
                orderLayer.Order.ShipCost    = shipCost * 100 / 118;
                orderLayer.Order.GrandTotal += shipCost;
            }

            orderLayer.Sync();
            orderLayer.Order.Payments = paymentWorker.GetSitePaymentTypes();

            ViewBag.ShipmentType = shipmentWorker.GetSiteShipmentType(orderLayer.Order.ShipmentTypeId);
            if (orderLayer.Order.ShipAddressId.HasValue)
            {
                ViewBag.ShipmentAddress = customerWorker.GetSiteCustomerAddress(orderLayer.Order.ShipAddressId.Value);
            }

            if (frm["InvoiceSendPartial"] == "yes")
            {
                ViewBag.InvoiceAddress = customerWorker.GetSiteCustomerAddress(orderLayer.Order.InvoiceAddressId.Value);
            }

            return(View(orderLayer.Order));
        }