2013-07-16 181 views
2

我想用我的asp.net代碼貝寶沙箱集成響應。該要求是,我必須將用戶帶到PayPal網站,用戶將用他的憑據登錄並支付指定金額。獲得來自PayPal沙箱

現在我能夠將用戶帶到PayPal的網站,並獲得成功地完成按我下面的代碼交易。我的下一步是讓來自貝寶的響應。在迴應我需要的狀態,也同時重定向到我想在響應太讓我的應用程序可以識別從哪個用戶的響應到達的PayPal網站,我將發送UNIQUEID。

private void PayJNP() 
    { 
     try 
     { 
      string redirectUrl = ""; 
      redirectUrl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" + ConfigurationManager.AppSettings["paypalemail"].ToString(); 
      redirectUrl += "&first_name=ATPTrader"; 
      redirectUrl += "&item_name=JNP"; 
      redirectUrl += "&amount=100"; 
      redirectUrl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString(); 
      redirectUrl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString(); 
      Response.Redirect(redirectUrl); 
     } 
     catch (Exception Ex) 
     { 

     } 
    } 

請幫我抓住迴應。

TIA


我已經開始實施IPN,但我得到的一些問題

我在PayPal網站

從將向您介紹一些隱藏控件我發送配置IPN從一個數據到貝寶沙盒

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="form1" 
     name="form1"> 
     <input type="hidden" name="cmd" value="_xclick"/> 
     <input type="hidden" name="business" value="[email protected]"/><!--Paypal or sandbox Merchant account --> 
     <input type="hidden" name="item_name" value="JNP"/> 
     <input type="hidden" name="item_number" value="1"/> 
     <input type="hidden" name="amount" value="100"/> 
     <input type="hidden" name="return" value="http://alltradepartners.com/test/paypal.aspx"/><!--this page will be your redirection page --> 
     <input type="hidden" name="cancel_return" value="http://alltradepartners.com/test/partnerregistration.aspx"/> 
     <input type="hidden" name="currency_code" value="USD"/> 
     <input type="hidden" name="notify_url" value="http://alltradepartners.com/test/paypal.aspx"/><!--this should be your domain web page where you going to receive all your transaction variables --> 
    </form> 

現在我有一個pa GE它收集的響應

//Post back to either sandbox or live 
     string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr"; 
     // string strLive = "https://www.paypal.com/cgi-bin/webscr"; 
     HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox); 

     //Set values for the request back 
     req.Method = "POST"; 
     req.ContentType = "application/x-www-form-urlencoded"; 
     byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength); 
     string strRequest = Encoding.ASCII.GetString(param); 
     strRequest += "&cmd=_notify-validate"; 
     req.ContentLength = strRequest.Length; 

     //for proxy 
     //WebProxy proxy = new WebProxy(new Uri("http://url:port#")); 
     //req.Proxy = proxy; 

     //Send the request to PayPal and get the response 
     StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); 
     streamOut.Write(strRequest); 
     streamOut.Close(); 
     StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); 
     string strResponse = streamIn.ReadToEnd(); 

     streamIn.Close(); 

     if (strResponse == "VERIFIED") 
     { 

      Response.Write("VERIFIED"); 
      //UPDATE YOUR DATABASE 

      //TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt"); 
      //txWriter.WriteLine(strResponse); 
      //txWriter.Close(); 

      //check the payment_status is Completed 
      //check that txn_id has not been previously processed 
      //check that receiver_email is your Primary PayPal email 
      //check that payment_amount/payment_currency are correct 
      //process payment 





      NameValueCollection these_argies = HttpUtility.ParseQueryString(strResponse); 
      string user_email = these_argies["payer_email"]; 
      string pay_stat = these_argies["payment_status"]; 
      //. 
      //. more args as needed look at the list from paypal IPN doc 
      //. 


      if (pay_stat.Equals("Completed")) 
      { 
       Response.Write("Completed"); 
       //Send_download_link("[email protected]", user_email, "Your order", "Thanks for your order this the downnload link ... blah blah blah"); 
      }  

     } 
     else if (strResponse == "INVALID") 
     { 
      Response.Write("INVALID"); 
      //UPDATE YOUR DATABASE 

      //TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt"); 
      //txWriter.WriteLine(strResponse); 
      ////log for manual investigation 
      //txWriter.Close(); 
     } 
     else 
     { 
      Response.Write("SUCCESS"); 
      //UPDATE YOUR DATABASE 

      //TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt"); 
      //txWriter.WriteLine("Invalid"); 
      ////log response/ipn data for manual investigation 
      //txWriter.Close(); 
     } 

現在我能夠發送請求並得到響應的驗證,但我沒有得到tranactionID。請建議我在哪裏丟失

TIA

回答

0

我建議你使用即時付款通知(IPN)。隨着IPN你的每一筆交易你定通知的網址,告訴您付款是否已完成後得到一個回。

你會使用notify_url變量定義通知URL。

這裏是我們的IPN代碼樣本的鏈接: https://github.com/paypal/ipn-code-samples

如果您有關於該服務的具體問題我還可以幫您解決。