//Paypal payment public ActionResult PaymentWithPaypal(List <string> data) { OrderId = DateTime.Now.ToString("ddmmyyyyhhmmss"); //getting the apiContext as earlier APIContext apiContext = PaymentConfiguration.GetAPIContext(); try { string payerId = Request.Params["PayerID"]; if (string.IsNullOrEmpty(payerId)) { //this section will be executed first because PayerID doesn't exist //it is returned by the create function call of the payment class // Creating a payment // baseURL is the url on which paypal sendsback the data. // So we have provided URL of this controller only string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Paypal/PaymentWithPayPal?"; //guid we are generating for storing the paymentID received in session //after calling the create function and it is used in the payment execution var guid = Convert.ToString((new Random()).Next(100000)); //CreatePayment function gives us the payment approval url //on which payer is redirected for paypal account payment //var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid); var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid, data); //get links returned from paypal in response to Create function call var links = createdPayment.links.GetEnumerator(); string paypalRedirectUrl = null; while (links.MoveNext()) { Links lnk = links.Current; if (lnk.rel.ToLower().Trim().Equals("approval_url")) { //saving the payapalredirect URL to which user will be redirected for payment paypalRedirectUrl = lnk.href; } } // saving the paymentID in the key guid Session.Add(guid, createdPayment.id); return(Json(new { data = paypalRedirectUrl }, JsonRequestBehavior.AllowGet)); } else { // This section is executed when we have received all the payments parameters // from the previous call to the function Create // Executing a payment var guid = Request.Params["guid"]; var orderid = Request.Params["OrionOrderId"]; var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string); if (executedPayment.state.ToLower() != "approved") { return(RedirectToAction("FailureView", "Paypal", new { area = "Shopping" })); } var payment = Payment.Get(apiContext, Session[guid].ToString()); string city = payment.transactions[0].item_list.shipping_address.city; string postalcode = payment.transactions[0].item_list.shipping_address.postal_code; string countryCode = payment.transactions[0].item_list.shipping_address.country_code; string recipentName = payment.transactions[0].item_list.shipping_address.recipient_name; string state = payment.transactions[0].item_list.shipping_address.state; string street = payment.transactions[0].item_list.shipping_address.line1; StringBuilder sb = new StringBuilder(); sb.Append("Recipient name: "); sb.Append(recipentName); sb.Append(Environment.NewLine); sb.Append("Address: "); sb.Append(street); sb.Append(Environment.NewLine); sb.Append("City: "); sb.Append(city); sb.Append(Environment.NewLine); sb.Append("State: "); sb.Append(state); sb.Append(Environment.NewLine); sb.Append("Postal code: "); sb.Append(postalcode); sb.Append(Environment.NewLine); sb.Append("Country code: "); sb.Append(countryCode); sb.Append(Environment.NewLine); string ShippingAddress = sb.ToString(); //update order after recievining parameters from paypal db_AirborneEntities OEM = new db_AirborneEntities(); var updatePayment = OEM.Order_Payments.Where(x => x.OrderID != null && x.OrderID == orderid).FirstOrDefault(); if (updatePayment != null) { TempData["Status"] = updatePayment.OrderID; updatePayment.ShippingAddress = ShippingAddress; updatePayment.RecipientName = recipentName ?? ""; updatePayment.Street = street ?? ""; updatePayment.City = city ?? ""; updatePayment.State = state ?? ""; updatePayment.PostalCode = postalcode ?? ""; updatePayment.CountryCode = countryCode ?? ""; updatePayment.Status = "1"; updatePayment.ModifiedDate = DateTime.UtcNow; updatePayment.PaypalTransactionID = Convert.ToString(Session[guid]); OEM.SaveChanges(); } var emailStatus = HtmlHelpersUtility.SendOrderEmail(updatePayment.OrderID, updatePayment.Email); } } catch (Exception ex) { log4net.ILog logger = log4net.LogManager.GetLogger("Errorlog"); logger.Error("Error" + ex.Message); //Logger.log("Error" + ex.Message); return(RedirectToAction("FailureView", "Paypal", new { area = "Shopping" })); } return(RedirectToAction("SuccessView", "Paypal", new { area = "Shopping" })); }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); //if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) if (user == null) { // Don't reveal that the user does not exist or is not confirmed return(View("ForgotPasswordConfirmation")); } // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // MailMessage mail = new MailMessage(); mail.To.Add(model.Email);//Change ToAdmin from web.config (All the emails are sending to site admin) mail.From = new MailAddress(WebConfigurationManager.AppSettings["ToAdmin"]); mail.Subject = "Reset Password"; Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("#email#", model.Email); parameters.Add("#Comments#", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); string template = HtmlHelpersUtility.GetDocumentText("ForgotPasswordMail.html"); foreach (KeyValuePair <string, string> item in parameters) { template = template.Replace(item.Key, item.Value); } mail.Body = template; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = WebConfigurationManager.AppSettings["host"]; //Change host from web.config smtp.Port = Convert.ToInt32(WebConfigurationManager.AppSettings["port"]); //Change port from web.config smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential(WebConfigurationManager.AppSettings["userName"], WebConfigurationManager.AppSettings["password"]); // change senders User name and password from web.config smtp.EnableSsl = Convert.ToBoolean(WebConfigurationManager.AppSettings["enableSsl"]); //Change ssl setting from web.config smtp.Send(mail); //await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("ForgotPasswordConfirmation", "Account")); // ModelState.AddModelError("", "The user either does not exist or is not confirmed."); // return View(); // } // // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // // Send an email with this link // // string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); // // var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // // await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); // // return RedirectToAction("ForgotPasswordConfirmation", "Account"); //} //// If we got this far, something failed, redisplay form //return View(model); } return(View(model)); }