コード例 #1
0
        public void enviarmail(Entities.Model.Order order)
        {
            try
            {
                //string filename = @"C:\Users\Paul\Documents\test.txt";
                //Attachment pdfb64 = new Attachment(Convert.ToBase64String(byte[] (order.Pdf));
                //pdfb64.TransferEncoding = TransferEncoding.Base64;
                byte[] stemp  = Convert.FromBase64String(order.Pdf);
                Stream stream = new MemoryStream(stemp);

                //Attachment data = new Attachment(byte, MediaTypeNames.Application.Octet);

                SmtpClient client = new SmtpClient();
                client.Port = 587;
                // utilizamos el servidor SMTP de gmail
                client.Host                  = "smtp.gmail.com";
                client.EnableSsl             = true;
                client.Timeout               = 10000;
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                // nos autenticamos con nuestra cuenta de gmail
                client.Credentials = new NetworkCredential("*****@*****.**", "MCGA2020!");

                MailMessage mail = new MailMessage("*****@*****.**", order.CreatedBy, "Spark-Art", "Gracias por su compra. Adjunta enviamos su fatura del pedido N° " + order.Id);
                mail.Attachments.Add(new Attachment(stream, Path.GetFileName("Factura.pdf"), "application/pdf"));
                //mail.Attachments.Add(pdfb64);
                mail.BodyEncoding = UTF8Encoding.UTF8;
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                //mail.Attachments.Add(data);
                client.Send(mail);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #2
0
        public string crear_pdf(Entities.Model.Order order, List <CartItem> carrito, Shipping ship)
        {
            MemoryStream ms          = new MemoryStream();
            PdfWriter    pw          = new PdfWriter(ms);
            PdfDocument  pdfdocument = new PdfDocument(pw);
            Document     doc         = new Document(pdfdocument, PageSize.A4);

            doc.SetMargins(75, 35, 70, 35);

            //PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);

            string pathlogo = Server.MapPath("~/Content/assets/img/core-img/logo.png");

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create(pathlogo));

            //Cabecera
            iText.Layout.Element.Cell  separador = new iText.Layout.Element.Cell(1, 1);
            iText.Layout.Element.Table table     = new iText.Layout.Element.Table(2).UseAllAvailableWidth() /*.SetBorder(Border.NO_BORDER)*/;
            iText.Layout.Element.Cell  cell      = new iText.Layout.Element.Cell(4, 1).SetTextAlignment(TextAlignment.LEFT).SetBorder(Border.NO_BORDER);
            cell.Add(img.ScaleToFit(150, 150));
            table.AddCell(cell);
            cell = new iText.Layout.Element.Cell(2, 2).Add(new Paragraph("Factura No: 0177-" + string.Format("{0:00000000}", order.Id)))
                   .SetTextAlignment(TextAlignment.RIGHT)
                   .SetBorder(Border.NO_BORDER);
            table.AddCell(cell);
            cell = new iText.Layout.Element.Cell(2, 2).Add(new Paragraph("Fecha: " + DateTime.Today.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture)))
                   .SetTextAlignment(TextAlignment.RIGHT).SetBorder(Border.NO_BORDER);
            table.AddCell(cell);

            doc.Add(table);


            //Datos Cliente
            iText.Layout.Element.Table _clienttable = new iText.Layout.Element.Table(1).UseAllAvailableWidth().SetMarginTop(20) /*.SetBorder(Border.NO_BORDER)*/;
            _clienttable.AddCell(separador);
            iText.Layout.Element.Cell _clientecell = new iText.Layout.Element.Cell(1, 1);
            _clientecell.Add(new Paragraph("Nombre: " + ship.FirstName + " " + ship.LastName))
            .SetTextAlignment(TextAlignment.LEFT)
            .SetMarginBottom(10).SetBorder(Border.NO_BORDER);
            _clienttable.AddCell(_clientecell);
            _clientecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("Dirección: " + ship.Address))
                           .SetTextAlignment(TextAlignment.LEFT).SetMarginBottom(10).SetBorder(Border.NO_BORDER);

            _clienttable.AddCell(_clientecell);
            _clientecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("Ciudad: " + ship.City))
                           .SetTextAlignment(TextAlignment.LEFT).SetMarginBottom(10).SetBorder(Border.NO_BORDER);
            _clienttable.AddCell(_clientecell);
            _clientecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("País: " + ship.Country))
                           .SetTextAlignment(TextAlignment.LEFT).SetMarginBottom(10).SetBorder(Border.NO_BORDER);
            _clienttable.AddCell(_clientecell);
            _clientecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("Email: " + ship.Email))
                           .SetTextAlignment(TextAlignment.LEFT).SetMarginBottom(10).SetBorder(Border.NO_BORDER);
            _clienttable.AddCell(_clientecell);
            _clienttable.AddCell(separador);
            doc.Add(_clienttable);


            //doc.Add(ls);
            //Datos Product Encabezado
            iText.Layout.Element.Table _prodtable = new iText.Layout.Element.Table(6).UseAllAvailableWidth().SetMarginTop(20) /*.SetBorder(Border.NO_BORDER)*/;

            iText.Layout.Element.Cell _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("# Item"))
                                                   .SetTextAlignment(TextAlignment.CENTER)
                                                   .SetMarginBottom(10);
            _prodtable.AddCell(_prodecell);
            _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("Codigo Articulo"))
                         .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
            _prodtable.AddCell(_prodecell);
            _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("Descripcion"))
                         .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
            _prodtable.AddCell(_prodecell);
            _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("Precio Unitario"))
                         .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
            _prodtable.AddCell(_prodecell);
            _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("Cantidad"))
                         .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
            _prodtable.AddCell(_prodecell);
            _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("Subtotal"))
                         .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
            _prodtable.AddCell(_prodecell);

            int x = 0;

            foreach (CartItem item in carrito)
            {
                x++;
                _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph(x.ToString())).SetBorder(Border.NO_BORDER)
                             .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
                _prodtable.AddCell(_prodecell);
                _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph(item.ProductId.ToString())).SetBorder(Border.NO_BORDER)
                             .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
                _prodtable.AddCell(_prodecell);
                _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph(item.Product.Title.ToString())).SetBorder(Border.NO_BORDER)
                             .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
                _prodtable.AddCell(_prodecell);
                _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph(item.Price.ToString())).SetBorder(Border.NO_BORDER)
                             .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
                _prodtable.AddCell(_prodecell);
                _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph(item.Quantity.ToString())).SetBorder(Border.NO_BORDER)
                             .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
                _prodtable.AddCell(_prodecell);
                _prodecell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph((item.Quantity * item.Price).ToString())).SetBorder(Border.NO_BORDER)
                             .SetTextAlignment(TextAlignment.CENTER).SetMarginBottom(10);
                _prodtable.AddCell(_prodecell);
            }
            doc.Add(_prodtable);

            //Total
            iText.Layout.Element.Table totaltable = new iText.Layout.Element.Table(1).UseAllAvailableWidth().SetMarginTop(20) /*.SetBorder(Border.NO_BORDER)*/;

            iText.Layout.Element.Cell totalcell = new iText.Layout.Element.Cell(1, 1).Add(new Paragraph("Total: $" + order.TotalPrice))
                                                  .SetTextAlignment(TextAlignment.RIGHT)
                                                  .SetMarginBottom(10).SetBorder(Border.NO_BORDER);
            totaltable.AddCell(totalcell);
            doc.Add(totaltable);
            //pdfdocument.AddEventHandler(PdfDocumentEvent.END_PAGE, new HeaderEventHandler1(img));

            //iText.Layout.Element.Table _table = new iText.Layout.Element.Table(1).UseAllAvailableWidth();

            doc.Close();

            byte[] byteStream    = ms.ToArray();
            var    inputAsString = Convert.ToString(Convert.ToBase64String(ms.ToArray()));

            ms = new MemoryStream();
            ms.Write(byteStream, 0, byteStream.Length);
            ms.Position = 0;
            var pdf = new FileStreamResult(ms, "application/pdf");

            /*return new FileStreamResult(ms, "application/pdf")*/;

            return(inputAsString.ToString());
        }
