Exemplo n.º 1
0
 public ActionResult PaymentWithPaypal(BuyingVM buyingVM, string Cancel = null)
 {
     //getting the apiContext
     PayPal.Api.APIContext apiContext = PaypalConfiguration.GetAPIContext();
     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 + "/ReportBuying/PaymentSuccess?";
             //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
             var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + buyingVM.GuId, buyingVM);
             //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);
             Response.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.
     return(View("SuccessView"));
 }
Exemplo n.º 2
0
        public string GenerateMailBody_PaymentMade(string PaymentSucess, BuyingVM userdata)
        {
            string result = "";

            //result = "Dear Admin, Payment made for <br /><br />" + "<table>";
            result  = PaymentSucess + "<table>";
            result += userdata.ReportTitle != "" ? "<tr> <td valign='top' width='30%'><b>Report Title</b></td>   <td valign='top' width='2%'><b> : </b></td> <td valign='top' width='68%'>" + userdata.ReportTitle + "</td> </tr>" : "";
            result += userdata.Name != "" ? "<tr> <td valign='top'><b>Customer Name</b></td>  <td valign='top'><b> : </b></td> <td valign='top'>" + userdata.Name + "</td> </tr>" : "";
            result += userdata.EmailId != "" ? "<tr> <td valign='top'><b>Email ID</b></td>       <td valign='top'><b> : </b></td> <td valign='top'>" + userdata.EmailId + "</td> </tr>" : "";
            result += userdata.PhoneNumber != "" ? "<tr> <td valign='top'><b>Phone</b></td>          <td valign='top'><b> : </b></td> <td valign='top'>" + userdata.PhoneNumber + "</td> </tr>" : "";
            result += userdata.Company != "" ? "<tr> <td valign='top'><b>Company Name</b></td>   <td valign='top'><b> : </b></td> <td valign='top'>" + userdata.Company + "</td> </tr>" : "";
            result += userdata.Designation != "" ? "<tr> <td valign='top'><b>Designation</b></td>    <td valign='top'><b> : </b></td> <td valign='top'>" + userdata.Designation + "</td> </tr>" : "";
            result += userdata.Country != "" ? "<tr> <td valign='top'><b>Country Name</b></td>   <td valign='top'><b> : </b></td> <td valign='top'>" + userdata.Country + "</td> </tr>" : "";
            //result += txtComment.Text.Trim() != "" ? "<tr> <td valign='top'><b>Enquiry Text</b></td>   <td valign='top'><b> : </b></td> <td valign='top'>" + txtComment.Text.Trim() + "</td> </tr>" : "";
            result += "<tr> <td valign='top'><b>IP Address</b></td>     <td valign='top'><b> : </b></td> <td valign='top'>" + userdata.IPAddress + "</td> </tr>";
            result += "</table>";
            return(result);
        }
Exemplo n.º 3
0
        public static void _PayPal(BuyingVM buynow)
        {
            PayPalConfig config = PayPalConfig.GetConfiguration(HttpContext.Current.Server.MapPath("~/paypalconfig/paypal.config"));

            config.guid = buynow.GuId;
            List <PaymentLibrary.PayPal.Item> items = new List <PaymentLibrary.PayPal.Item>();

            //foreach (OrderSummary orderSummary in buynow.OrderSummary)
            //{
            //    //if price is not set or null then do not add to order summary
            //    if (orderSummary.Price == null)
            //        continue;

            //    PaymentLibrary.PayPal.Item itm = new PaymentLibrary.PayPal.Item();
            //    itm.Name = orderSummary.ReportTitle.ZSubstring(0, 20);
            //    itm.Quantity = orderSummary.Quantity;
            //    itm.Price = orderSummary.Price;
            //    items.Add(itm);
            //}

            items.Add(new Item
            {
                Name     = buynow.ReportTitle.Length > 20 ? buynow.ReportTitle.Substring(0, 20) : buynow.ReportTitle,
                Quantity = 1,
                Price    = buynow.Price
            });

            // PaymentLibrary.PayPal.Token tkn = PaymentLibrary.PayPal.PayPal.GetToken(config, items, true);
            PaymentLibrary.PayPal.Token tkn = GetToken(config, items, true);

            if (!string.IsNullOrEmpty(tkn.L_ERRORCODE0))
            {
                log4net.LogManager.GetLogger("Error").Error("Error at SaveBuynowDetails. PayPal \nErrorCode - " + tkn.L_ERRORCODE0 + "\nError Message - " + tkn.L_SHORTMESSAGE0 + "\n" + tkn.L_LONGMESSAGE0 + "\nFull Data - " + Newtonsoft.Json.JsonConvert.SerializeObject(buynow));
                //return new Utility.Message { MessageText = tkn.L_LONGMESSAGE0 };
            }

            PaymentLibrary.PayPal.PayPal.RedirectUser(tkn);

            // return new Utility.Message { MessageText = "Payment Initiated" };
        }
