public static string ExpressCheckout(WorldpayViewModel order) { NameValueCollection values = new NameValueCollection(); values["instId"] = "1018224"; values["cartId"] = order.OrderID; values["amount"] = order.Total; values["currency"] = "GBP"; values["desc"] = order.Description; values["testMode"] = "100"; values["MC_callback"] = "http://Ns3.sbcserver.com/WorldPay/WorldPayCallback"; values["name"] = order.CustomerName; values["address"] = order.Address; values["postcode"] = order.PostCode; return(Submit(values)); //values = Submit(values); ////string ack = values["ACK"].ToLower(); ////if (ack == "success" || ack == "successwithwarning") ////{ // return new WorldpayRedirect // { // Token = values["TOKEN"], // Url = String.Format("https://select.worldpay.com/wcc/purchase?{0}", // values["TOKEN"]) // }; //} //else //{ // throw new Exception(values["L_LONGMESSAGE0"]); //} }
private ActionResult Customer(object customer) { var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); //if (Session["orderType"].ToString() == "" || cart.Items.Count() == 0) // return RedirectToAction("Index", "Home"); string dt = ""; if (Session[Constants.SESSION_DELIVERY_TIME] != null) { dt = Session[Constants.SESSION_DELIVERY_TIME].ToString(); } if (ModelState.IsValid && !dt.Equals("")) { if (cart.Items.Count() == 0) { return(RedirectToAction("Menu", "Home")); } // update db Order order = GetOrder(cart.CartID); if (Session[Constants.SESSION_DELIVERY_TIME] != null) { order.DeliveryDT = ConvertToDateTime(Session[Constants.SESSION_DELIVERY_TIME].ToString()); } foreach (var item in cart.Items) { order.AddItem(item.ProductId, item.Quantity, item.ResId == "undefined" ? null : item.ResId); } order.FeeShipping = cart.GetShippingFee(); Customer newCustomer = null; if (customer is CollectionViewModel) { CollectionViewModel c = (CollectionViewModel)customer; newCustomer = new Customer(); newCustomer.FirstName = c.FirstName; newCustomer.LastName = c.LastName; newCustomer.PhoneNo = c.ContactNo; } else if (customer is DeliveryViewModel) { var deliveryCustomer = (DeliveryViewModel)customer; newCustomer = new Customer(); newCustomer.FirstName = deliveryCustomer.FirstName; newCustomer.LastName = deliveryCustomer.LastName; newCustomer.PhoneNo = deliveryCustomer.ContactNo; newCustomer.Address1 = deliveryCustomer.Address.Replace(",", ""); newCustomer.Address1 = newCustomer.Address1.Replace("'", ""); newCustomer.Postcode = deliveryCustomer.Postcode; newCustomer.Info = deliveryCustomer.Email; } order.Customer = newCustomer; //db.Entry(order).State = System.Data.Entity.EntityState.Modified; db.Orders.Add(order); db.SaveChanges(); StringBuilder sb = new StringBuilder(); //string host = Request.Url.Host; //string appPath = Request.ApplicationPath; //string temp = host + appPath + "Paypal/Notify"; string description = ""; foreach (var item in cart.Items) { description += item.Quantity + "x" + item.Description; if (item.ResId != "") { description += " " + item.ResName; } description += "\n"; } WorldpayViewModel model = new WorldpayViewModel(); model.OrderID = "WEB" + string.Format("{0:00}", order.OrderID); model.Description = description; model.Total = cart.GetGrandTotal().ToString(); model.CustomerName = newCustomer.FullName; model.Email = newCustomer.Info; if (customer is DeliveryViewModel) { model.Address = newCustomer.Address1; model.PostCode = newCustomer.Postcode; } ViewBag.WorldpayModel = model; //sb.Append("<form id='paypalForm' action='https://select.worldpay.com/wcc/purchase' method='post'>"); //sb.Append("<input type='hidden' name='instId' value='1018224' />"); //sb.Append("<input type='hidden' name='cartId' value='WEB" + string.Format("{0:00}", order.OrderID) + "' />"); //sb.Append("<input type='hidden' name='amount' value='" + cart.GetGrandTotal() + "' />"); //sb.Append("<input type='hidden' name='currency' value='GBP' />"); //sb.Append("<input type='hidden' name='desc' value='" + description + "' />"); //sb.Append("<input type='hidden' name='testMode' value='100' />"); //sb.Append("<input type='hidden' name='MC_callback' value='http://Ns3.sbcserver.com/WorldPay/WorldPayCallback'>"); //sb.Append("<input type='hidden' name='name' value='" + customer.FullName + "' />"); //sb.Append("<input type='hidden' name='address' value='" + customer.Address1 + "' />"); //sb.Append("<input type='hidden' name='postcode' value='+" + customer.Postcode + "' />"); ////sb.Append("<input type='hidden' name='country' value='"+customer.Postcode+"' />"); ////sb.Append("<input type='hidden' name='email' value='"+customer.Email+"' />"); //sb.Append("</form>"); //cart.ClearCart(); //Session.Remove(ShoppingCart.SHOPPING_CART_SESSION); //Session.Remove("DeliveryTime"); //SessionHelper.Write(ShoppingCart.SHOPPING_CART_SESSION, new ShoppingCart()); //Session["orderType"] = ""; //return Content(sb.ToString()); //if (customer is DeliveryViewModel) //WorldpayRedirect redirect = Worldpay.ExpressCheckout(model); //return new RedirectResult(redirect.Url); return(Pay(model)); //return View("Index"); //else // return RedirectToAction("Index", "Home"); } ViewBag.State = 2; ViewBag.WorldpayModel = null; //string viewName=""; //if (Session["orderType"].ToString() == "01") // viewName = "_ForCollection"; //else if (Session["orderType"].ToString() == "02") // viewName = "_ForDelivery"; return(View("Index")); }
public ActionResult Pay(WorldpayViewModel model) { ViewBag.WorldpayModel = model; //Retrieve the InstallationID, MD5SecretKey and SiteBaseURL values from the web.config int installationID = Convert.ToInt32(WebConfigurationManager.AppSettings["InstallationID"]); string MD5secretKey = WebConfigurationManager.AppSettings["MD5secretKey"]; string WebsiteURL = WebConfigurationManager.AppSettings["WebsiteURL"]; int testMode = Convert.ToInt32(WebConfigurationManager.AppSettings["testMode"]); HostedTransactionRequest PRequest = new HostedTransactionRequest(); PRequest.instId = installationID; //amount - A decimal number giving the cost of the purchase in terms of the major currency unit e.g. 12.56 PRequest.amount = Convert.ToDouble(model.Total); //cartId - If your system has created a unique order/cart ID, enter it here. PRequest.cartId = string.Format("{0:00}", model.OrderID);//Guid.NewGuid().ToString(); //desc - enter the description for this order. PRequest.desc = model.Description; //currency - 3 letter ISO code for the currency of this payment. PRequest.currency = "GBP"; //name, address1/2/3, town, region, postcode & country - Billing address fields PRequest.name = model.CustomerName; PRequest.address1 = model.Address; //PRequest.address2 = TxtAddress2.Text; //PRequest.address3 = TxtAddress3.Text; //PRequest.town = "BKK"; //PRequest.region = TxtRegion.Text; PRequest.postcode = model.PostCode; //PRequest.country = DdlCountry.SelectedValue; ////tel - Shopper's telephone number //PRequest.tel = TxtTelephone.Text; ////fax - Shopper's fax number //PRequest.fax = TxtFax.Text; ////email - Shopper's email address PRequest.email = model.Email; ////If passing delivery details, set withDelivery = true. //PRequest.withDelivery = true; ////delvName, delvAddress1/2/3, delvTown, delvRegion, delvPostcode & delvCountry - Delivery address fields (NOTE: do not need to be passed/set if "withDelivery" set to false. PRequest.delvName = model.CustomerName; PRequest.delvAddress1 = model.Address; //PRequest.delvAddress2 = TxtdelvAddress2.Text; //PRequest.delvAddress3 = TxtdelvAddress3.Text; //PRequest.delvTown = "ABC"; //PRequest.delvRegion = TxtdelvRegion.Text; PRequest.delvPostcode = model.PostCode; //PRequest.delvCountry = DdldelvCountry.SelectedValue; //authMode - set to TransactionType.A for Authorise & Capture, set to TransactionType.E for Pre-Auth Only. PRequest.authMode = TransactionType.A; //testMode - set to 0 for Live Mode, set to 100 for Test Mode. PRequest.testMode = testMode; //hideCurrency - Set to true to hide currency drop down on the hosted payment page. PRequest.hideCurrency = false; //fixContact - Set to true to stop a shopper from changing their billing/shipping addresses on the hosted payment page. PRequest.fixContact = false; //hideContact - set to true to hide the billing/shipping address fields on the hosted payment page. PRequest.hideContact = false; //MC_callback - the URL of the Callback.aspx file. SiteBaseURL is set in the web.config file. PRequest.MC_callback = WebsiteURL + "/Payment/WorldPayCallback"; HttpContext httpa = default(HttpContext); httpa = System.Web.HttpContext.Current; HostedPaymentProcessor process = new HostedPaymentProcessor(httpa); process.SubmitTransaction(PRequest, MD5secretKey); return(View()); }