2015-11-05 80 views
0

我正在使用MVC和C#與自定義購物車,我試圖融入貝寶。我在使用paypal的許多不同選項中迷失了方向。有沒有簡單的資源解釋基礎知識?我嘗試使用下面的代碼,它失敗了,但沒有錯誤代碼。我不太瞭解整合是如何工作的,文檔涵蓋了很多不同的安排,我發現它很難。貝寶說我應該在這個論壇上發帖。入門和貝寶集成(C#)

string authToken = WebConfigurationManager.AppSettings["PDTToken"]; 
     //read in txn token from querystring 
     string txToken = Request.QueryString.Get("tx"); 

     string query = string.Format("cmd=_notify-synch&tx={0}&at={1}", 
           txToken, authToken); 
     // Create the request back 
     string url = WebConfigurationManager.AppSettings["PayPalSubmitUrl"]; 
     HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); 
     // Set values for the request back 
     req.Method = "POST"; 
     req.ContentType = "application/x-www-form-urlencoded"; 
     req.ContentLength = query.Length; 
     // Write the request back IPN strings 
     StreamWriter stOut = new StreamWriter(req.GetRequestStream(), 
           System.Text.Encoding.ASCII); 
     stOut.Write(query); 
     stOut.Close(); 
     // Do the request to PayPal and get the response 
     StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); 
     string strResponse = stIn.ReadToEnd(); 
     stIn.Close(); 
     if (strResponse.StartsWith("SUCCESS")) 
     { 
      PDTHolder pdt = PDTHolder.Parse(strResponse); 
      return pdt; 
     } 
     else 
     { 
      return null; 
     } 

我的web.config是正確的,並在調試網址似乎是正確的,但它只是迴應「不及格」,沒有更多的細節。

有沒有人有任何想法?所需的系統將用戶添加到購物車,然後單擊訂單,然後系統將用戶帶到paypal.com,然後付款,然後返回到我的網站。

回答

0

使用.NET SDK貝寶: https://github.com/paypal/PayPal-NET-SDK

自述包含指向教程和示例代碼在C#中使用的一噸。

+0

只是爲了更新讀者,paypal實際上有一個支持服務(以前我不知道),他們顯然提供幫助。我現在正在使用這個。 –