Exemplo n.º 4
0
        public ActionResult CheckoutForm(int reportid, string buynow)
        {
            if (reportid.ToString() != null && (!string.IsNullOrEmpty(buynow)))
            {
                BuyingVM ObjBuy = new BuyingVM();


                ObjBuy.ReportId = reportid;

                var report = (from l in db.ReportMasters
                              where l.ReportId == reportid
                              select l).FirstOrDefault();
                ObjBuy.ReportTitle = report.ReportTitle;
                ObjBuy.ReportUrl   = report.ReportUrl;
                ObjBuy.Type        = buynow == "0" ? "Single User" : buynow == "1" ? "Multi User" : "Corporate User";
                ObjBuy.Price       = (decimal)(buynow == "0" ? report.SinglePrice : (buynow == "1" ? report.MultiUserPrice : report.CorporateUserPrice));

                return(View(ObjBuy));
            }
            else
            {
                return(RedirectToAction("ReportDetail", "ReportsCollection"));
            }
        }
Exemplo n.º 5
0
        public ActionResult CheckoutForm(BuyingVM ObjBuy)
        {
            //  var MailbodyMethodCall = new QYGroupRepository.PaymentGateway.Emailsending();

            if (ModelState.IsValid)
            {
                string realCaptcha = Session["Captchacode"].ToString();
                string Publisher   = string.Empty;
                if (ObjBuy.ReportId > 0)
                {
                    var publish = (from l in db.ReportMasters
                                   join p in db.PublisherMasters on l.PublishereId equals p.PublisherId
                                   where l.ReportId == ObjBuy.ReportId
                                   select p).FirstOrDefault();
                    Publisher = publish.PublisherName;
                }
                if (ObjBuy.CaptchaCode == realCaptcha)
                {
                    //JavaScriptSerializer serializer = new JavaScriptSerializer();
                    //var s = serializer.Serialize(Enquiredata);
                    //BuyingInfo cst = serializer.Deserialize<BuyingInfo>(s);
                    //CategoryMaster categorymaster = serializer.Deserialize<CategoryMaster>(s);

                    ObjBuy.GuId      = System.Guid.NewGuid().ToString();
                    ObjBuy.IPAddress = ExcellentMarketResearch.Models.PaymentGateway.IPAddress.GetIPAddress();


                    BuyingInfo binfo = new BuyingInfo();

                    binfo.Address         = ObjBuy.Address;
                    binfo.Name            = ObjBuy.Name;
                    binfo.AreaCode        = ObjBuy.AreaCode;
                    binfo.CustomerMessage = ObjBuy.CustomerMessage;
                    binfo.ReportTitle     = ObjBuy.ReportTitle;
                    binfo.ReportUrl       = ObjBuy.ReportUrl;
                    binfo.EmailId         = ObjBuy.EmailId;
                    binfo.Company         = ObjBuy.Company;
                    binfo.CaptchaCode     = ObjBuy.CaptchaCode;
                    binfo.Country         = ObjBuy.Country;
                    binfo.Designation     = ObjBuy.Designation;
                    binfo.State           = ObjBuy.State;
                    binfo.City            = ObjBuy.City;
                    binfo.Price           = ObjBuy.Price;
                    binfo.PhoneNumber     = ObjBuy.PhoneNumber;
                    binfo.Type            = ObjBuy.Type;
                    binfo.ReportId        = ObjBuy.ReportId;
                    binfo.Zipcode         = ObjBuy.Zipcode;
                    binfo.Paymentmode     = ObjBuy.Paymentmode;
                    binfo.GuId            = ObjBuy.GuId;
                    binfo.IPAddress       = ObjBuy.IPAddress;
                    try
                    {
                        db.BuyingInfoes.Add(binfo);
                        //  db.Entry(cst).State = EntityState.Added;
                        db.SaveChanges();

                        //The lead information goes to CRM here......
                        //  new CRMWebService.WebServiceSoapClient().InsertUpdateKey(0, ObjBuy.ReportId, ObjBuy.ReportTitle, 3, 34, 1, 1, ObjBuy.ReportUrl, QYGroupRepository.PaymentGateway.IPAddress.GetIPAddress(), ObjBuy.Name, ObjBuy.EmailId, ObjBuy.AreaCode, ObjBuy.Company, ObjBuy.Designation, "!", ObjBuy.State, ObjBuy.Country, ObjBuy.Zipcode, ObjBuy.CustomerMessage, 1, ObjBuy.GuId, "!", "!", Publisher, 38, "BW&Zk^HfZ44P339nEzqrrawY4HL_VXw-5f+%8b4Hdw?$?m$G*!+kCGLK%3JjDn-74NY*LyhdJr6RAte&8MBWy6F2j82+qn7ap&DB@z-*q3sdH*#D-kwACucyaM7vzet4pSa?m^xnP@3zN5K9=*L6WLpDurTSuVTR3Hd&3XLHJnCcR!h*dL#fQhp^*#25LEFrMTt@z&8RWdf^CQcj!QrQU^WkdC5$Ub$8qnu!g7?*$$4%%M9?8spAugyCzZg5@dLGBNS_^7?x3VczR75J&=+9yFDVg*Qpd@R^_Jz-GtWgHxv4Kf$=2pxT@bqhx%aqgzZAN6RzZZ%rNX7km3fu$h?Z=+V3b_MQPLAxJBVT!=Ta+7Xd?CF3#4w44L@HU%nf4m#y-d2vgn6Gp2t7w!qFY%kN#y6DNAy#TbrZnqnjMtgeAd%BHSm9H29z4G_?qnBHE5J2EyutZ2RSh?P2fUE-sF8bNFdre@G^qQ??JzJuDCT3hby2py#+yfg*jC%&YBkrutHs");

                        if (ObjBuy.Paymentmode == "wireTransfer")
                        {
                            //Auto Mailer
                            //  objEmailsending.SendEmail("*****@*****.**", "Sales", ObjBuy.EmailId, "", "*****@*****.**", "Payment Initiated : " + ObjBuy.ReportTitle, MailbodyMethodCall.GenerateMailBody_PaymentInitiated_AutoReply(ObjBuy.ReportTitle, ObjBuy.Name));
                            //To company
                            //                            objEmailsending.SendEmail(ObjBuy.EmailId, ObjBuy.Name, "*****@*****.**", "", "[email protected],[email protected]", "xyz.com" + " : Payment Initiated(Wire Transfer)", MailbodyMethodCall.GenerateMailBody_PaymentInitiated(ObjBuy.ReportTitle, ObjBuy.Name, ObjBuy.EmailId, ObjBuy.PhoneNumber, ObjBuy.Company, "", "", ObjBuy.Country, ""));
                        }
                        else
                        {
                            //Auto Mailer
                            //                          objEmailsending.SendEmail("*****@*****.**", "Sales", ObjBuy.EmailId, "", "*****@*****.**", "Payment Initiated : " + ObjBuy.ReportTitle, GenerateMailBody_PaymentInitiated_AutoReply(ObjBuy.ReportTitle, ObjBuy.Name));

                            //To company
                            //                        objEmailsending.SendEmail(ObjBuy.EmailId, ObjBuy.Name, "*****@*****.**", "", "[email protected],[email protected]", "xyz.com" + " : Payment Initiated(pay pal )", GenerateMailBody_PaymentInitiated(ObjBuy.ReportTitle, ObjBuy.Name, ObjBuy.EmailId, ObjBuy.PhoneNumber, ObjBuy.Company, "", "", ObjBuy.Country, ""));



                            //The paypalpage will appear to the user or buer ....
                            //Paypal._PayPal(ObjBuy);

                            PaymentWithPaypal(ObjBuy, null);
                            //return RedirectToAction("PaymentWithPaypal", "ReportBuying", new {ObjBuy, Cancel = false });
                            //return RedirectToAction("PaymentWithPaypal");
                        }



                        //  return RedirectToAction("Index");
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                            }
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Verification Code is Incorrect");
                }
            }
            Session["Name"] = ObjBuy.Name;
            return(RedirectToAction("Index", "InquiryForm", new { reportid = ObjBuy.ReportId }));
        }
