public string DownloadApplicationPDF_Friend(EmailModelAttachment EMA)
        {
            try
            {
                if (System.IO.File.Exists(EMA.FileURL))
                {
                    System.IO.File.Delete(EMA.FileURL);
                }
                string strInvoiceComReceipt = string.Empty;
                System.IO.StreamReader strReader;
                strReader            = System.IO.File.OpenText(System.Web.HttpContext.Current.Server.MapPath(@"/FriendsInvoice.html"));
                strInvoiceComReceipt = strReader.ReadToEnd();
                strReader.Close();
                strReader.Dispose();
                strInvoiceComReceipt = strInvoiceComReceipt.Replace("TodayDate", DateTime.Now.ToString("MM/dd/yyyy"));
                strInvoiceComReceipt = strInvoiceComReceipt.Replace("CustomerName", EMA.CustomerName);
                strInvoiceComReceipt = strInvoiceComReceipt.Replace("FriendNotification", EMA.FriendsHTML);
                strInvoiceComReceipt = strInvoiceComReceipt.Replace("includingGST", EMA.includingGST);
                strInvoiceComReceipt = strInvoiceComReceipt.Replace("TotalAmount", EMA.TotalAmount);

                string htmlContent1 = strInvoiceComReceipt;
                string path         = System.Web.HttpContext.Current.Server.MapPath(@"/FriendInvoice/" + EMA.PayPalPaymentId + ".pdf");

                byte[] pdfBytes = (new NReco.PdfGenerator.HtmlToPdfConverter()).GeneratePdf(htmlContent1);
                System.IO.File.WriteAllBytes(path, pdfBytes);
                return("File Saved in Friend Inovice Folder");
            }

            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        public string SendEmailWithAttachment(EmailModelAttachment EMA)
        {
            string Result = "";

            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(EMA.ToEmail);
                mail.Subject = EMA.Subject;
                mail.Body    = "Hi " + EMA.CustomerName + ", Please find attached the Invoice.";
                Attachment at = new Attachment(HttpContext.Current.Server.MapPath(EMA.FileURL));
                mail.Attachments.Add(at);
                SmtpServer.Port        = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "testifiedpassword@hackfree");
                SmtpServer.EnableSsl   = true;
                SmtpServer.Send(mail);
                Result = "Ok";
            }
            catch (Exception ex)
            {
                Result = Convert.ToString(ex);
            }
            return(Result);
        }
        public string TestInovice(string Paymentid)
        {
            EmailModelAttachment tm = new EmailModelAttachment();
            var GetUserdetail       = _objFriendFitDBEntity.UserProfiles.Where(x => x.Id == 44).FirstOrDefault();

            tm.ToEmail = "*****@*****.**";
            if (GetUserdetail.LastName != null)
            {
                tm.CustomerName = GetUserdetail.FirstName + ' ' + GetUserdetail.LastName;
            }
            else
            {
                tm.CustomerName = GetUserdetail.FirstName;
            }
            tm.PayPalPaymentId = Paymentid;
            // tm.messagebody = "Hi " + GetUserdetail.FirstName;
            tm.Subject     = "Notifit Inovice";
            tm.FileURL     = "~/Invoice/" + Paymentid + ".pdf";
            tm.messagebody = _objIinvoiceRepository.DownloadApplicationPDF(tm);
            var SMSStatus = _objIinvoiceRepository.SendEmailWithAttachment(tm);

            return(SMSStatus);
        }
