我在Paypal上使用自适应付款。
我在JSON数据上添加了ipnNotificationUrl
字段,但从未调用过此url。但是,我的付款已执行,我被重定向到成功页面。
在我的IPN历史记录中,我所有的付款都标有“ Nouvel essai en cours”(“正在进行的新审判”)。
"actionType" => "PAY",
"currencyCode" => "EUR",
"receiverList" => array(
"receiver" => array(
array(
"amount" => "5.00",
"email" => "[email protected]"
),
array(
"amount" => "2.00",
"email" => "[email protected]"
)
)
),
"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);
}
谢谢你的帮助。
最佳答案
首先,您需要在ipn模拟器中检查IPN脚本。
-登录到https://developer.paypal.com/
-转到https://developer.paypal.com/developer/ipnSimulator/
-检查您的IPN脚本。
例如:
IPN处理程序URL:http://www.domainname.com/ipn.php
交易类型:选择您的交易类型
此网址将用于检查您的ipn脚本,是否正确运行。
第二,
您需要在您的贝宝帐户中设置IPN脚本。让我给你步。
登录到您的贝宝账户
点击个人资料链接
点击“我的销售工具”链接
点击“即时付款通知”的“更新”链接。
点击“选择IPN设置”按钮
输入您的IPN脚本路径。例如http://www.domainname.com/ipn.php
选择“接收IPN消息(已启用)”
点击保存按钮。
现在,通过这种方式,您的ipn脚本将保存在Paypal中。另外,在您的贝宝代码中添加“ notifyurl”。
尝试这些步骤。您可以解决您的问题。
关于php - IPN不发送自适应付款,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38124932/