public async Task SendMail()
        {
            string wNumOrder = "12365";
            UserBL userBL    = new UserBL();

            userBL.SetGoogleCedential();
            var    appSettings = ConfigurationManager.AppSettings;
            string wUrlPDF     = appSettings["UlrPDF"];
            bool   sendEmail   = false;

            try
            {
                FileStream wPFD = ManagementDocument.CreateOrderDocument(wUrlPDF, wNumOrder, await new CartBL().GetCartByUser("asfffkjoqejf9f"),
                                                                         null);
                //invio Mail


                string wEmail   = "*****@*****.**";
                string wName    = "fede";
                string wsurname = "fede";

                sendEmail = MailManagment.SendEmail(wPFD.Name, wEmail, wName, wsurname);
            }
            catch (Exception ex)
            {
                Assert.Fail();
            }

            Assert.IsTrue(sendEmail);
        }
Ejemplo n.º 2
0
        public async void SendMail(string pUrlPDF, string pNumOrder, string pIdUser)
        {
            FileStream wPFD = ManagementDocument.CreateOrderDocument(pUrlPDF, pNumOrder, await new CartBL().GetCartByUser(pIdUser),
                                                                     await new UserBL().SigIn(pIdUser));

            //invio Mail
            try
            {
                MailManagment.SendEmail(wPFD.Name, wLogUser);
            }
            catch (Exception ex)
            {
                Log.Error("Errore durante l'invio della mail.", ex);
            }
            return("value");
        }
Ejemplo n.º 3
0
        public async void SendMail(string pNumOrder, string pIdUser)
        {
            var    appSettings = ConfigurationManager.AppSettings;
            string wUrlPDF     = appSettings["UlrPDF"];

            Log.Info("REST:Scrittura PDF per ordine " + pNumOrder);
            User       wUser = await new UserBL().GetUser(pIdUser);
            FileStream wPFD  = ManagementDocument.CreateOrderDocument(wUrlPDF, pNumOrder, await new CartBL().GetCartByUser(pIdUser),
                                                                      wUser);

            //invio Mail
            try
            {
                Log.Info("REST:Tentativo invio mail per ordine " + pNumOrder);
                MailManagment.SendEmail(wPFD.Name, wUser.email, wUser.nome, wUser.cognome);
            }
            catch (Exception ex)
            {
                Log.Error("REST:Errore durante l'invio della mail.", ex);
            }
        }
        public async Task <ActionResult> PaymentWithPaypal(string userId, string Cancel = null)
        {
            //getting the apiContext
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            wLogUser = (LoggedUser)Session["CurrentUser"];
            Cart wCart = null;

            try
            {
                //A resource representing a Payer that funds a payment Payment Method as paypal
                //Payer Id will be returned when payment proceeds or click to pay
                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.
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority +
                                     "/Cart/PaymentWithPayPal?";

                    //here we are generating guid for storing the paymentID received in session
                    //which will be 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
                    wCart = ConvertEntityUserTOUserModel.ConvertoCartEntityTOCartModel(await new CartBL().GetCartByUser(wLogUser.wDetailUser.Id));

                    if (wCart.DetailsCart.Count == 0)
                    {
                        ViewBag.ErrorMessage = "Non sono presenti articoli nel carrello";
                        wCart.UserOwner      = wLogUser.wDetailUser;
                        return(View("Details", wCart));
                    }
                    wCart.NumOrder      = new CartBL().GenerateNumOrder();
                    Session["NumOrder"] = wCart.NumOrder;
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid, wCart);

                    //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(Redirect(paypalRedirectUrl));
                }
                else
                {
                    // This function exectues after receving all parameters for the payment

                    var guid = Request.Params["guid"];

                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);

                    //If executed payment failed then we will show payment failure message to user
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("FailureView"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(View("FailureView"));
            }


            //on successful payment, show success page to user.
            wLogUser = (LoggedUser)Session["CurrentUser"];
            string wNumOrder = Session["NumOrder"] != null ? Session["NumOrder"].ToString() : "";

            //scrittura pdf di conferma acquisto
            Log.Info("Scrittura PDF per ordine " + wNumOrder);
            var        appSettings = ConfigurationManager.AppSettings;
            string     wUrlPDF     = appSettings["UlrPDF"];
            FileStream wPFD        = ManagementDocument.CreateOrderDocument(wUrlPDF, wNumOrder, await new CartBL().GetCartByUser(wLogUser.wDetailUser.Id),
                                                                            ConvertEntityUserTOUserModel.ConvertoUserEntityTOUserModel(wLogUser.wDetailUser));

            //invio Mail
            try
            {
                Log.Info("Tentativo invio mail per ordine " + wNumOrder);
                MailManagment.SendEmail(wPFD.Name, wLogUser.Email, wLogUser.wDetailUser.Name, wLogUser.wDetailUser.Surname);
            }
            catch (Exception ex)
            {
                Log.Error("Errore durante l'invio della mail.", ex);
            }

            try
            {
                //creo lo storico dell'ordine
                Log.Info("Scrittura Storico per ordine " + wNumOrder + " dell'utente " + wLogUser.Id);
                await new CartBL().AddHistoryBuy(wLogUser.wDetailUser.Id, wNumOrder);
            }
            catch (Exception ex)
            {
                Log.Error("Errore durante la scrittura dello storico ordine.", ex);
            }
            return(View("SuccessView"));
        }