// // GET: /CCForm/ // public ActionResult CCForm(string pname) { //int productId = ParseProductId(pid); var products = GetAllProducts(); var productData = GetProductDataById(pname); var productItem = products.Find(m => m.ProductName == pname); if (productItem == null) { AddModelError(ErrorType.ProductNotExist); return View("Error"); } CCFormModel model = new CCFormModel(); //var model = PaymentInfoObj.Obj.ToBillingFormModel<CCFormModel>(); model.Product = productItem; Session["BillingModel"] = model; return View(model); }
public ActionResult Paypal(CCFormModel model) { if (ModelState.IsValid) { try { Session["method"] = "Paypal"; var productData = GetProductDataById(model.Product.ProductName); var data = productData.Find(m => m.ProductTermId == model.ProductTermsId); setProfile(); string url = Request.Url.Scheme + "://" + Request.UrlReferrer.Host + ":" + Request.UrlReferrer.Port + @"/"; string cancelURL = url + "?pname=" + model.Product.ProductName; com.paypal.sdk.services.NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize(); NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "SetExpressCheckout"; encoder["CANCELURL"] = cancelURL; encoder["PAYMENTACTION"] = ConfigurationManager.AppSettings["paymentType"]; encoder["CURRENCYCODE"] = ConfigurationManager.AppSettings["currency"]; encoder["L_NAME0"] = model.ProductTermsId; encoder["L_DESC0"] = "Inywhere payment"; encoder["L_AMT0"] = data.Amount.ToString(); decimal ft = data.Amount; encoder["ITEMAMT"] = ft.ToString(); encoder["AMT"] = ft.ToString(); if (url.Contains("inywhere")) url += "payment/"; string returnURL = url + "BillingForm/Paypal"; encoder["RETURNURL"] = returnURL; encoder["NOSHIPING"] = "1"; encoder["REQCONFIRMSHIPPING"] = "0"; string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = caller.Call(pStrrequestforNvp); NVPCodec decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"]; if (strAck != null && (strAck == "Success" || strAck == "SuccessWithWarning")) { Session["BillingModel"] = model; ViewData["ProductData"] = productData; Session["TOKEN"] = decoder["TOKEN"]; string host = "www." + Session["stage"].ToString() + ".paypal.com"; string ECURL = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + decoder["TOKEN"]; Response.Redirect(ECURL); return View("OrderSummary", model); } else { LogHelper.Instance.Fatal(decoder["L_LONGMESSAGE0"]); AddModelError(ErrorType.TransactionProcessError); return View(model); } } catch (Exception ex) { LogHelper.Instance.Fatal("Inywhere account service is not avaliable."); AddModelError(ErrorType.ServiceError); return View("Error"); } } return View(model); }
public ActionResult Card(CCFormModel model) { if (ModelState.IsValid) { if (CreditCardUtility.IsValidNumber(model.CardNum)) { try { Session["method"] = "Card"; var productData = GetProductDataById(model.Product.ProductName); Session["BillingModel"] = model; ViewData["ProductData"] = productData; return View("OrderSummary", model); } catch (Exception ex) { LogHelper.Instance.Fatal("Inywhere account service is not avaliable."); AddModelError(ErrorType.ServiceError); return View("Error"); } } else { AddModelError(ErrorType.InvalidCardNumber); ModelState.AddModelError("CardNum", "Invalid card num."); return View(model); } } return View(model); }