コード例 #3
0
        public ActionResult procesar_pago(FormCollection Request)
        {
            var token             = Request["token"].Split(',')[0];
            var payment_method_id = Request["payment_method_id"].Split(',')[0];
            var installments      = Request["installments"].Split(',')[0];
            var issuer_id         = Request["issuer_id"].Split(',')[0];

            if (MercadoPago.SDK.AccessToken == null)
            {
                MercadoPago.SDK.SetAccessToken("TEST-6196665787772204-120903-7e3696caa9ad7207eae686fc4d423f53-684823230");
            }
            var carrito      = cartprocess.GetByCookie(User.Identity.Name);
            var listadoitems = itemsprocess.GetByCartId(carrito.Id);
            var Total        = sum_items(listadoitems);
            //MercadoPago.SDK.SetAccessToken(token);
            Payment payment = new Payment();


            payment.TransactionAmount = (float)Total;
            payment.Token             = token;
            payment.Description       = "Spark-Art";
            payment.Installments      = int.Parse(installments); //Convert.ToInt32(installments);
            payment.PaymentMethodId   = payment_method_id;
            payment.IssuerId          = issuer_id;
            payment.Payer             = new MercadoPago.DataStructures.Payment.Payer()
            {
                Email = "*****@*****.**"
            };
            var payret = payment.Save();

            ViewBag.Confirmacion = (payment.Status);
            ViewBag.Cuotas       = payment.Installments;
            ViewBag.Monto        = payment.TransactionAmount;

            //Impacto y creacion de la orden y lineas de orden
            Entities.Model.Order order = new Entities.Model.Order();
            CheckAuditPattern(order, true);
            var ship = shippingprocess.GetByCookie(User.Identity.Name);

            order.ShippingId = ship.Id;
            order.Email      = User.Identity.Name;
            order.OrderDate  = DateTime.Now;
            order.TotalPrice = Total;
            order.ItemCount  = carrito.CartItem.Count();
            order            = orderprocess.AgregarOrder(order);
            var pdf = crear_pdf(order, listadoitems, ship);

            order.Pdf = pdf;
            orderprocess.EditarOrder(order);
            enviarmail(order);
            ViewBag.items = listadoitems;
            ViewBag.pago  = payment;
            foreach (CartItem item in listadoitems)
            {
                OrderDetail orderdetail = new OrderDetail();
                CheckAuditPattern(orderdetail, true);
                orderdetail.OrderId   = order.Id;
                orderdetail.ProductId = item.ProductId;
                orderdetail.Price     = item.Price;
                orderdetail.Quantity  = item.Quantity;
                orderprocess.AgregarLinea(orderdetail);
                itemsprocess.EliminarCartItem(item.Id);
            }
            cartprocess.EliminarCart(carrito);

            ViewBag.items = listadoitems;

            return(View("procesar_pago", order));
        }