Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal IPN override charset

i have a problem with this paypal IPN. I saw, a lot of people had.

I try to pay as a user: Árvíztűrő Tükörfúrógép In this name, there are all special chars, what are in hungarian ABC.

I am a hungarian PHP developer.

Ok, i tried to search a lot of on google. The first thing was to check the paypal language settings: http://jlchereau.blogspot.hu/2006/10/paypal-ipn-with-utf8.html

Every settings are UTF-8.

When paypal called my notify url, i (previous developer) build the request URL. When i logged this url, i saw, the charset was not UTF-8, so i force the script to use that.

$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
   if ($key == 'charset') {
      $req .= "&charset=utf-8";
   } else {
      $value = urlencode(stripslashes($value));
      $req .= "&$key=$value";
   }

}

And here is the intresting thing. I get back a totally mallformed username. So i dump it char by char.

The first name will be: CHARS: 193, 114, 118, 237, 122, 116, 26, 114, 26

Suck. I tried to everything to get my real utf-8 name The mb_detect_encoding is UTF-8 for it.

I tried to use iconv, mb_convert_encoding, utf8_encode and decode. No success. Tried to not urlencode the name, no success again.

Can somebody tell me, why is it, and how can i get back the real utf8 name?

The URL what i sent: cmd=_notify-validate&mc_gross=10.00&protection_eligibility=Eligible&address_status=confirmed&payer_id=JA3YMCJFKSCNJ&tax=0.00&address_street=1+Main+St&payment_date=07%3A41%3A40+Sep+05%2C+2012+PDT&payment_status=Completed*&charset=utf-8*&address_zip=95131&first_name=%C1rv%EDzt%1Ar%1A&mc_fee=0.59&address_country_code=US&address_name=%C1rv%EDzt%1Ar%1A+T%FCk%F6rf%FAr%F3g%E9p&notify_version=3.6&custom=lolka_bolka%3Bfalse%3B%3B%3B%3BHungary%3B%3B%3B%3B%3B%3B&payer_status=verified&business=vaso_1346830963_biz%40mydomain.hu&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=AVVJjJNeVwHbYcMDVfj2N1DqWwUdAtNQIpb9KIP99gZ2PY-LPoOYzSCc&payer_email=test_1346830232_per%40mydomain.hu&txn_id=4J747779YW528551F&payment_type=instant&last_name=T%FCk%F6rf%FAr%F3g%E9p&address_state=CA&receiver_email=vaso_1346830963_biz%40mydomain.hu&payment_fee=0.59&receiver_id=TGEHBCMG336WE&txn_type=web_accept&item_name=510+Silk&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=lolka_bolka%3Bfalse%3B%3B%3B%3BHungary%3B%3B%3B%3B%3B%3B&payment_gross=10.00&shipping=0.00&ipn_track_id=6fe12a7a34b74

like image 256
vaso123 Avatar asked Sep 05 '12 15:09

vaso123


2 Answers

You should change your settings at Paypal.

  • go to your Paypal profile
  • click My selling tools in the sidebar
  • scroll to the bottom and click PayPal button language encoding
  • click More options and set the encoding to UTF-8

End page

like image 53
Lenart Avatar answered Nov 17 '22 04:11

Lenart


Lenart's answer is great and very useful, but I thought I'd add a few things that wouldn't fit in a comment.

  • To clarify: setting the charset on your site, in your order form (e.g.: via a hidden input), is NOT enough, you also need to set your default encoding – as explained in Lenart's answer.
    • That's because that option applies only to your own data, while the default setting applies to the data sent by PayPal to your IPN-handling script.
    • e.g.: maybe you have UTF-8 as a hidden input on your order form but PayPal IPNs still are in windows-1252. You can only fix that by changing the default setting in your PayPal account.
  • For testing purposes, you'll want to set that encoding option for your Sandbox merchant account, too! (Just log in to https://sandbox.paypal.com with your Sandbox merchant details.)
  • After setting the default encoding, if you go back to the setting again to check on its value, it will show the default value instead of the value you set. This is a bug (and illustrative of the quality of PayPal's work) and the value you set previously is actually still set.
    • So if you want to make sure what the charset really is, do so inside of your IPN-handling script by checking the value of charset in the POST message.
  • The default charset used by PayPal does not work properly.
    • e.g.: Western European Languages (including English) would cause French accented characters not to work.
    • You're better off using UTF8 everywhere (will show as UTF-8 in the IPNs.)

§

EDIT. Last but not least:

If you'd like to test your IPN-handling script with special or accented characters, you have (theoretically) a few different options but most do not work in practice.

Here's a recap:

  • Using the IPN Simulator won't work as it cannot validate the request (it produces fake requests, not real ones.)
  • Creating a PayPal Sandbox customer account with special characters inside of the firstname or last name is sadly not possible.
    • The user interface does not support it and will ask you to Only enter letters (sic).
    • The bulk account upload functionality is no better, resulting in Something went wrong. One or more sandbox accounts could not be uploaded. Try again.
  • The one option that works: test your site with the PayPal Sandbox server and choose to pay without a PayPal account.
    • This way, you'll be able to enter accented / special characters for the first and last names.
    • (You'll get the credit card number, type and expiry date from `Developer/Sandbox Accounts › your customer account › Profile › Funding – any number will do for the CVV value.)

I reported this issue to PayPal months ago but nothing has changed.

§

Working with PayPal is no fun and a big waste of time. I hope this will help you save some time. Take your business elsewhere if you can.

like image 32
Fabien Snauwaert Avatar answered Nov 17 '22 05:11

Fabien Snauwaert