如何检查PayPal付款是否完成?

时间:2011-08-27 06:02:53

标签: php paypal-sandbox

我正在使用paypal IPN。现在一切正常。而且我获得VERIFIED身份。但是如何检查payment_status是否completed?感谢

if (strcmp ($res, "VERIFIED") == 0) {

// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
 }

没有名为$_POST['payment_status']

的变量
Array
(
[txn_type] => subscr_signup
[subscr_id] => I-LDEC0BD3UYL7
[last_name] => User
[residence_country] => US
[mc_currency] => USD
[item_name] => Alice's Weekly Digest
[business] => savife_1314264698_biz@gmail.com
[amount3] => 35.00
[recurring] => 0
[verify_sign] => AkLS8p39eNu16-x1.zjarjEI8cwRAJTbKtOMbm2NinNXnj79aqkEZ5it
[payer_status] => verified
[test_ipn] => 1
[payer_email] => savife_1314427849_per@gmail.com
[first_name] => Test
[receiver_email] => savife_1314264698_biz@gmail.com
[payer_id] => SWCUEE3GNET7A
[reattempt] => 1
[item_number] => DIG Weekly
[subscr_date] => 00:02:52 Aug 27, 2011 PDT
[charset] => windows-1252
[notify_version] => 3.2
[period3] => 1 M
[mc_amount3] => 35.00
[auth] => _XXXXXXX   [form_charset] => UTF-8
)

3 个答案:

答案 0 :(得分:9)

您没有看到'payment_status'变量的原因是因为Paypal在订阅的响应中不包含该变量。

对于订阅,您应该检查

if ($_POST['txn_type'] == "subscr_ signup") {
  //do whatever
}

其他选择包括: subscr_ cancel,subscr_ modify,subscr_payment,subscr_ failed和subscr_eot

有关详细信息,请参阅此页面上的订阅变量摘要: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables#id091EB0901HT

答案 1 :(得分:1)

查看paypal提供的示例脚本

...

if (strcmp ($res, "VERIFIED") == 0) {
        if ($_POST['payment_status'] != "Completed") {

...

答案 2 :(得分:0)

尝试回复$_POST['payment_status']。 payment_status是由paypal发送到你的ipn脚本的ipn变量。如果付款完成,它将打印完成,否则不会。

以下代码显示了IPN的有效性,而不是付款。

if (strcmp ($res, "VERIFIED") == 0) {
// IPN VERIFIED
}
else if (strcmp ($res, "INVALID") == 0) {
// IPN INVALID
}

编辑1:

$ _ POST数组在此处拆分,您无需自行拆分:

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

只需采用以下格式的变量值:

// assign posted variables to local variables
$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'];

你会看到paypal发布了一个名为payment_status的变量。

尝试将此行echo $_POST['payment_status'];添加到您的ipn页面并查看其打印内容,如果打印完成,则表示您的付款状态已成功完成。

希望这有帮助。