Esempio n. 1
0
        public static PTDHolder Success(string tx)
        {
            PayPalConfig payPalConfig = PayPalService.GetPayPalConfig();

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            authToken = payPalConfig.AuthToken;
            txToken   = tx;
            query     = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, authToken);
            string         url = payPalConfig.PostUrl;
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            req.Method        = "POST";
            req.ContentType   = "application/x-www-form-urlencoded";
            req.ContentLength = query.Length;
            StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);

            stOut.Write(query);
            stOut.Close();
            StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());

            strResponse = stIn.ReadToEnd();
            stIn.Close();
            if (strResponse.StartsWith("SUCCESS"))
            {
                return(PTDHolder.Parse(strResponse));
            }
            return(null);
        }
Esempio n. 2
0
        private static PTDHolder Parse(string postData)
        {
            String    sKey, sValue;
            PTDHolder ph = new PTDHolder();

            try
            {
                String[] StringArray = postData.Split('\n');
                int      i;
                for (i = 1; i < StringArray.Length - 1; i++)
                {
                    String[] StringArray1 = StringArray[i].Split('=');

                    sKey   = StringArray1[0];
                    sValue = HttpUtility.UrlDecode(StringArray1[1]);
                    switch (sKey)
                    {
                    case "mc_gross":
                        ph.GrossTotal = Convert.ToDouble(sValue);
                        break;

                    case "invoice":
                        ph.InvoiceNumber = Convert.ToInt32(sValue);
                        break;

                    case "payment_status":
                        ph.PaymentStatus = Convert.ToString(sValue);
                        break;

                    case "first_name":
                        ph.PayerFirstName = Convert.ToString(sValue);
                        break;

                    case "mc_fee":
                        ph.PaymentFee = Convert.ToDouble(sValue);
                        break;

                    case "business":
                        ph.BusinessEmail = Convert.ToString(sValue);
                        break;

                    case "payer_email":
                        ph.PayerEmail = Convert.ToString(sValue);
                        break;

                    case "last_name":
                        ph.PayerLastName = Convert.ToString(sValue);
                        break;

                    case "receiver_email":
                        ph.ReceiverEmail = Convert.ToString(sValue);
                        break;

                    case "item_name":
                        ph.IteamName = Convert.ToString(sValue);
                        break;

                    case "mc_currency":
                        ph.Currency = Convert.ToString(sValue);
                        break;

                    case "txn_id":
                        ph.TransactionId = Convert.ToString(sValue);
                        break;

                    case "custom":
                        ph.Custom = Convert.ToString(sValue);
                        break;

                    case "subscr_id":
                        ph.SubscriberId = Convert.ToString(sValue);
                        break;
                    }
                }
                return(ph);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }