我在paypal上使用自适应付款。
我在我的JSON数据上添加了字段ipnNotificationUrl
,但从未调用此网址。但是,我的付款已执行,我被重定向到成功页面。
在我的IPN历史记录中,我的所有付款都标有" Nouvel essai en cours"("新正在进行的试用")。
"actionType" => "PAY",
"currencyCode" => "EUR",
"receiverList" => array(
"receiver" => array(
array(
"amount" => "5.00",
"email" => "email@domain.com"
),
array(
"amount" => "2.00",
"email" => "email2@domain.com"
)
)
),
"returnUrl" => "http://myUrl.com/return.php",
"cancelUrl" => "http://myUrl.com/cancel.php",
"ipnNotificationUrl" => "http://myUrl.com/ipn.php",
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll"
)
在我的ion.php
脚本中,我写了一个文件,看它是否被调用。但是这个文件从未被写过。
file_put_contents("called", "file is called");
define("DEBUG", 1);
define("USE_SANDBOX", 1);
define("LOG_FILE", "./ipn.log");
$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]);
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}
// Post IPN data back to PayPal to validate the IPN data is genuine
// Without this step anyone can fake IPN data
if(USE_SANDBOX == true) {
$paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
} else {
$paypal_url = "https://www.paypal.com/cgi-bin/webscr";
}
$ch = curl_init($paypal_url);
if ($ch == FALSE) {
return FALSE;
}
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
if(DEBUG == true) {
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
}
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
$res = curl_exec($ch);
if (curl_errno($ch) != 0) // cURL error
{
if(DEBUG == true) {
error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
}
curl_close($ch);
exit;
} else {
// Log the entire HTTP response if debug is switched on.
if(DEBUG == true) {
error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 3, LOG_FILE);
error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE);
}
curl_close($ch);
}
$tokens = explode("\r\n\r\n", trim($res));
$res = trim(end($tokens));
if (strcmp ($res, "VERIFIED") == 0) {
error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
} else if (strcmp ($res, "INVALID") == 0) {
error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
}
感谢您的帮助。
答案 0 :(得分:1)
首先,您需要在ipn模拟器中检查您的IPN脚本。 - 登录https://developer.paypal.com/ - 转到https://developer.paypal.com/developer/ipnSimulator/ - 检查您的IPN脚本。
例如: IPN处理程序网址:http://www.domainname.com/ipn.php 交易类型:选择您的交易类型
此网址将用于检查您的ipn脚本,是否正常运行。
第二次,
您需要在paypal帐户中设置IPN脚本。让我试试你的步骤。
现在,这样你的ipn脚本将保存在Paypal中。另外,在您的paypal代码中添加'notifyurl'。
尝试以下步骤。你可以解决你的问题。
答案 1 :(得分:0)
我解决了我的问题。 ipn链接不应是IP地址(http://x.x.x.x/)。