【发布时间】:2012-08-12 20:11:10
【问题描述】:
我正在尝试从 PayPal 获取 IPN,但它一直返回 INVALID 而不是 VERIFIED,我看不出我做错了什么。
目前,我有 2 个使用来自 paypal 开发者网站的示例代码的 php 文件。代码似乎运行良好,我使用的是sandbox,所以我可以看到正在转移的付款,所以我不明白为什么我会收到INVALID。
谁能看一下代码,因为我看不到我做错了什么。
1. basic_payment.php(发送支付数据到paypal的文件)
<?php require_once ("paypalplatform.php"); $actionType = "PAY"; $cancelUrl = "http://[my server details go here]/cancel.php"; $returnUrl = "http://[my server details go here]/success.php"; $currencyCode = "GBP"; $receiverEmailArray = array( 'seller_15456764326_biz@mail.com' ); $receiverAmountArray = array( '2' ); $receiverPrimaryArray = array(); $senderEmail = ""; $feesPayer = ""; $ipnNotificationUrl = "http://[my server details go here]/ipn.php"; $memo = ""; $pin = ""; $preapprovalKey = ""; $reverseAllParallelPaymentsOnError = ""; $trackingId = generateTrackingID(); $receiverInvoiceIdArray = array( $trackingId ); $resArray = CallPay ($actionType, $cancelUrl, $returnUrl, $currencyCode, $receiverEmailArray, $receiverAmountArray, $receiverPrimaryArray, $receiverInvoiceIdArray, $feesPayer, $ipnNotificationUrl, $memo, $pin, $preapprovalKey, $reverseAllParallelPaymentsOnError, $senderEmail, $trackingId ); $ack = strtoupper($resArray["responseEnvelope.ack"]); if($ack=="SUCCESS") { if ("" == $preapprovalKey) { $cmd = "cmd=_ap-payment&paykey=" . urldecode($resArray["payKey"]); RedirectToPayPal ( $cmd ); } else { $payKey = urldecode($resArray["payKey"]); $paymentExecStatus = urldecode($resArray["paymentExecStatus"]); } } ?>
2。 ipn.php(监听paypals响应的文件)
<?php $ipn_post_data = $_POST; $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; $request = curl_init(); curl_setopt_array($request, array ( CURLOPT_URL => $url, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => http_build_query(array('cmd' => '_notify-validate') + $ipn_post_data), CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HEADER => FALSE, )); $response = curl_exec($request); $status = curl_getinfo($request, CURLINFO_HTTP_CODE); curl_close($request); $to = "oshirowanen@mail.com"; $from = "me@desktop.com"; $subject = "response"; $message = "<pre>".print_r($status,true)." - ".print_r($response,true)."</pre>\n"; $header = 'To: Oshirowanen <oshirowanen@mail.com>' . "\r\n"; $header .= 'From: Me <me@desktop.com>' . "\r\n"; mail($to,$subject,$message,$header); ?>
错误信息:
Apache 错误日志 - 无错误
这就是为什么我在 ipn.php 中添加电子邮件内容以尝试捕获某些内容,并且它正在返回:
<pre>200 - INVALID</pre>
谁能看出我做错了什么?
【问题讨论】:
-
难道 PayPal API 没有一个地方可以告诉您它发送到服务器的内容吗?我们能看到这些数据吗?
-
@David,我已经添加了您要求的代码。
-
我已经更新了这个问题,希望它更容易理解。
标签: php paypal paypal-ipn paypal-sandbox