Exemplo n.º 6
0
        private Payment CreatePayment(PayPal.Api.APIContext apiContext, string redirectUrl, BuyingVM buyingVM)
        {
            //create itemlist and add item objects to it

            var itemList = new ItemList()
            {
                items = new List <Item>()
            };

            // Adding Item Details like name, currency, price etc
            itemList.items.Add(new Item()
            {
                name     = buyingVM.ReportTitle.ToString(), // buyingVM.ReportTitle,
                currency = "USD",
                price    = buyingVM.Price.ToString(),       //(buyingVM.Price).ToString(),
                quantity = "1",
                sku      = "sku"
            });
            var transaction = new Transaction()
            {
                amount = new Amount()
                {
                    currency = "USD",
                    total    = buyingVM.Price.ToString()
                },
                item_list = itemList,

                description = "This is the payment transaction description.",

                invoice_number = GetRandomInvoiceNumber()
            };

            var payer = new Payer()
            {
                payment_method = "paypal"
            };


            var redirUrls = new RedirectUrls()
            {
                cancel_url = redirectUrl + "&Cancel=true",
                return_url = redirectUrl
            };


            this.payment = new Payment()
            {
                intent       = "sale",
                payer        = payer,
                transactions = new List <Transaction>()
                {
                    transaction
                },
                redirect_urls = redirUrls
            };

            return(this.payment.Create(apiContext));

            /*
             * //create itemlist and add item objects to it
             * //var pricedemo = 10;
             * var itemList = new ItemList()
             * {
             *  items = new List<Item>()
             * };
             * // Adding Item Details like name, currency, price etc
             * itemList.items.Add(new Item()
             * {
             *  name = "Global 3-Methyl-1",// buyingVM.ReportTitle,
             *  currency = "USD",
             *  price = "1",//(buyingVM.Price).ToString(),
             *  quantity = "1",
             *  sku = "sku"
             * });
             *
             * var payer = new Payer()
             * {
             *  payment_method = "paypal"
             * };
             * // Configure Redirect Urls here with RedirectUrls object
             * var redirUrls = new RedirectUrls()
             * {
             *  cancel_url = redirectUrl + "&Cancel=true",
             *  return_url = redirectUrl
             * };
             * // Adding Tax, shipping and Subtotal details
             * var details = new Details()
             * {
             *  tax = "1",
             *  shipping = "1",
             *  subtotal = "1"
             * };
             * //Final amount with details
             * var amount = new Amount()
             * {
             *  currency = "USD",
             *  total ="1",// pricedemo.ToString(),//buyingVM.Price.ToString(), // Total must be equal to sum of tax, shipping and subtotal.
             *  details = details
             * };
             * var transactionList = new List<Transaction>();
             * // Adding description about the transaction
             * transactionList.Add(new Transaction()
             * {
             *  description = "Transaction description",
             *  invoice_number = "your generated invoice number", //Generate an Invoice No
             *  amount = amount,
             *  item_list = itemList
             * });
             * this.payment = new Payment()
             * {
             *  intent = "sale",
             *  payer = payer,
             *  transactions = transactionList,
             *  redirect_urls = redirUrls
             * };
             * // Create a payment using a APIContext
             * return this.payment.Create(apiContext);
             */
        }
