Exemplo n.º 1
0
        private bool VerifyPayment()
        {
            bool isVerified = false;

            GatewayController controller = new GatewayController(Server.MapPath(ModulePath));
            GatewayInfo gateway = controller.GetGateway(storeInfo.GatewayName);
            PayPalSettings _settings = new PayPalSettings(gateway.GetSettings(PortalId));

            _verificationURL = _settings.UseSandbox ? _sandboxVerificationURL : _settings.VerificationURL;
            _paymentURL = _settings.UseSandbox ? _sandboxPaymentURL : _settings.PaymentURL;

            PayPalIPNParameters ipn = new PayPalIPNParameters(Request.Form);
            if (ipn.IsValid)
            {
                HttpWebRequest request = WebRequest.Create(_verificationURL) as HttpWebRequest;
                if (request != null)
                {
                    request.Method = "POST";
                    request.ContentLength = ipn.PostString.Length;
                    request.ContentType = "application/x-www-form-urlencoded";

                    StreamWriter writer = new StreamWriter(request.GetRequestStream());
                    writer.Write(ipn.PostString);
                    writer.Close();

                    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                    if (response != null)
                    {
                        StreamReader reader = new StreamReader(response.GetResponseStream());
                        string responseString = reader.ReadToEnd();
                        reader.Close();

                        if (string.Compare(responseString, "VERIFIED", true) == 0)
                        {
                            isVerified = true;
                        }
                        else
                        {
                            //Not verified, possible fraud
                        }
                    }
                }
            }

            return isVerified;
        }
Exemplo n.º 2
0
        private bool VerifyPayment()
        {
            bool isVerified = false;

            PayPalIPNParameters ipn = new PayPalIPNParameters(Request.Form);
            if (ipn.IsValid)
            {
                HttpWebRequest request = WebRequest.Create(_verificationURL) as HttpWebRequest;
                if (request != null)
                {
                    request.Method = "POST";
                    request.ContentLength = ipn.PostString.Length;
                    request.ContentType = "application/x-www-form-urlencoded";

                    StreamWriter writer = new StreamWriter(request.GetRequestStream());
                    writer.Write(ipn.PostString);
                    writer.Close();

                    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                    if (response != null)
                    {
                        StreamReader reader = new StreamReader(response.GetResponseStream());
                        string responseString = reader.ReadToEnd();
                        reader.Close();

                        if (string.Compare(responseString, "VERIFIED", true) == 0)
                        {
                            isVerified = true;
                        }
                        else
                        {
                            //Not verified, possible fraud
                        }
                    }
                }
            }

            return isVerified;
        }