3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPでstripslashes関数を使うとIPNのValidationがうまくいかない

Posted at

PayPalのウェブペイメントプラスでクレジット決済を行った後、IPNデータを取得してシステムへのデータ取り込みをPHPで書いているのですが、送られてきたデータが正しいかPayPalに問い合わせるValidationが、VERIFIEDでなくINVALIDで返ってきてしまい、はまりました。

原因は、SHIFT JISの0x5C問題、いわゆる「ダメ文字」というやつで、今回だと「圭」が対象でした。

PayPalのIPNでは、送られてきたでデータをそのままの順序、そのままの内容でPayPalに送り返すことで
通知が正しいもの=VERIFIEDだと認識されますが、その送り返すデータを作成するときに
stripslashes関数をつかっていたため、ダメ文字の0x5Cが削除されてしまうために、
受信文字列と送信文字列が一致しない結果INVALIDが返却されていました。


foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= ""&$key=$value"";
}

php.iniでmagic_quotesがOFFになっているので、そもそもstripslashes()は呼び出す必要はなかったですね。。

IPNの実装方法についてはこちらに詳しく載っています。
https://developer.paypal.com/docs/classic/ipn/gs_IPN/

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?