Exemplo n.º 7
0
        public ActionResult paypalprocess(PayPalResponse response)
        {
            var      mailbody      = new ExcellentMarketResearch.Models.PaymentGateway.Emailsending();
            string   paymentstatus = string.Empty;
            BuyingVM buy           = new BuyingVM();
            var      userdata      = (from b in db.BuyingInfoes
                                      where b.GuId == response.guid
                                      select b).FirstOrDefault();
            var userreport = (from r in db.ReportMasters
                              where r.ReportId == userdata.ReportId
                              select new { r.ReportTitle, r.ReportUrl }).FirstOrDefault();

            buy.Name        = userdata.Name;
            buy.ReportTitle = userreport.ReportTitle.ToString();
            buy.ReportUrl   = userreport.ReportUrl.ToString();
            buy.Company     = userdata.Company;
            buy.EmailId     = userdata.EmailId;
            buy.Country     = userdata.Country;
            buy.IPAddress   = userdata.IPAddress;
            buy.PhoneNumber = userdata.PhoneNumber;
            buy.Designation = userdata.Designation;


            var updatestatus = db.BuyingInfoes.Where(x => x.GuId == response.guid).FirstOrDefault();

            // b.PaymentTransaction = true;
            //updatestatus.PaymentTransaction = response.PaymentTransaction;
            updatestatus.PaymentStatus   = response.PaymentStatus;
            updatestatus.Intent          = response.Intent;
            updatestatus.PaymentId       = response.PaymentID;
            updatestatus.PayerId         = response.PAYERID;
            updatestatus.OrderId         = Convert.ToInt32(response.OrderID);
            updatestatus.Token           = response.TOKEN;
            updatestatus.ACK             = response.ACK;
            db.Entry(updatestatus).State = EntityState.Modified;
            db.SaveChanges();


            if (response.PaymentStatus == "Success")
            {
                paymentstatus = "dear admin, payment made for <br /><br />";

                //auto mailer
                objEmailsending.SendEmail("*****@*****.**", "sales", userdata.EmailId, "", "*****@*****.**", "Excellent Market Research :payment confirmation ", mailbody.GenerateMailBody_PaymentMade(paymentstatus, buy));

                //to company
                objEmailsending.SendEmail("*****@*****.**", userdata.Name, "*****@*****.**", "*****@*****.**", ".com", "Excellent Market Research " + " :payment confirmation(paypal) ", mailbody.GenerateMailBody_PaymentMade_AutoReply(userdata.Name.ToString(), userreport.ReportTitle.ToString()));

                return(Json(new
                {
                    msg = "sucess"
                          //return RedirectToAction("Index", "InquiryForm", new { reportid = ObjBuy.ReportId });
                }));
                // return RedirectToAction("sucess", "paymentprocess");
            }
            else if (response.PaymentStatus == "Cancel")
            {
                return(Json(new
                {
                    msg = "Cancel"
                          //return RedirectToAction("Index", "InquiryForm", new { reportid = ObjBuy.ReportId });
                }));
            }
            else
            {
                paymentstatus = "dear admin, payment canceled or unapproved for report<br /><br />";


                //to buyer
                objEmailsending.SendEmail("*****@*****.**", "sales", userdata.EmailId, "", "", "Excellent Market Research : " + " : payment cancel(pay pal)", mailbody.GenerateMailBody_PaypalError_AutoReply(buy.Name, buy.ReportTitle, buy.ReportUrl));

                //to company
                objEmailsending.SendEmail("*****@*****.**", userdata.Name, "*****@*****.**", "*****@*****.**", "", "Excellent Market Research" + " : payment cancel(pay pal)", mailbody.GenerateMailBody_PaypalError_AutoReply(userdata.Name.ToString(), userreport.ReportTitle.ToString(), userreport.ReportUrl.ToString()));

                return(Json(new
                {
                    msg = "failure"
                          //return RedirectToAction("Index", "InquiryForm", new { reportid = ObjBuy.ReportId });
                }));
                //return RedirectToAction("failure", "paymentprocess");
            }
        }