我昨天也有这个问题,但是对于沙盒,但有人建议我沙盒有问题,我应该用 live paypal 进行测试。
这是条件——
我有一个 Drupal 表单,我在其中收集一些数据,我从中进行查询并将其发送到带有如下 URL 的贝宝——
$form_state['redirect'] = 'https://www.paypal.com/cgi-bin/webscr?' .$query;
其中查询变量的结果携带——
cmd=_xclick&business=ctaep.austin%40gmail.com&page_style=Primary&bn=PP-DonationsBF&item_name=Membership¤cy_code=USD&no_shipping=1&tax=0&lc=US&rm=1&return=http%3A%2F%2Fctaep-test.kr001.us%2F%3Fq%3Dpaypal%2Fpayment&cancel_return=http%3A%2F%2Fctaep-test.kr001.us%2F%3Fq%3Duser%2Fregister&uname=Raj_vm&email=rajeevkr.dei%40gmail.com&user_type=General&first_name=Rajeev&last_name=Kumar&comp_name=&address1=sector+27&address2=&city=noida&state=ca&zip=201301&phone=9650361380&mobile=&fax=&amount=0.01&item_number=1
填写表格并提交后,我被转发到贝宝,我在那里付款,然后我不得不按下返回按钮(虽然我也通过查询发送了返回路径),
状态为无效,因为被调用以处理 IPN 的函数中的条件始终处于无效条件。这是代码 -
function paypal_payment_paypal_ipn_callback(){
header("Content-type: text/html");
header("Expires: Wed, 29 Jan 1975 04:15:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
watchdog('paypal', '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 = '';
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
watchdog('paypal', 'HTTP error');
}
else
{
fputs ($fp, $header . $req);
watchdog('paypal-fp-else-', $header . $req);
dpm($_POST['uname']);
dpm($_POST['user_type']);
while (!feof($fp)) {
watchdog('paypal', '3');
watchdog('pay_status',$res);
if (strcmp ($res, "VERIFIED") == 0) {
watchdog("verified");
watchdog('paypal', '4');
//Information about you:
$receiver_email = $_POST['business'];
//Information about the transaction:
$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'];
$user_name = $_POST['uname'];
$user_email = $_POST['email'];
$user_type = $_POST['user_type'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$company_name = $_POST['comp_name'];
$address_address_line_1 = $_POST['address1'];
$address_address_line_2 = $_POST['address2'];
$address_city = $_POST['city'];
$address_state = $_POST['state'];
$address_zip = $_POST['zip'];
$user_phone = $_POST['phone'];
$user_mobile = $_POST['mobile'];
$user_fax = $_POST['fax'];
// process payment
$password = user_password(8);
$fields = array(
'name' => $user_name,
'mail' => $user_email,
'pass' => $password,
'status' => 1,
'init' => $user_email,
'roles' => array(
DRUPAL_AUTHENTICATED_RID => $user_type,),
'field_first_name' => array(
LANGUAGE_NONE => array(
array('value' => $first_name))),
'field_last_name' => array(
LANGUAGE_NONE => array(
array('value' => $last_name))),
'field_company_name' => array(
LANGUAGE_NONE => array(
array('value' => $company_name))),
'field_address_line_1' => array(
LANGUAGE_NONE => array(
array('value' => $address_address_line_1))),
'field_address_line_2' => array(
LANGUAGE_NONE => array(
array('value' => $address_address_line_2))),
'field_user_city' => array(
LANGUAGE_NONE => array(
array('value' => $address_city))),
'field_user_state' => array(
LANGUAGE_NONE => array(
array('value' => $address_state))),
'field_user_zip' => array(
LANGUAGE_NONE => array(
array('value' => $address_zip))),
'field_phone_number_' => array(
LANGUAGE_NONE => array(
array('value' => $user_phone))),
'field_mobile_number_' => array(
LANGUAGE_NONE => array(
array('value' => $user_mobile))),
'field_fax_number_' => array(
LANGUAGE_NONE => array(
array('value' => $user_fax))),
);
$account = user_save('', $fields);
watchdog("user registered");
}
elseif (stripos($res, "INVALID") == 0) {
watchdog('Res value--', stripos($res, "INVALID"));
watchdog('paypal', 'INVALID');
}
else{
watchdog("Not Verified nor Invalid");
}
}
fclose ($fp);
}
return 'Transaction Complete';
}
我相信,即使状态是无效的,我也应该得到我发送到那里的数据作为回报,但是,当我试图通过**$_POST**
(你可以在 else 部分的 while 循环之前看到它)来获取它时,我收到错误“未定义指数”。
编辑 - -
我尝试转储 $_POST 变量,它只是在数组中返回我返回路径,该路径为 14 个字符。
我不知道该怎么办..
我可以从任何人那里得到任何帮助吗?