1

I'm trying to fix my auto return page to generate a name based license for some software. I've got PDT working and it gives me data back. However the name info has been converted to something other than Unicode and destroyed.

My test data is a user in the sandbox with a Japanese name. I attempt to run a transaction as that user and get this back:

last_name=%1A%1A
first_name=%1A%1A

In the PDT response. Some what ironically PayPal reports the content type as utf-8:

Content-Type: text/html; charset=UTF-8

Yah, nope. The test user's name is actually: 木家 寿司. Just some random Japanese characters.

My HTTP request is basically:

    if ($method == "POST")
        $r = "POST $usepath HTTP/1.1\r\n";
    else
        $r = "GET $usepath HTTP/1.1\r\n";

    $r .=   "Host: $host\r\n" .
            "User-Agent: $ua\r\n" .
            "Connection: close\r\n" .
            "Accept-Charset: utf-8\r\n" .
            "Accept: */*\r\n" .
            "Accept: image/gif\r\n" .
            "Accept: image/x-xbitmap\r\n" .
            "Accept: image/jpeg\r\n";

    if ($method == "POST")
    {
        $strlength = strlen($postdata);

        $r .=   "Content-type: application/x-www-form-urlencoded\r\n" .
                "Content-length: $strlength\r\n".
                "\r\n" .
                $postdata;
    }

Of note I set Accept-Charset to utf-8. I've also tried setting the content-type to include utf-8 as the charset. And also putting "charset=utf-8" in the form fields themselves.

Seems like PDT is just broken when it comes to unicode. Or am I doing something wrong here?

Edit: Bah, this is solved here.

fret
  • 1,542
  • 21
  • 36
  • why the frik are you generating the HTTP request manually? use curl for this! but are you really getting back exactly `last_name=%1A%1A` ? or something that looks like it? – hanshenrik Sep 23 '18 at 08:00
  • You're using PHP. How is your PHP installation set-up to handle Unicode? – Dai Sep 23 '18 at 08:01
  • @Dai Other pages on my site have no issue with utf-8 so I'm going to assume yes. – fret Sep 23 '18 at 08:18
  • 1
    @hanshenrik because I copy and pasted some code 10 years ago? And I don't have to start a process to do a HTTP request? Idk seems like not great reasons, but I briefly looked for a HTTP call built into PHP. At this point it's less work to just leave it. All the other fields are URL encoded in the HTTP response data so I'm fairly sure PayPal is giving me those exact chars. But I'll add htmlentities to the echo just to be sure. – fret Sep 23 '18 at 08:23
  • @fret Use a tool like Wireshark to find out for certain. Are you able to run Wireshark on a computer that PayPal is able to communicate with for PDT? – Dai Sep 23 '18 at 08:28
  • I just noticed in the PDT data returned there is this: charset=windows-1252 – fret Sep 23 '18 at 08:31
  • Possible duplicate of [Paypal IPN override charset](https://stackoverflow.com/questions/12284341/paypal-ipn-override-charset) – fret Sep 23 '18 at 08:41
  • @fret sorry, i didn't mean curl the binary, i meant php's libcurl api wrapper called curl_ - see http://php.net/manual/en/function.curl-exec.php - i meant something like this: https://paste.debian.net/plain/1043779 – hanshenrik Sep 23 '18 at 09:42

1 Answers1

1

Seeing as I can't close this as a duplicate I'll post the actual answer for posterity.

In your PayPal Profile under "My selling tools", there is PayPal button language wncoding. Which in my case I set to utf-8 (really what else would you want to use?)

They should default it to utf-8. They should also honour the input charset. They should do a lot of things... but they're PayPal.

fret
  • 1,542
  • 21
  • 36