PayPal 并行支付 IPN
我已经被困了好几天了!我正在尝试从并行付款中获取 PayPal IPN 的详细信息。
我需要汇款的两个电子邮件地址、金额以及状态。
我正在看这里:
https://cms .paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APIPN
这些是我的代码中的行,其中我尝试获取电子邮件和金额:
$Email1 = $_POST['transaction[0].receiver'];
$Email2 = $_POST['transaction[1].receiver'];
以及金额部分:
$Amount1 = $_POST['transaction[0].amount'];
$Amount2 = $_POST['transaction[1].amount'];
我正在使用此页面上的 IPN 代码。
https://cms.paypal.com/cms_content/AU/en_AU /files/developer/IPN_PHP_41.txt
有帮助吗? POST 变量显示为空白?
更新:我发现了这个:
<source lang="php">
<?php
error_reporting(E_ALL ^ E_NOTICE);
// By Gleb Esman, [email protected], http://www.memberwing.com/
//
// Pull raw POST data.
// We need to pull raw data and build our own copy of $_POST in order to
// workaround of invalid POST keys that Adaptive IPN request uses.
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$_YOUR_POST = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode('=', $keyval);
if (count($keyval) == 2)
$_YOUR_POST[$keyval[0]] = urldecode($keyval[1]);
}
if (count($_YOUR_POST) < 3) {
$_YOUR_POST = $_POST;
$original_post_used = TRUE;
}
else
$original_post_used = FALSE;
// Build final $_req postback request
// Paypal's IPN Sample
// read the post from PayPal system and add 'cmd'
if ($original_post_used) {
$_req = 'cmd=_notify-validate';
foreach ($_YOUR_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$_req .= "&$key=$value";
}
}
else
$_req = $raw_post_data . '&cmd=_notify-validate';
// $_req is ready for postback to Paypal here...
$req = $_req;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// PHP 4.1
// read the post from PayPal system and add 'cmd'
//$req = 'cmd=_notify-validate';
//
//foreach ($_POST 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://www.paypal.com', 443, $errno, $errstr, 30);
// throw all this junk into the local error log so we can see what happened!
function log_arr($item, $key) {
$p .= "$key = $item";
error_log(urldecode($p));
}
array_walk_recursive($_YOUR_POST, 'log_arr');
error_log(urldecode($req));
// 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'];
if (!$fp) {
// HTTP ERROR
} else {
fputs($fp, $header . $req);
while (!feof($fp)) {
$res = fgets($fp, 1024);
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
}
}
fclose($fp);
}
?>
</source>
它在日志文件中产生了这个:
[10-Dec-2011 07:13:50] transaction[0].id_for_sender_txn = xxxxx
[10-Dec-2011 07:13:50] log_default_shipping_address_in_transaction = xxx
[10-Dec-2011 07:13:50] transaction[0].receiver = xxxxx
[10-Dec-2011 07:13:50] action_type = xxxx
[10-Dec-2011 07:13:50] transaction[1].paymentType = xxx
[10-Dec-2011 07:13:50] transaction[0].amount = xxxx
[10-Dec-2011 07:13:50] charset = xxx
任何人都可以告诉我如何将它们放入变量中,因为这是日志文件中打印的内容?
I have been stuck for days! I am trying to get the details from PayPal IPN from a parallel payment.
I need the two email addresses that money was sent to and the amount, also the status.
I am looking here:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APIPN
These are the lines in my code where I try and get email and amount:
$Email1 = $_POST['transaction[0].receiver'];
$Email2 = $_POST['transaction[1].receiver'];
And amount part:
$Amount1 = $_POST['transaction[0].amount'];
$Amount2 = $_POST['transaction[1].amount'];
I am use the IPN code from this page.
https://cms.paypal.com/cms_content/AU/en_AU/files/developer/IPN_PHP_41.txt
Any help? The POST variables come up blank?
Update: I Have found this:
<source lang="php">
<?php
error_reporting(E_ALL ^ E_NOTICE);
// By Gleb Esman, [email protected], http://www.memberwing.com/
//
// Pull raw POST data.
// We need to pull raw data and build our own copy of $_POST in order to
// workaround of invalid POST keys that Adaptive IPN request uses.
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$_YOUR_POST = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode('=', $keyval);
if (count($keyval) == 2)
$_YOUR_POST[$keyval[0]] = urldecode($keyval[1]);
}
if (count($_YOUR_POST) < 3) {
$_YOUR_POST = $_POST;
$original_post_used = TRUE;
}
else
$original_post_used = FALSE;
// Build final $_req postback request
// Paypal's IPN Sample
// read the post from PayPal system and add 'cmd'
if ($original_post_used) {
$_req = 'cmd=_notify-validate';
foreach ($_YOUR_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$_req .= "&$key=$value";
}
}
else
$_req = $raw_post_data . '&cmd=_notify-validate';
// $_req is ready for postback to Paypal here...
$req = $_req;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// PHP 4.1
// read the post from PayPal system and add 'cmd'
//$req = 'cmd=_notify-validate';
//
//foreach ($_POST 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://www.paypal.com', 443, $errno, $errstr, 30);
// throw all this junk into the local error log so we can see what happened!
function log_arr($item, $key) {
$p .= "$key = $item";
error_log(urldecode($p));
}
array_walk_recursive($_YOUR_POST, 'log_arr');
error_log(urldecode($req));
// 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'];
if (!$fp) {
// HTTP ERROR
} else {
fputs($fp, $header . $req);
while (!feof($fp)) {
$res = fgets($fp, 1024);
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
}
}
fclose($fp);
}
?>
</source>
which produces this in log file:
[10-Dec-2011 07:13:50] transaction[0].id_for_sender_txn = xxxxx
[10-Dec-2011 07:13:50] log_default_shipping_address_in_transaction = xxx
[10-Dec-2011 07:13:50] transaction[0].receiver = xxxxx
[10-Dec-2011 07:13:50] action_type = xxxx
[10-Dec-2011 07:13:50] transaction[1].paymentType = xxx
[10-Dec-2011 07:13:50] transaction[0].amount = xxxx
[10-Dec-2011 07:13:50] charset = xxx
Can anyone tell me how to get these into variables as this is what is printed in log file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
$_POST['transaction']['0']['receiver']
等等。另外,启用E_ALL
错误消息,以便您看到有关此类事件的通知。如果启用了该功能,并且您检查了错误日志,您将看到未定义的索引通知。另外,如果您非常渴望调试$_POST/$_GET/whatever
内容,并且不是您控制请求,您可以随时将内容写入文件并检查它。Try
$_POST['transaction']['0']['receiver']
and so on. Also, enableE_ALL
error messages so you see notices about things like this. If that were enabled, and you checked your error log, you would have seen an undefined index notice. Also, if you're ever desperate to debug$_POST/$_GET/whatever
stuff and it's not you controlling the request, you can always write the content to a file and examine it.