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")); } }
//GET: Commit public ActionResult Commit(int id) { var orderLayer = new OrderLayer(); string orderMail = this.RenderRazorView("Mails/Order", orderLayer.Order); var customerWorker = new CustomerWorker(); var customerUser = customerWorker.GetCustomerUser(CustomerLayer.Customer.Id.ToString()); var mailer = new Khaled.SmtpClient.SmtpMailClient(); mailer.PostMail(ConfigurationManager.AppSettings["AdminEmail"], "Sipariş", orderMail); BasketLayer.RemoveAll(); ViewBag.Method = id; return(View(orderLayer.Order)); }
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)); }
//GET: Begin public ActionResult Begin() { var customerWorker = new CustomerWorker(); var shipmentWorker = new ShipmentWorker(); ViewBag.Cities = LocationWalker.GetCities().Select(s => new SelectListItem { Value = s.Id.ToString(), Text = s.Title }); ViewBag.Districts = LocationWalker.GetDistrict(1).Select(s => new SelectListItem { Value = s.Id.ToString(), Text = s.Title }); var orderLayer = OrderLayer.Create(); orderLayer.Order.Addresses = customerWorker.GetSiteCustomerAddresses(CustomerLayer.Customer.Id, 1); orderLayer.Order.Shipments = shipmentWorker.GetSiteShipmentTypes(); return(View(orderLayer.Order)); }
public ActionResult Payment(string message = null) { 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 (posSetting.AssemblyData) { case "paypal": var paypal = new Components.Payment.Paypal.Controller(posSetting.Parameters); return(Redirect(paypal.Payment())); case "payflex": ViewData["Pos"] = posSetting.AssemblyData; ViewData["Installment"] = payment.Installments.FirstOrDefault(f => f.Id == orderLayer.Order.InstallmentId).NumberOf; ViewData["Message"] = message; return(View()); default: return(null); } }
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); } }
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)); }
public string Payment() { var culture = CultureInfo.GetCultureInfo("en-US"); IFormatProvider numericFormatProvider = culture.NumberFormat; var orderLayer = new OrderLayer(); var itemList = new ItemList(); itemList.items = new List <Item>(); foreach (var line in orderLayer.Order.Lines) { var item = new Item { currency = "TRY", description = line.ProductName, name = line.ProductName, price = line.Price.ToString("F2", numericFormatProvider), quantity = line.Quantity.ToString(), sku = line.ProductId.ToString(), tax = line.Tax.ToString("F2", numericFormatProvider) }; itemList.items.Add(item); } var payer = new Payer { payment_method = "paypal" }; var baseUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + "/Order/PaymentCallback/Paypal"; var redirUrl = new RedirectUrls { return_url = baseUrl + "?result=ok", cancel_url = baseUrl + "?result=fail" }; var details = new Details { fee = (orderLayer.Order.InstallmentFee + orderLayer.Order.PaymentFee).ToString("F2", numericFormatProvider), shipping = orderLayer.Order.ShipCost.ToString("F2", numericFormatProvider), tax = orderLayer.Order.TaxTotal.ToString("F2", numericFormatProvider), subtotal = orderLayer.Order.OrderTotal.ToString("F2", numericFormatProvider) }; var amount = new Amount { currency = "TRY", total = orderLayer.Order.GrandTotal.ToString("F2", numericFormatProvider), details = details }; var transactionList = new List <Transaction>(); transactionList.Add( new Transaction { invoice_number = orderLayer.Order.Id.ToString("00000000"), amount = amount, item_list = itemList } ); var payment = new PayPal.Api.Payment { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrl }; var paymenter = payment.Create(apiCtx); var links = paymenter.links.GetEnumerator(); while (links.MoveNext()) { var link = links.Current; if (link.rel.ToLower().Trim().Equals("approval_url")) { return(link.href); } } return(string.Empty); }