gpt4 book ai didi

php - 使用paypal沙箱ipn模拟器调试ipn.php

转载 作者:太空宇宙 更新时间:2023-11-03 15:47:49 26 4
gpt4 key购买 nike

使用paypal沙箱ipn模拟器工具时如何调试ipn.php文件?

代码如下所示:

// 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.sandbox.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs($fp, $header.$req);

while (!feof($fp)) {
$res = fgets($fp, 1024);

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

$DBH = new PDO("mysql:host=localhost;dbname=db", "user", "pass");
$DBH - > setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$STH = $DBH - > prepare("update table2 set status = :status where tracking_id = :tracking_id");

$status = 1;
parse_str($req, $data);

$STH - > bindParam(':status', $status, PDO::PARAM_INT, 1);
$STH - > bindParam(':tracking_id', 'id_goes_here', PDO::PARAM_STR, 50);

$STH - > execute();

$DBH = null;

} else if (strcmp($res, "INVALID") == 0) {
// do something else
}
}

fclose($fp);
}

我通常使用 netbeans 调试工具进行调试,但如何使用沙盒模拟器进行调试?当我从沙盒 ipn 模拟器单击 send ipn 时,我在沙盒中收到一条消息,提示 IPN 已成功发送。,但是当我进入我的数据库检查 状态,它仍然是0

最佳答案

可能是参数绑定(bind)有问题

$STH - > bindParam(':tracking_id', 'id_goes_here', PDO::PARAM_STR, 50);

如果表 'table2' 不包含 tracking_id = 'id_goes_here' 的行,更新操作将失败。

试试这个

<?php

$testMode = false;
$url = 'https://www.paypal.com/cgi-bin/webscr';
if ($testMode === true)
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';

$ipnResponse = ''; // holds the IPN response from paypal
$ipnData = array(); // array will contain the POST values for IPN

$urlParsed = parse_url($url);

$req = 'cmd=_notify-validate'; // Add 'cmd' to req (ipn command)

// Read the post from PayPal system and add them to req
foreach ($_POST as $key => $value) {
$ipnData["$key"] = $value;
$value = urlencode(stripslashes($value));
$req .= "&" . $key . "=" . $value;
}

// Open the connection to paypal
$fp = fsockopen($urlParsed['host'], "80", $errno, $errstr, 30);

// If could open the connection and check response
if ($fp) {

fputs($fp, "POST " . $urlParsed['path'] . " HTTP/1.1\r\n");
fputs($fp, "Host: " . $urlParsed['host'] . "\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: " . strlen($req) . "\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $req . "\r\n\r\n");

// Loop through the response from the server and append to variable
while (!feof($fp)) {
$ipnResponse .= fgets($fp, 1024);
}
fclose($fp);

// Valid IPN transaction.
if (preg_match('/^VERIFIED/', $ipnResponse)) {
// Some action on IPN validation - update payment status etc
die("OK. IPN Validation: Success");
}
// Invalid IPN transaction
else {
// Some action on IPN validation - update payment status etc
die("ERROR. IPN Validation: Failed");
}
}
// Else no connection, so maybe wrong url or other reasons, you can do another call later
else {
die("ERROR. IPN Connection: fsockopen error");
}


?>

关于php - 使用paypal沙箱ipn模拟器调试ipn.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11700399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com