简体   繁体   中英

Validating IPN notification of PayPal with Java. How encode “item_name” param with special char

I build an IPN Listener to validate PayPal notifications. All notifications are validating well, exception when the param item_name has a special char. Example of item name: "Um mês"

I have tried encoding the url in some charsets, but no one worked. If I remove the special char of item_name the IPN validation returns VALID, but when put just a simple special char, always I get INVALID as return.

What is the right encoding I must use before to do the request?

Here is my code: ` public void verificaIPN(FacesContext fc) throws FalseINPException, IOException { ExternalContext externalContext = fc.getExternalContext(); Iterator requestParameterNames = externalContext .getRequestParameterNames();

 String requestUrl = Messages.getString("PayPalUtil.paypalURL"); //$NON-NLS-1$
 while (requestParameterNames.hasNext()) {
    String chave = requestParameterNames.next();
    String valor = externalContext.getRequestParameterMap().get(chave);

    //is this below right?
    requestUrl += "&" + chave + "=" + URLEncoder.encode(valor, "UTF-8");
 }

 URL urlConPayPal = new URL(requestUrl);
 URLConnection yc = urlConPayPal.openConnection();
 yc.setDoOutput(true);
 yc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

 BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
 String inputLine;

 while ((inputLine = in.readLine()) != null) {
    if (inputLine.equals("VERIFIED")) {
    } else {
       throw new FalseINPException("O paypal não confirma esta transação: "
           + inputLine);
    }
 }
 in.close();

}

Have you tried changing your account encoding and just doing URL encoding in your app?

So PayPal hid this link (not sure why). You literally cannot get to it via navigating in your account anywhere (that I've found). So log into your account and click this:

https://www.paypal.com/us/cgi-bin/webscr?cmd=_profile-language-encoding

Click More Options

And change your encoding to what it needs to be for your language.

This should do the trick for you.

The problem cam from the fact you forget one parameter in our call. It seems you try to send portuges word, like me. :) You need to had:

 <INPUT TYPE="hidden" name="charset" value="utf-8">

(utf-8 or whatever you want, acoording to your encoding). And you can then have itm name like "Doação" etc....

See: https://developer.paypal.com/docs/classic/paypal-payments-standard /integration-guide/formbasics/#id08A6F0RK0PN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM