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 PaymentCallback(string id)
        {
            var orderLayer = new OrderLayer();
            var payment    = orderLayer.Order.Payments.FirstOrDefault(f => f.Id == orderLayer.Order.PaymentTypeId);

            var posWorker  = new PosWorker();
            var posSetting = posWorker.GetSitePosSetting(payment.PosType);


            switch (id.ToLower())
            {
            case "paypal":
                if (Request.Params["result"] == "fail")
                {
                    return(View("PaymentError"));
                }
                var paypal       = new Components.Payment.Paypal.Controller(posSetting.Parameters);
                var paypalresult = paypal.PaymentExcution(Request.Params["payerId"], Request.Params["paymentId"]);
                if (paypalresult.Status)
                {
                    var paymentWorker      = new PaymentWorker();
                    var paymentEntityModel = Mapper.Map <PaymentEntityViewModel>(orderLayer.Order);
                    paymentEntityModel.PaymentDate = DateTime.Now;
                    paymentEntityModel.Status      = 0;
                    paymentEntityModel.Log         = paypalresult.Data;
                    paymentWorker.InsertSitePaymentEntity(paymentEntityModel);
                }
                return(RedirectToAction("Commit", new { id = orderLayer.Order.Id.ToString("000000") }));

            case "payflex":
                if (Request.Params["result"] == "fail")
                {
                    return(RedirectToAction("Payment", "Bir hata oluştu lütfen tekrar deneyin!"));
                }
                Components.Payment.PayFlex.Controller payFlex  = Session["PayFlexInstance"] as Components.Payment.PayFlex.Controller;
                Dictionary <string, string>           formdata = new Dictionary <string, string>();
                foreach (string prm in Request.Params.AllKeys)
                {
                    formdata.Add(prm, Request.Params[prm]);
                }
                payFlex.MPITransaction = new Components.Payment.PayFlex.Models.MPITransactionResponse(formdata);
                payFlex.MPIChekout(posSetting.Parameters["mpicheckouturl"]);
                if (int.Parse(payFlex.PaymentModel.Installment) > 0)
                {
                    var result = payFlex.CheckoutResult as Components.Payment.PayFlex.Models.VInstallmentResponse;
                    if (result.ResultCode == "0000")
                    {
                        var paymentWorker      = new PaymentWorker();
                        var paymentEntityModel = Mapper.Map <PaymentEntityViewModel>(orderLayer.Order);
                        paymentEntityModel.PaymentDate = DateTime.Now;
                        paymentEntityModel.Status      = 0;
                        paymentEntityModel.Log         = Components.Converters.StringSerializer.Serialize <Components.Payment.PayFlex.Models.VInstallmentResponse>(payFlex.CheckoutResult);
                        paymentWorker.InsertSitePaymentEntity(paymentEntityModel);
                        return(RedirectToAction("Commit", new { id = orderLayer.Order.Id }));
                    }
                    else
                    {
                        return(RedirectToAction("Payment", "Bir hata oluştu lütfen tekrar deneyin!"));
                    }
                }
                else
                {
                    var result = payFlex.CheckoutResult as Components.Payment.PayFlex.Models.VPrepaidResponse;
                    if (result.ResultCode == "0000")
                    {
                        var paymentWorker      = new PaymentWorker();
                        var paymentEntityModel = Mapper.Map <PaymentEntityViewModel>(orderLayer.Order);
                        paymentEntityModel.PaymentDate = DateTime.Now;
                        paymentEntityModel.Status      = 0;
                        paymentEntityModel.Log         = Components.Converters.StringSerializer.Serialize <Components.Payment.PayFlex.Models.VPrepaidResponse>(payFlex.CheckoutResult);
                        paymentWorker.InsertSitePaymentEntity(paymentEntityModel);
                        return(RedirectToAction("Commit", new { id = orderLayer.Order.Id }));
                    }
                    else
                    {
                        return(RedirectToAction("Payment", "Bir hata oluştu lütfen tekrar deneyin!"));
                    }
                }

            default:
                return(null);
            }
        }