Example #4
0
        public string GetPaymentDetails(string paymentID)
        {
            var    apiContext      = PayPalConfiguration.GetAPIContext();
            var    payment         = new Payment();
            string str_payment     = "";
            string Result          = "";
            string FileSavedResult = "";

            try
            {
                payment = Payment.Get(apiContext, paymentID);
                FriendFit.Data.Payment tbl_payment = new FriendFit.Data.Payment();

                var payPalPaymentIdExist = _objFriendFitDBEntity.Payments.Where(s => s.PaypalId == payment.id).FirstOrDefault();

                if (payPalPaymentIdExist == null)
                {
                    if (payment.state == "created")
                    {
                        //  var GetPay
                        str_payment = "Payment success";

                        tbl_payment.PaypalId                = payment.id;
                        tbl_payment.Intent                  = payment.intent;
                        tbl_payment.Cart                    = payment.cart;
                        tbl_payment.State                   = payment.state;
                        tbl_payment.Create_time             = payment.create_time;
                        tbl_payment.Update_time             = payment.update_time;
                        tbl_payment.Payer_PaymentMethod     = payment.payer.payment_method;
                        tbl_payment.Status                  = payment.payer.status;
                        tbl_payment.Payer_info_Email        = payment.payer.payer_info.email;
                        tbl_payment.Payer_info_FirstName    = payment.payer.payer_info.first_name;
                        tbl_payment.Payer_info_LastName     = payment.payer.payer_info.last_name;
                        tbl_payment.Payer_info_Payer_Id     = payment.payer.payer_info.payer_id;
                        tbl_payment.Payer_info_Country_Code = payment.payer.payer_info.country_code;
                        //tbl_payment. = payment.payer.payer_info.country_code;

                        tbl_payment.Shipping_Address_Recipient_Name = payment.payer.payer_info.shipping_address.recipient_name;
                        tbl_payment.Shipping_Address_Line1          = payment.payer.payer_info.shipping_address.line1;
                        tbl_payment.Shipping_Address_Line2          = payment.payer.payer_info.shipping_address.line2;
                        tbl_payment.Shipping_Address_City           = payment.payer.payer_info.shipping_address.city;
                        tbl_payment.Shipping_Address_Country_Code   = payment.payer.payer_info.shipping_address.country_code;
                        tbl_payment.Shipping_Address_PostedCode     = payment.payer.payer_info.shipping_address.postal_code;
                        tbl_payment.Shipping_Address_State          = payment.payer.payer_info.shipping_address.state;

                        tbl_payment.Transactions_Description = payment.transactions[0].description;
                        tbl_payment.Transactions_InvoiceNum  = payment.transactions[0].invoice_number;
                        tbl_payment.RowInsert = DateTime.UtcNow;
                        tbl_payment.UserId    = Convert.ToInt32(payment.transactions[0].description);

                        _objFriendFitDBEntity.Payments.Add(tbl_payment);
                        _objFriendFitDBEntity.SaveChanges();

                        foreach (var item in payment.transactions)
                        {
                            int   payid  = _objFriendFitDBEntity.Payments.Where(x => x.PaypalId == payment.id).FirstOrDefault().Id;
                            Int64 newsku = 0;
                            foreach (var item_ in item.item_list.items)
                            {
                                FriendFit.Data.PurchaseProductsList pr = new FriendFit.Data.PurchaseProductsList();
                                pr.PaymentId = payid;
                                pr.SKU       = item_.sku;
                                pr.Name      = item_.name;
                                pr.Quantity  = item_.quantity;
                                pr.Price     = item_.price;
                                pr.Currency  = item_.currency;
                                pr.RowInsert = DateTime.UtcNow;
                                _objFriendFitDBEntity.PurchaseProductsLists.Add(pr);
                                _objFriendFitDBEntity.SaveChanges();
                                newsku = Convert.ToInt64(item_.sku);

                                var IsPaymentDone = _objFriendFitDBEntity.FriendsInvitations.Where(x => x.Id == newsku).FirstOrDefault();
                                if (IsPaymentDone != null)
                                {
                                    IsPaymentDone.IsActive    = true;
                                    IsPaymentDone.IsRowActive = true;
                                    IsPaymentDone.PaymentDone = 1;
                                    _objFriendFitDBEntity.Entry(IsPaymentDone).State = EntityState.Modified;
                                    _objFriendFitDBEntity.SaveChanges();
                                }
                                ;
                            }
                        }

                        //-------------------------for Inovice
                        int PaymentRowId       = _objFriendFitDBEntity.Payments.Where(x => x.PaypalId == payment.id).FirstOrDefault().Id;
                        var GetAllRows_Payment = _objFriendFitDBEntity.PurchaseProductsLists.Where(x => x.PaymentId == PaymentRowId).ToList();

                        string FriendsHTML      = "";
                        EmailModelAttachment tm = new EmailModelAttachment();
                        var     GetUserdetail   = _objFriendFitDBEntity.UserProfiles.Where(a => a.Id == tbl_payment.UserId).FirstOrDefault();
                        decimal TotalAmt        = 0;
                        foreach (var Payment_item in GetAllRows_Payment)
                        {
                            long id        = Convert.ToInt64(Payment_item.SKU);
                            var  GetuserId = _objFriendFitDBEntity.FriendsInvitations.Where(x => x.Id == id).FirstOrDefault();

                            tm.IsSMS = _objFriendFitDBEntity.DeliveryTypeMasters.Where(x => x.Id == GetuserId.DeliveryTypeId).FirstOrDefault().Name;
                            tm.Isrecurringmonthly = _objFriendFitDBEntity.SubscriptionTypeMasters.Where(x => x.Id == GetuserId.SubscriptionTypeId).FirstOrDefault().SubcriptionType;
                            tm.ProductAmount      = Convert.ToString(GetuserId.Cost.Value.ToString("0.00"));
                            FriendsHTML          += "<tr><td>Workout reminders via NotiFit app notifications to Friend " + GetuserId.FriendsName + "(" + tm.Isrecurringmonthly + " payment expiring " + GetuserId.ExpiryDate.Value.ToString("MM/dd/yyyy") + ")</td><td>$" + GetuserId.Cost.Value.ToString("0.00") + "</td></tr>";
                            TotalAmt += Convert.ToDecimal(GetuserId.Cost.Value.ToString("0.00"));
                        }

                        tm.ToEmail     = GetUserdetail.Email;
                        tm.FriendsHTML = FriendsHTML;
                        if (GetUserdetail.LastName != null)
                        {
                            tm.CustomerName = GetUserdetail.FirstName + ' ' + GetUserdetail.LastName;
                        }
                        else
                        {
                            tm.CustomerName = GetUserdetail.FirstName;
                        }

                        tm.PayPalPaymentId = payment.id;
                        tm.Subject         = "Notifit Friend Inovice";
                        tm.FileURL         = "/FriendInvoice/" + payment.id + ".pdf";

                        if (GetUserdetail.CountryId == 61)
                        {
                            tm.includingGST = "Total price in USD including GST";
                        }
                        else
                        {
                            tm.includingGST = "Total price in USD ";
                        }

                        tm.TotalAmount  = Convert.ToString(TotalAmt);
                        FileSavedResult = Inovoice.DownloadApplicationPDF_Friend(tm);
                        Result          = Inovoice.SendEmailWithAttachment(tm);
                    }
                    else
                    {
                        str_payment = "Payment Fail !";
                    }
                }

                else
                {
                    str_payment = "Payment Id already exists";
                }
            }
            catch (PaymentsException ex)
            {
                //throw new Exception("Sorry there is an error getting the payment details. " + ex.Response);
                str_payment = "Sorry there is an error getting the payment details. " + ex.Response;
            }
            return(str_payment + "------" + FileSavedResult + "-------------" + Result);
        }