2013-09-03 2 views
4

저는 회사 웹 사이트에서 페이팔 IPN 시스템을 구현하려고 시도해 왔습니다. IPN 샌드 박스 도구에서 스크립트를 테스트 할 때 유효성이 확인되고 모든 것이 잘 진행되지만 IPN이 실제로 옮겨지면 IPN이 INVALID로 반환되지만 지불이 잘 완료되었습니다. 내 계정에 IPN 내역을 확인할 때 , 나는 HTTP 응답 (200)이 IPN 메시지를 볼 수 있습니다PayPal IPN이 샌드 박스에서 라이브 및 확인시 INVALID를 반환합니다.

mc_gross=0.01&invoice=40&protection_eligibility=Ineligible&item_number1=&payer_id=mypayerId&tax=0.00&payment_date=08:06:52 Sep 03, 2013 PDT&payment_status=Completed&charset=windows-1252&mc_shipping=0.00&mc_handling=0.00&first_name=myName&mc_fee=0.01&notify_version=3.7&custom=18528&payer_status=verified&business=bussiness_mail&num_cart_items=1&mc_handling1=0.00&verify_sign=AJ.HL1f2A9aoBiFQCLn.3J-QkKQGAF.RVW8er5rbGJ6SsQFWBbStuRtD&payer_email=myMail&mc_shipping1=0.00&tax1=0.00&txn_id=61052338B4613440H&payment_type=instant&last_name=MySurname&item_name1=Paquete Lite&receiver_email=mybussiness_mail&payment_fee=&quantity1=1&receiver_id=SVRXVCZYE2AYC&txn_type=cart&mc_gross_1=0.01&mc_currency=EUR&residence_country=ES&transaction_subject=18528&payment_gross=&ipn_track_id=38c492cbe6257

  • 페이팔 살 자격 증명을 확인합니다.
  • URL은

내 IPNHandler은 자바 서블릿이다 OK (https://www.paypal.com/cgi-bin/webscr)입니다. doPost 액션은 다음과 같습니다.

@Override 
protected void doPost(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException { 
    // Java JSP 
    log.error("IPN doPost " + new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds()); 

    // read post from PayPal system and add 'cmd' 
    Enumeration en = request.getParameterNames(); 
    String str = "cmd=_notify-validate"; 
    while (en.hasMoreElements()) { 
     String paramName = (String) en.nextElement(); 
     String paramValue = request.getParameter(paramName); 
     paramValue = new String(paramValue.getBytes("iso-8859-1"), "utf-8"); 
     str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue); 
    } 

    boolean isSandbox = "true".equals(PropertiesManager.getProperty("signbox", "PaypalSandbox")); 
    // post back to PayPal system to validate 
    // NOTE: change http: to https: in the following URL to verify using SSL (for increased security). 
    // using HTTPS requires either Java 1.4 or greater, or Java Secure Socket Extension (JSSE) 
    // and configured for older versions. 
    String url = null; 
    if (isSandbox){ 
     url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; 
    }else{ 
     url = "https://www.paypal.com/cgi-bin/webscr"; 
    } 
    log.error("La url de a la que redirigimos a Paypal es " + url); 
    URL u = new URL(url); 
    URLConnection uc = u.openConnection(); 
    uc.setDoOutput(true); 
    uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
    PrintWriter pw = new PrintWriter(uc.getOutputStream()); 
    pw.println(str); 
    pw.close(); 

    BufferedReader in = new BufferedReader(
      new InputStreamReader(uc.getInputStream())); 
    String res = in.readLine(); 
    in.close(); 
    log.error("Tras abrir la conexión, res es = " + res); 

    // assign posted variables to local variables 
    String idUser = request.getParameter("custom"); 
    String idCompra = request.getParameter("invoice"); 
    String paymentStatus = request.getParameter("payment_status"); 
    String paymentAmount = request.getParameter("mc_gross"); 
    String fee = request.getParameter("mc_fee"); 
    String paymentCurrency = request.getParameter("mc_currency"); 
    String txnId = request.getParameter("txn_id"); 
    String receiptId = request.getParameter("receipt_id"); 
    String receiverEmail = request.getParameter("receiver_email"); 
    String payerEmail = request.getParameter("payer_email"); 
    String paymentType = request.getParameter("payment_type"); 
    String txnType = request.getParameter("txn_type"); 

    if (!"instant".equals(paymentType) || !"cart".equals(txnType)) { 
     log.debug("NO ES UN CART CHECKOUT. Detalles:"); 
     log.debug("idCompra=" + idCompra); 
     log.debug("status=" + paymentStatus); 
     log.debug("amount=" + paymentAmount); 
     log.debug("currency=" + paymentCurrency); 
     log.debug("transactionId=" + txnId); 
     log.debug("receiptId=" + receiptId); 
     log.debug("receiverEmail=" + receiverEmail); 
     log.debug("payerEmail=" + payerEmail); 
     log.debug("paymentType=" + paymentType); 
     log.debug("txnType=" + txnType); 

     return; 
    } 

    **//HERE THE RESPONSE IS INVALID IN LIVE MODE** 
    if (res != null && res.equals("VERIFIED")) { //res = "VERIFIED" res = "INVALID" 
     // more code not important for this issue.... 

아이디어가 있으십니까? 내가 말했듯이, 지불은 완료되었지만 IPN은 유효하지 않습니다.

+0

boolean isSandbox = "false"를 끕니다. sandbox = verified, live = invalid의 # 1 원인으로 보입니다. 간단한 것들이 우리를 위로 여행 할 수 있습니다! – Patanjali

답변

1

나는 이것이 오래되었지만 다른 사람에게 도움이 될 수 있음을 알고 있습니다. 유효성 검사를 위해 데이터를 POST해야한다고 생각합니다.

Paypal IPN Docs에 따르면

//After receiving an IPN message from PayPal, 
//you must respond to PayPal with a POST message 
//that begins with "cmd=_notify-validate". 
//Append to your message a duplicate of the 
//notification received (the same IPN fields 
//and values in the exact order you received them) 

... 
URL u = new URL(url); 
HttpURLConnection uc = (HttpURLConnection) u.openConnection(); 
uc.setRequestMethod("POST"); 
... 
0

는 페이팔에서 IPN 메시지 데이터를 수신하려면 리스너는이 요청 - 응답의 흐름을 따라야합니다

있는 1.Your 리스너가 HTTPS POST IPN 메시지를 수신을 그 페이팔 각 이벤트와 함께 보냅니다.

2. PayPal에서 IPN 메시지를 수신 한 후 리스너는 빈 HTTP 200 응답을 PayPal에 반환합니다. 그렇지 않으면 PayPal이 IPN 메시지를 다시 보냅니다.

3. 청취자가 HTTPS POST를 사용하여 전체 메시지를 PayPal로 다시 보냅니다.

반환 된 메시지 앞에 cmd = _notify-validate 변수를 붙여 넣되 메시지 필드, 필드 순서 또는 원본 메시지의 문자 인코딩을 변경하지 마십시오. 다시 페이팔

보내기 응답 메시지 :

자세한 정보는 다음을 참조하십시오. https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNImplementation/#specs

관련 문제