Exemplo n.º 3
0
        public ActionResult Payment(Models.Internal.PaymentModel model)
        {
            if (ModelState.IsValid)
            {
                var posWorker  = new PosWorker();
                var posSetting = posWorker.GetSitePosSetting(model.Pos);

                var orderLayer = new OrderLayer();
                var payment    = orderLayer.Order.Payments.FirstOrDefault(f => f.Id == orderLayer.Order.PaymentTypeId);

                switch (model.Pos)
                {
                case "payflex":
                    var akposRequest = new Components.Payment.PayFlex.Models.MPIStatusRequest
                    {
                        BankId           = posSetting.Referance,
                        BrandName        = model.CardType == "visa" ? "100" : model.CardType == "mastercard" ? "200" : "",
                        ExpiryDate       = model.ExpiryMonth + model.ExpiryYear,
                        FailureUrl       = Request.Url.Host + "/Order/PaymentCallback/payflex?result=fail",
                        MerchantId       = posSetting.Parameters["merchantid"],
                        MerchantPassword = posSetting.Parameters["password"],
                        InstallmentCount = int.Parse(model.Installment) > 0 ? model.Installment : null,
                        Pan                       = model.CCNumber,
                        PurchaseAmount            = string.Format("{0:F0}", orderLayer.Order.GrandTotal * 100),
                        SuccessUrl                = Request.Url.Host + "/Order/PaymentCallback/payflex?result=ok",
                        VerifyEnrollmentRequestId = orderLayer.Order.Id.ToString()
                    };
                    var payFlex = new Components.Payment.PayFlex.Controller(akposRequest);
                    if (payFlex.Is3D(posSetting.Parameters["mpiurl"]))
                    {
                        payFlex.PaymentModel       = model;
                        Session["PayFlexInstance"] = payFlex;
                        return(View("PayFlexMpiPost", payFlex.MPIStatus));
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(akposRequest.InstallmentCount))
                        {
                            //TODO: payflex TRY kodu girilecek
                            var vprepaidRequest = new Components.Payment.PayFlex.Models.VPrepaidRequest
                            {
                                BankId          = akposRequest.BankId,
                                CurrencyAmount  = akposRequest.Currency,
                                CurrencyCode    = "888",
                                Cvv             = model.Ccv,
                                Expiry          = akposRequest.ExpiryDate,
                                MerchantId      = akposRequest.MerchantId,
                                Pan             = akposRequest.Pan,
                                Password        = akposRequest.MerchantPassword,
                                TransactionId   = Guid.NewGuid().ToString(),
                                TransactionType = "sale"
                            };
                            payFlex.VPrepaidCheckout(posSetting.Parameters["checkouturl"], vprepaidRequest);
                            if (payFlex.CheckoutResult.ResultCode == "0000")
                            {
                                var paymentWorker      = new PaymentWorker();
                                var paymentEntityModel = Mapper.Map <PaymentEntityViewModel>(orderLayer.Order);
                                paymentEntityModel.PaymentDate = DateTime.Now;
                                paymentEntityModel.Status      = 0;
                                paymentEntityModel.Log         = Components.Converters.StringSerializer.Serialize <Components.Payment.PayFlex.Models.VPrepaidResponse>(payFlex.CheckoutResult);
                                paymentWorker.InsertSitePaymentEntity(paymentEntityModel);
                                return(RedirectToAction("Commit", new { id = orderLayer.Order.Id }));
                            }
                            else
                            {
                                return(RedirectToAction("Payment", new { message = (new Components.Payment.PayFlex.ErrorCodes())[payFlex.CheckoutResult.ResultCode] }));
                            }
                        }
                        else
                        {
                            //TODO: payflex TRY kodu girilecek
                            var vinstallmentRequest = new Components.Payment.PayFlex.Models.VInstallmentRequest
                            {
                                BankId           = akposRequest.BankId,
                                CurrencyAmount   = akposRequest.Currency,
                                CurrencyCode     = "888",
                                Cvv              = model.Ccv,
                                Expiry           = akposRequest.ExpiryDate,
                                MerchantId       = akposRequest.MerchantId,
                                Pan              = akposRequest.Pan,
                                Password         = akposRequest.MerchantPassword,
                                TransactionId    = Guid.NewGuid().ToString(),
                                TransactionType  = "sale",
                                InstallmentCount = akposRequest.InstallmentCount
                            };
                            payFlex.VInstallmentCheckout(posSetting.Parameters["checkouturl"], vinstallmentRequest);
                            if (payFlex.CheckoutResult.ResultCode == "0000")
                            {
                                var paymentWorker      = new PaymentWorker();
                                var paymentEntityModel = Mapper.Map <PaymentEntityViewModel>(orderLayer.Order);
                                paymentEntityModel.PaymentDate = DateTime.Now;
                                paymentEntityModel.Status      = 0;
                                paymentEntityModel.Log         = Components.Converters.StringSerializer.Serialize <Components.Payment.PayFlex.Models.VInstallmentResponse>(payFlex.CheckoutResult);
                                paymentWorker.InsertSitePaymentEntity(paymentEntityModel);
                                return(RedirectToAction("Commit", new { id = orderLayer.Order.Id }));
                            }
                            else
                            {
                                return(RedirectToAction("Payment", new { message = (new Components.Payment.PayFlex.ErrorCodes())[payFlex.CheckoutResult.ResultCode] }));
                            }
                        }
                    }

                default:
                    return(RedirectToAction("Begin"));
                }
            }
            return(View(model));
        }