サンドボックスを使用して、トランザクション後に Paypal IPN から返された情報を取得しました。私が抱えている問題は、IPN が購入者の住所情報を送信しないことですが、たとえば、購入者の名前と姓を取得することはできます。取引IDや購入商品情報も問題なく取得できています。取得できない唯一の変数は、$_POST['address_name'] や $_POST['address_city'] などの購入者の住所情報です。これは私のHTMLフォームです:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type='hidden' value="Montant_Achat" name="amount" />
<input name="currency_code" type="hidden" value="EUR" />
<input name="shipping" type="hidden" value="0.00" />
<input name="tax" type="hidden" value="0.00" />
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="XXXXXXX">
<p>
<input type="hidden" name="on0" value="Durée"><span id="texteDuree">Durée : </span><select id="duree" onchange="changeCustom()" name="os0">
<option value="1 mois" id="30">1 mois €0,01 EUR</option>
<option value="3 mois" id="90">3 mois €15,00 EUR</option>
<option value="6 mois" id="180">6 mois €30,00 EUR</option>
</select>
</p>
<input name="return" type="hidden" value="factures.php" />
<input name="cancel_return" type="hidden" value="paypal_pro.php" />
<input name="notify_url" type="hidden" value="paypal/paypal_notify.php" />
<input name="item_name" type="hidden" value="Nom de votre produit" />
<input name="no_note" type="hidden" value="1" />
<input name="lc" type="hidden" value="FR" />
<input name="bn" type="hidden" value="PP-BuyNowBF" />
<input id="custom" name="custom" type="hidden" value="<?php echo $_SESSION["numUser"]; ?>||30" />
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="no_shipping" value="2" />
<input type='hidden' name="address_override" value="1">
<input type="image" style="height:auto;" src="https://www.paypalobjects.com/fr_FR/FR/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - la solution de paiement en ligne la plus simple et la plus sécurisée !">
<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
</form>
これは私のペイパル通知ファイルの始まりです:
// lire le formulaire provenant du système PayPal et ajouter 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// renvoyer au système PayPal pour validation
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
$_req = 'cmd=_notify-validate';
foreach ($myPost as $key => $value) {
$value = urlencode(stripslashes($value));
$_req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);
// récupération des informations de paypal
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$custom = explode("||", $_POST['custom']);
$id_user = $custom[0];
$dureeContrat = $custom[1];
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$address_city = $_POST["address_city"];
$address_country = $_POST["address_country"];
$address_country_code = $_POST["address_country_code"];
$address_name = $_POST["address_name"];
$address_state = $_POST["address_state"];
$address_street = $_POST["address_street"];
$address_zip = $_POST["address_zip"];
そして、これは IPN によって返される $POST 変数です。
Key: mc_gross
Key: protection_eligibility
Key: payer_id
Key: tax
Key: payment_date
Key: payment_status
Key: charset
Key: first_name
Key: option_selection1
Key: mc_fee
Key: notify_version
Key: custom
Key: payer_status
Key: business
Key: quantity
Key: verify_sign
Key: payer_email
Key: option_name1
Key: txn_id
Key: payment_type
Key: btn_id
Key: last_name
Key: receiver_email
Key: payment_fee
Key: shipping_discount
Key: insurance_amount
Key: receiver_id
Key: txn_type
Key: item_name
Key: discount
Key: mc_currency
Key: item_number
Key: residence_country
Key: handling_amount
Key: shipping_method
Key: transaction_subject
Key: payment_gross
Key: shipping
Key: ipn_track_id
よろしくお願いいたします。