コード例 #1
0
        public static bool PayPalProcess(PaymentLibrary.PayPal.PayPalResponse paypalResponse)
        {
            ExcellentMarketResearchEntities db = new ExcellentMarketResearchEntities();

            if (paypalResponse != null && (!string.IsNullOrEmpty(paypalResponse.PAYERID) || !string.IsNullOrEmpty(paypalResponse.guid)))
            {
                BuyingInfo b = new BuyingInfo();

                if (string.IsNullOrEmpty(paypalResponse.PAYERID))
                {
                    log4net.LogManager.GetLogger("Error").Error("PayerID not found OR Response is null OR guid is not found.\nData - " + Newtonsoft.Json.JsonConvert.SerializeObject(paypalResponse));
                }

                //TODO: Get buyer from table using guid

                var buyer = GetBuyerByGuId(paypalResponse.guid);

                //bool IsBuyerExist= buyer.Count(x=>x.GuId==paypalResponse.guid)>0?true:false;
                bool IsBuyerExist = buyer != null ? true : false;

                //TODO: Check buyer if exist or not
                if (IsBuyerExist == null)
                {
                    // log4net.logmanager.getlogger("error").error("buyer not found.\ndata - " + newtonsoft.json.jsonconvert.serializeobject(paypalresponse));
                    return(false);
                }


                ValidResponse vResponse = PaymentLibrary.PayPal.PayPal.IsPaymentValid(paypalResponse,
                                                                                      PayPalConfig.GetConfiguration(HttpContext.Current.Server.MapPath("/paypalconfig/paypal.config"), false), false);

                if (vResponse.IsValid)
                {
                    //TODO: update status of payment transaction to success

                    var updatestatus = db.BuyingInfoes.Where(x => x.GuId == paypalResponse.guid).FirstOrDefault();
                    b.PaymentTransaction            = true;
                    updatestatus.PaymentTransaction = b.PaymentTransaction;
                    db.Entry(updatestatus).State    = EntityState.Modified;
                    db.SaveChanges();
                    return(true);
                }
                Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
                Stream     s = new MemoryStream();
                TextWriter t = new StreamWriter(s);

                serializer.Serialize(t, paypalResponse);
                TextReader r = new StreamReader(s);

                //TODO: Save error to db

                //_saveStatus(, 'f', vResponse.Reason + "|ErrorCode - " + vResponse.ErrorCode + "|PaypalResponse - " + r.ReadToEnd());

                var saveError = db.BuyingInfoes.Where(x => x.GuId == paypalResponse.guid).FirstOrDefault();
                b.PaymentTransaction         = false;
                saveError.PaymentTransaction = b.PaymentTransaction;
                saveError.ErrorReason        = vResponse.Reason;
                saveError.ErrorCode          = vResponse.ErrorCode;
                db.Entry(saveError).State    = EntityState.Modified;
                db.SaveChanges();

                return(false);
            }
            return(false);
        }
コード例 #2
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 }));
        }