首页 文章

Paypal IPN:获取买方地址

提问于
浏览
4

我已经使用沙箱来获取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>

这是我的paypal通知文件的开头:

// 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

预先感谢您的帮助 .

1 回答

  • 3

    如果付款信息中包含地址,PayPal将仅发送带有IPN通知的地址 . 否则,它完全没有了 .

    如果在按钮创建过程中您指定不需要运送,则不会导致在IPN中退回运送 . 另一种可能性是您没有订单上的运输,因此买家只需在结账时选择不包括他们的送货地址,在这种情况下,PayPal不会将其发送给您 .

相关问题