0

我想在我的网站上测试 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 和令牌传递给下一个代码。

  <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 按钮,我可以成功支付,但是当我输入信用卡号并点击“立即支付”时,我的测试账户无法取款。现在我不知道如何调试我的代码,因为它是在 PayPal 中执行的,所以我在我的代码中找不到错误在哪里。所以我把我的代码贴在这里,希望有人能帮助我。

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

4

0 回答 0