Payflow网关和付款高级

时间:2013-07-10 04:27:35

标签: paypal credit-card payflowpro

我想在我的网站上测试PayPal Payment Advanced,请使用:https://ppmts.custhelp.com/app/answers/detail/a_id/929/。现在我完成了它与我的网站的整合。但现在我可以用PayPal账户付款,但我没有用信用卡付款,当我使用这个API时,我无法从PayPal得到任何错误的回复。这是我的代码:

 public NameValueCollection PayAdvanced(VM_BasketOrder basketOrder)
        {
            string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority;
            string ReturnURL = baseUrl + Url.Action("ReturnPayAdvanced", "ShoppingCart");

            string CancelURL = baseUrl + Url.Action("CancelPay", "ShoppingCart");

            StoredAddress billAddress = basketOrder.billto_sAddress;
            StoredAddress shipAddress = basketOrder.shipto_sAddress;

            NameValueCollection requestArray = new NameValueCollection()
            {
                {"PARTNER", "PayPal"},  

                {"VENDOR", "s04124226"},  
                {"USER", "g041234226"},
                {"PWD", "k_123452346789"},


                {"CREATESECURETOKEN", "Y"},
                {"SECURETOKENID", genId()},

                {"TRXTYPE", "S"},//A
                {"SHIPAMOUNT", basketOrder.ShippingAmount.ToString()},
                {"AMT", basketOrder.Total.ToString()},
                {"TAX", basketOrder.SalesTax.ToString()},
               // {"ACCT","4111111111111111"},
               // {"EXPDATE","1215"},

                {"CURRENCY", "USD"},

                //{"SILENTTRAN","TRUE"},

                {"RETURNURL", ReturnURL}, 
                {"CANCELURL", CancelURL},
                {"ERRORURL", CancelURL},

                {"BILLTOFIRSTNAME",billAddress.Name.AddressNameSplit()[0]},
                {"BILLTOLASTNAME", billAddress.Name.AddressNameSplit()[1]},
                {"BILLTOSTREET", billAddress.Street1},
                {"BILLTOCITY",billAddress.City},
                {"BILLTOSTATE",billAddress.State},
                {"BILLTOZIP",billAddress.Zip},
                {"BILLTOCOUNTRY",billAddress.Country},

                {"BILLTOPHONE","55555"},


                {"SHIPTOFIRSTNAME", shipAddress.Name.AddressNameSplit()[0]},
                {"SHIPTOLASTNAME", shipAddress.Name.AddressNameSplit()[1]},
                {"SHIPTOSTREET", shipAddress.Street1},
                {"SHIPTOCITY", shipAddress.City},
                {"SHIPTOSTATE", shipAddress.State},
                {"SHIPTOZIP",shipAddress.Zip},
                {"SHIPTOCOUNTRY",shipAddress.Country},

                {"SHIPTOPHONE","55555"},
            };

            NameValueCollection resp = run_payflow_call(requestArray);


            return resp;
        }

        protected NameValueCollection run_payflow_call(NameValueCollection requestArray)
        {
            #region send request to Payflow
                String nvpstring = "";
                foreach (string key in requestArray)
                {
                    //format:  "PARAMETERNAME[lengthofvalue]=VALUE&".  Never URL encode.
                    var val = requestArray[key];
                    nvpstring += key + "[ " + val.Length + "]=" + val + "&";
                }

                string urlEndpoint = "https://pilot-payflowpro.paypal.com/";

                HttpWebRequest payReq = (HttpWebRequest)WebRequest.Create(urlEndpoint);
                payReq.Method = "POST";
                payReq.ContentLength = nvpstring.Length;
                payReq.ContentType = "application/x-www-form-urlencoded";

                StreamWriter sw = new StreamWriter(payReq.GetRequestStream());
                sw.Write(nvpstring);
                sw.Close();
            #endregion

            #region get Payflow response
                HttpWebResponse payResp = (HttpWebResponse)payReq.GetResponse();
                StreamReader sr = new StreamReader(payResp.GetResponseStream());
                string response = sr.ReadToEnd();
                sr.Close();
            #endregion

            #region parse string into array and return
                    NameValueCollection dict = new NameValueCollection();
                    foreach (string nvp in response.Split('&'))
                    {
                        string[] keys = nvp.Split('=');
                        dict.Add(keys[0], keys[1]);
                    }
                    return dict;
            #endregion

        }

        protected string genId()
        {
            var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var random = new Random();
            var result = new string(
                Enumerable.Repeat(chars, 16)
                          .Select(s => s[random.Next(s.Length)])
                          .ToArray());
            return "MySecTokenID-" + result; //add a prefix to avoid confusion with the "SECURETOKEN"
        }

我使用此代码,然后将tokenid和token传递给下一个代码。

  <iframe src="@("https://payflowlink.paypal.com?MODE=TEST&SECURETOKENID="+ViewBag.SECURETOKENID+"&SECURETOKEN="+ViewBag.SECURETOKEN)" name="test_iframe" scrolling="no" style=" width:480px;height:490px;border:0px;"></iframe>

我在我的网站上获得PayPal iframe,点击PayPal按钮,我可以成功付款,但是当我输入信用卡号码并点击&#34;立即付款&#34;时,我无法获得金钱在我的测试帐户中。现在我不知道如何调试我的代码,因为它是在PayPal中执行的,所以我无法找到代码中的错误。所以我在这里粘贴了我的代码,希望有些人可以帮助我。

今天我发现,当我使用信用卡支付时,PNREF = V72A4DR7AE07,我无法获得PPREF。当我使用PayPal账户支付时,我可以获得PNREF和PPREF。而PPREF是PayPal transactionId。

0 个答案:

没有答案