2013-07-16 2 views
2

paypal 샌드 박스를 asp.net 코드와 통합하려고합니다. 요구 사항은 내가 사용자를 페이팔 사이트로 데려 가서 사용자가 자신의 자격 증명으로 로그인하고 지정된 금액을 지불해야한다는 것입니다.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 구현하기 시작했습니다하지만 난 내가 몇 가지 숨겨진 컨트롤을 통해 내가 보내고에서 하나에서 페이팔 사이트

에 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> 

이제 나는 펜실바니아 응답

//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(); 
     } 

를 수집 GE는 지금은 요청 검증 등의 응답을 얻기를 보낼 수 있어요,하지만 난 tranactionID을 받고 있지 않다. 내가 TIA

답변

0

을 잃었 어디 당신이 즉시 지불 통지 (IPN)를 사용하는 것이 좋습니다 것 제안하십시오. IPN을 사용하면 모든 거래가 끝난 후 결제가 완료되었는지 여부를 알려주는 알림 메시지가 발송됩니다.

notify_url 변수를 사용하여 알림 URL을 정의합니다. 당신이 서비스에 대한 특정 질문이있는 경우 https://github.com/paypal/ipn-code-samples

내가 더 당신을 도울 수 있습니다 : 여기

는 우리의 IPN 코드 샘플에 대한 링크입니다.

관련 문제